I'm trying to create a project, that will light my indicator light on my arduino, if my motor on my project stops.
what sketch am basically trying to create is:
if +5V pulse on pin X is less than 1hz, light internal light of arduino
if +5V pulse is more than 1hz, don't light internal light of arduino
note:I tried searching for this simple logic, but I keep coming up with heart rate monitors and pwm projects.
Look at pulseIn() command on the Reference page.
Write code that keeps resetting an output pin off for 1 second.
If it is not written off, it turns on by default.
Sorry definite noobie to arduino logic, I am not however to simple dc circuit design.
Anyways I was wondering if you could show me how to sketch this out, as I am not a programmer by trade, and this is my third arduino project to help learn how to interface with various pieces of hardware.
for reference to others I have read the article:
Not trying to be lazy, just trying to understand.
If you want, please add comments in the sketch to let me know.
5$ to paypal for the first person who helps me through this problem(or charity of your choice)
Maybe something like this, assumes a 50% duty cycle at 1 Hz. Adjust the pulse width you want to look for.
1/10th second? 1/100th?
byte pulsePin = 7; // measure on this pin
byte errorPin = 13; // use onboard LED for testing
unsigned long duration;
void setup()
{
pinMode(pulsePin, INPUT_PULLUP); // turn on internal pullup so pin is not floating
pinMode (errorPin, OUTPUT);
}
void loop()
{
//pulseIn(pin, value, timeout)
//timeout (optional): the number of microseconds to wait for the pulse to start; default is one second (unsigned long)
//the length of the pulse (in microseconds) or 0 if no pulse started before the timeout (unsigned long)
duration = pulseIn(pin, LOW); // look for low pulses
if (duration >=250000){ // got a 1/4 second low pulse?
digitalWrite(errorPin, LOW); // keep LED off
}
else{
digitalWrite(errorPin, HIGH); // no pulse, turn LED on
}
}
Well it looks kinda like it works sometimes?
I ran the code and it works kinda well for low RPM (me twisting it by hand) but high rpm, I always get the light(light is supposed to be off).
The motor feed back circuit does 4, +5v pulses per single rotation
I just need to know when it stops completely. either on a +5v high or GND signal input to pin7.
Not sure why you want it, so maybe my simple solution would miss the line totally, but given such task at school, I would just brute force it along this lines:
int pinIn=10;
int pinOut=13;
int lastSeen=0; // was input HIGH?
int nowSeen=0; // is actually HIGH?
int lastMs=0; // When was last change
int nowMs=0; // what time is now?
int status=LOW; // LOW=ok, HIGH=problem
void setup() {
pinMode(pinIn,INPUT);
pinMode(pinOut,OUTPUT);
lastMs=millis();
lastSeeen=digitalRead(pinIn);
}
void loop(){
nowSeen=digitalRead(pinIn);
if (nowSeen<>lastSeen) { // there was a change
nowMs=millis();
if (nowMs-lastMs>550) { //halfpulse so half a second + some margin
digitalWrite(pinOut,HIGH); // it is too slow
} else if (nowMS-lastMs < 450) {
digitalWrite(pinOut,HIGH); // it is too fast
} else {
digitalWrite(pinOut,LOW); // just on schedule
};
lastMs=nowMS;
lastSeen=nowSeen; // and go wait for other change
}
} // endloop
just writing from a head, so maybe little incorrect, but I hope Idea is clear. (And yes - it is probabelly overkill)