how to make something time sensitive??

Hi. I'm working on a project and I need help writing a code that would function as ...

(if analogRead reaches a certain voltage for a certain amount of time then digitalWrite HIGH)

I really only need help with how to code the input durations.

Please and Thank You

Pseudo code (relies on you knowing about state change detection) but it should show you :slight_smile:

if(voltageBecomesAboveThreshold){
  savedTime = millis();
}
if(voltageIsAboveThreshold && millis() - savedTime > duration){
  digitalWrite(pin, HIGH);
}

Thank you. below is my code. I'm getting an error code of "too many arguments to function"

I am new to coding and slowly learning. Any help is greatly appreciated.

TM_saver_sketch.ino (609 Bytes)

Welcome to the group.

Slow down and look at the example sketches that came with the IDE.
In particular, look at the BWD blink without delay and the analog input examples.

.

Study how millis() works. Here's a good place to start.

It doesn't take arguments so nothing can go in the brackets.

It returns the time in milliseconds since the arduino booted - that's all it does.

so I guess one question would be is how feasible is my project.

I want the Arduino to monitor the load of an electric motor. I have a circuit to convert Amps to mVdc

If the motor reaches X amps its only rated to hold that for 50min
(Y amps for 25min) and (Z amps for 8min) and if it reaches any of those then activate a relay to knock the load down.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Your proposal is very possible, even to adding a readout of current and time the motor has been in the maxload region.

Thanks.. Tom.. :slight_smile:

George, I'm taking my readings from the back of an analog amp meter. The amps are already shown and the motor load is manually controlled. Being that most operators don't care if maintenance workers have to change out parts. I want to build something to factor out "stupid"

int loadSensor = analogRead (A0);
float readLoad = loadSensor * (5.0 / 1023); //converts input signal to voltage reading
int llrPin = 1; //Load Limiting Relay



void setup() {
  // put your setup code here, to run once:

  pinMode(llrPin, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:

  if (readLoad >= 5 && millis(480000))digitalWrite(llrPin, HIGH);

  if (readLoad >= 4 && millis(1500000))digitalWrite(llrPin, HIGH);

  if (readLoad >= 3.33 && millis(3000000))digitalWrite(llrPin, HIGH);


}

op amp from load meter.JPG

This syntax is wrong: millis(3000000)

As mentioned mills() returns the number of milliseconds since reset.

Stop and get some basic understanding in Arduino programming before you proceed any further.

See the Learning tab above.

.

Hi,
Thanks for the diagram, is your circuit AC or DC?
Is the shunt and ammeter at gnd potential, because the analog input measures with respect to Arduino gnd?
OPs Circuit.
op amp from load meter.jpg

Tom.. :slight_smile:

[codefloat readLoad = loadSensor * (5.0 / 1023); //converts input signal to voltage reading

Let's try 1024 :wink:

And indeed, have a look at Blink without delay.

Hi,
How are you powering the op-amp, what is the op-amp?

Please your circuit needs power supply and output circuitry, but mainly at the moment we need to see your complete input circuit, including the motor and its supply.

Are you aware that your op-amp output may not go to your supply voltage of the op-amp if you are needing it to?

Thanks.. Tom... :slight_smile:

septillion:

float readLoad = loadSensor * (5.0 / 1023); //converts input signal to voltage reading

Let's try 1024

Why do you think it will help the OP?
Converting ADC result to "real voltage" this way is bad in many ways; value of the constant is the least important of them.

I agree. But if he insists on doing it wasteful with floats, at least do it correct.

I used an op amp because it gives the board the ability to read 0 to 1024. I recently made a horse power calculator where I had to take a mVdc reading across a shunt, I found that using an amp makes a mVdc reading more accurate if max mVdc = 5.

I guess in this scenario I don't need to convert 1024 to 5vdc.

@TomGeorge. the op amp is getting powered from the +and- from the back of the ammeter. it receives a voltage of 75mvdc. the ammeter is powered from a converter and the converter gets its signal from a shunt in the motor circuit.

in the circuit diagram I sent you I didn't draw a power supply to the Arduino. I figured that was a given.
I pretty much just drew sensor in and digital out.

How about putting the read of the load sensor in loop(), where it stands a chance of working?

septillion:
I agree. But if he insists on doing it wasteful with floats, at least do it correct.

Since ADC conversion is not injective function (more voltages result in the same ADC result) there is no "correct way" to make inverse function - assign single voltage to an ADC result. Difference between 1023 and 1024 is below precision of ADC (1 LSB) and probably way below Vref precision (USB power is 5 +/-0.25V). Dividing by 1023 can result in both 0 and Vref reading - you can get "nice numbers". I am not aware about any real advantages of dividing by 1024.

I am not aware about any real advantages of dividing by 1024.

  1. it's quicker (the compiler will see to that)
  2. it's correct.

AWOL:

  1. it's quicker (the compiler will see to that)
  2. it's correct.
  1. If you convert ADC result to float you are probably not interested in speed
  2. Define "correct". You mean politically correct? Gender correct?

Correct: right, accurate, true, veracious, exact, precise, unerring, faithful, strict, faultless, flawless, errorless, error-free, perfect, word-perfect, scrupulous, meticulous;

You're welcome.