I am reading an analog signal and I am getting "0.00 0.00 0.45 0.46 0.00 0.00 0.35 0.37..." and so on. A simple IF over 0.20V turn LED HIGH ELSE turn LED LOW is causing the LED to be tristated and flickering because it is reading the 0.00 of the signal. Anyone have an idea of how I can turn the LED on if I get this fluctuation(wire connected) but off if I get consistent 0V(wire disconnected). This wire is part of a larger circuit and I am getting a signal when it is connected vs when it is not.
Anyone have an idea of how I can turn the LED on if I get this fluctuation(wire connected) but off if I get consistent 0V(wire disconnected).
You will NOT get a consistent 0 when you disconnect the wire just because you start a new thread.
Paul, I am getting a consistent zero when there is nothing connected I do not understand why you do not think I do. I have the values also printing to the serial monitor. Even if you do not think I do, is there a way around that?
You are just reading a small amount of noise on the analog input. You haven't really defined "if I get this fluctuation" well enough to design a filter to keep the LED on for that condition. If the fluctuations are faster than you want to light the LED, you have to use a combination of threshold control and low pass filtering (effectively).
Suppose you read a positive value. How long do you expect the LED to be on? Until the next 0 value is received? Until the middle of next week?
Without concrete requirements, you'll get nowhere.
What if I want the LED HIGH when I get values "0.00 0.00 0.45 0.45 0.00 0.00"(obviously the 0.45 will change) but then LED LOW when I get values "0.00 0.00 0.00 0.00". These are the values I am getting when the wire is connected and disconnected, respectively. How can I write that so that when I get the first set of values, and wire is connected, Turn the LED HIGH until I get the consistent zeros like the second set of values.
Define "consistent"
with the wire disconnected, I am reading 0V at that pin. I need to implement that in the code so that the LED turns off when that is disconnected.
deeg92:
with the wire disconnected, I am reading 0V at that pin. I need to implement that in the code so that the LED turns off when that is disconnected.
According to your description, it already does.
Yeah but how would I write the code for that. I simple IF ELSE does not work because when the wire is connected, the signal goes to 0V and then up. So the LED would turn off if i tried that.
I am getting a consistent zero when there is nothing connected I do not understand why you do not think I do.
The resion why he thinks you don't is because of Physics, you simply do not. With nothing connected on an input your pin is floating and is apt to pick up interference and give a fluctuating reading. If you are currently not seeing that then it means nothing, you will eventually will.
Please read this to understand inputs.
Even if I do not the problem still remains the same. I need a piece of code that turns on the LED when I am fluctuating high and low, and then off when I am disconnected and my voltage is sitting very very low(close to zero)....
Maybe a 10K resistor tied to ground. A floating analog input will get noise so a pull down resistor could fix the problem.
I need a piece of code that turns on the LED when I am fluctuating high and low, and then off when I am disconnected and my voltage is sitting very very low
Then write one.
It is a simple missing pulse detector.
At each reading over a threshold then make a copy of the millis timer in a variable. Then check that the current value of millis() minus that variable is greater than some threshold time and if it is then turn off the LED.
Is there any way you could give me an example? I am a little new at this. Thanks for your help
I need anything you can help me out with. I have to get this implemented somehow and have been unsuccessful in every attempt
Why not just use a simple comparison? Something like:
if (analogRead(A0)<50){
digitalWrite (ledPin, LOW);
}
else {digitalWrite (ledPin, HIGH);
}
Because it will try to pull the light low and high at the same time
How can it do that? The output pin is either high or low at any one point in time.
Do you have something unusual wired up?
Im saying the signal is going up and down its an ac signal Im reading which means the voltage is changing