I have 3 sensors that output 0-1024 values and they are connected to an Arduino, which i want to light up 3 LEDs, each LED when a corresponding sensor sends a value over a certain threshold.
My problem is, that every time 1 of the sensors goes over the threshold value, all the 3 LEDs light up, instead of only one.
What could be the problem?
Here is the code:
int RedLED = 5;
int GreenLED = 6;
int BlueLED = 7;
int RedLEDinput = A0;
int GreenLEDinput = A1;
int BlueLEDinput = A2;
#define Threshold 500
void setup() {
pinMode(RedLED, OUTPUT);
pinMode(GreenLED, OUTPUT);
pinMode(BlueLED, OUTPUT);
pinMode(RedLEDinput,INPUT);
pinMode(GreenLEDinput,INPUT);
pinMode(BlueLEDinput,INPUT);
}
void loop() {
if (analogRead(RedLEDinput)>=Threshold){
digitalWrite(RedLED, HIGH);
}
else if (analogRead(RedLEDinput)<Threshold){
digitalWrite(RedLED, LOW);
}
if (analogRead(GreenLEDinput)>=Threshold){
digitalWrite(GreenLED, HIGH);
}
else if (analogRead(GreenLEDinput)<Threshold){
digitalWrite(GreenLED, LOW);
}
if (analogRead(BlueLEDinput)>=Threshold){
digitalWrite(BlueLED, HIGH);
}
else if (analogRead(BlueLEDinput)<Threshold){
digitalWrite(BlueLED, LOW);
}
}
Your topic was MOVED to its current forum category which is more appropriate than the original as it has nothing to do with Installation and Troubleshooting of the IDE