Coming back from a while away from Arduino so I seem to have gotten rusty.
I'm using these IR sensors to turn on an an LED. 1 sensor to 1 LED. When using this first set of code, the LED comes on at full brightness, obviously it stays on as there's no code to turn off.
int rSensor = A0;
int gSensor = A1;
int wSensor = A2;
int rLed = 9;
int gLed = 8;
int wLed = 10;
void setup() {
Serial.begin (9600);
pinMode (rLed, OUTPUT);
pinMode (gLed, OUTPUT);
pinMode (wLed, OUTPUT);
pinMode (rSensor, INPUT);
pinMode (gSensor, INPUT);
pinMode (wSensor, INPUT);
}
void loop() {
int rSensor = analogRead(A0);
int gSensor = analogRead(A1);
int wSensor = analogRead(A2);
Serial.println(rSensor);
if (rSensor < 200){
digitalWrite(rLed, HIGH);
}
if (gSensor < 200){
digitalWrite(gLed, HIGH);
}
if (wSensor < 200){
digitalWrite(wLed, HIGH);
}
}
But when i use an ELSE function to turn the light back off when the sensor stops sending a signal, the LEDs only come on very faintly.
int rSensor = A0;
int gSensor = A1;
int wSensor = A2;
int rLed = 9;
int gLed = 8;
int wLed = 10;
void setup() {
Serial.begin (9600);
pinMode (rLed, OUTPUT);
pinMode (gLed, OUTPUT);
pinMode (wLed, OUTPUT);
pinMode (rSensor, INPUT);
pinMode (gSensor, INPUT);
pinMode (wSensor, INPUT);
}
void loop() {
int rSensor = analogRead(A0);
int gSensor = analogRead(A1);
int wSensor = analogRead(A2);
Serial.println(rSensor);
if (rSensor < 200){
digitalWrite(rLed, HIGH);
}
else (rSensor > 300);
{
digitalWrite(rLed, LOW);
}
if (gSensor < 200){
digitalWrite(gLed, HIGH);
}
else (gSensor > 300);
{
digitalWrite(gLed, LOW);
}
if (wSensor < 200){
digitalWrite(wLed, HIGH);
}
else (wSensor > 300);
{
digitalWrite(wLed, LOW);
}
}
The LEDs are each wired 5v in, out to a 330 ohm resistor, and then to GND. I'm just struggling to see why the use of the ELSE function makes them only light up very dimly.
Thanks