Go Down

Topic: how to make something time sensitive?? (Read 1 time) previous topic - next topic

LandonW

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


septillion

Pseudo code (relies on you knowing about state change detection) but it should show you :)
Code: [Select]
if(voltageBecomesAboveThreshold){
  savedTime = millis();
}
if(voltageIsAboveThreshold && millis() - savedTime > duration){
  digitalWrite(pin, HIGH);
}
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

LandonW

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.

larryd

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.


.
No technical PMs.
The last thing you did is where you should start looking.

GypsumFantastic

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.

LandonW

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.

TomGeorge

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.. :)
Everything runs on smoke, let the smoke out, it stops running....

LandonW

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"

Code: [Select]

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);


}

larryd

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.


.
No technical PMs.
The last thing you did is where you should start looking.

TomGeorge

#9
Apr 21, 2017, 04:17 am Last Edit: Apr 21, 2017, 04:18 am by TomGeorge
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.


Tom.. :)
Everything runs on smoke, let the smoke out, it stops running....

septillion

Code: [Select]
[codefloat readLoad = loadSensor * (5.0 / 1023); //converts input signal to voltage reading
Let's try 1024  ;)


And indeed, have a look at Blink without delay.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

TomGeorge

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... :)
Everything runs on smoke, let the smoke out, it stops running....

Smajdalf

Code: [Select]
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.
On 8-bit (i.e. Uno) use "byte" instead of "int" if possible - it is faster and saves resources!

septillion

I agree. But if he insists on doing it wasteful with floats, at least do it correct.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

LandonW

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.

Go Up