When I apply 5v to A15 using the 5v on the Arduino board, LED turns ON instantly. But when I pull the 5v from A15, led turn OFF about half a second later.
Is there a way to make it turn off instantly?
How can I turn on multiple leds with one line of code? (ledred1, ledred2, HIGH) (ledred1 + ledred 2, HIGH)?
Here's my code. It's not finished yet.
int ledgr1 = 5;
int ledgr2 = 6;
int ledgr3 = 7;
int ledor1 = 8;
int ledor2 = 9;
int ledor3 = 10;
int ledred1 = 11;
int ledred2 = 12;
int ledred3 = 13;
unsigned long rpm;
void setup(){
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
}
void loop(){
int sensorValue = analogRead(A15);
float voltage = sensorValue * (5.0 / 1023.0);
Serial.println(voltage);
{
}
if (voltage > 4) digitalWrite (ledred1, HIGH);
if (voltage < 4) digitalWrite (ledred1, LOW);
}
My guess is that the ADC value is not falling as quickly as you think it is.
Get the program to print the actual value returned by the ADC.
Also, you don't have any dead band between ON and OFF so it may be flickering so fast you can't see it.
Better to make it go on if > 4.0 and off if less than (say) 3.9
It would also make sense to get rid of the float stuff. 4v should be 818. So why not just say
This is an important question. If you attach 5V to an Arduino pin, and then simply remove that wire, the pin will actually STAY at 5V for a while, because there is no place for the the charge to go (essentially.) A TINY bit is used by the arduino, but not enough to return the pin to a lower voltage "instantly."
The circuitry to fix this doesn't need to be complex; a simple pull-down resistor will do it, but you have to pick the value somewhat carefully to avoid interfering with whatever analog source you will actually have driving the pin.
westfw:
This is an important question. If you attach 5V to an Arduino pin, and then simply remove that wire, the pin will actually STAY at 5V for a while, because there is no place for the the charge to go (essentially.) A TINY bit is used by the arduino, but not enough to return the pin to a lower voltage "instantly."
The circuitry to fix this doesn't need to be complex; a simple pull-down resistor will do it, but you have to pick the value somewhat carefully to avoid interfering with whatever analog source you will actually have driving the pin.
That explains it. Thanks
Another question. With nothing hooked up on A15, the leds with the lower volt setting light up. Those are set at 200,250,300 (roughly 1, 1.25 and 1.5v volts).
This is with a LM2596 hooked up to 12v battery stepped down to 9v.
You can't write to several pins with a single digitalWrite().
If you really need to do that you need to learn about port manipulation - but I doubt if that is necessary.
Put your LED pin numbers into an array and you can update them all like this
for (n = 0; n < numLeds; n++) {
digitalWrite(ledPinArray[n] = LOW;
}