So the current program is for lights on a roundhouse garage for a Model Railroad, when there is a train in the stall the sensor is tripped low so a red light turns on. If the stall is empty the sensor is not tripped it reads high and a green light turns on. I want to add led lights on the inside and want them to turn on for a specific time when a sensor change in state for any of the sensors.
int LDR1 = 0;
int LDR2 = 0;
int LDR3 = 0;
int LDR4 = 0;
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(A0, INPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(A1, INPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(A2, INPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(A3, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
LDR1 = analogRead(A0);
Serial.println(LDR1);
if (LDR1 < 712)
{
digitalWrite(13, 1);
digitalWrite(12, 0);
}
else if (LDR1 > 712)
{
digitalWrite(13, 0);
digitalWrite(12, 1);
}
LDR2 = analogRead(A1);
Serial.println(LDR2);
if (LDR2 < 712)
{
digitalWrite(11, 1);
digitalWrite(10, 0);
}
else if (LDR2 > 712)
{
digitalWrite(11, 0);
digitalWrite(10, 1);
}
LDR3 = analogRead(A2);
Serial.println(LDR3);
if (LDR3 < 712)
{
digitalWrite(9, 1);
digitalWrite(8, 0);
}
else if (LDR3 > 712)
{
digitalWrite(9, 0);
digitalWrite(8, 1);
} LDR4 = analogRead(A3);
Serial.println(LDR4);
if (LDR4 < 712)
{
digitalWrite(7, 1);
digitalWrite(6, 0);
}
else if (LDR4 > 712)
{
digitalWrite(7, 0);
digitalWrite(6, 1);`Use code tags to format code for the forum`
}
}
Welcome to the Arduino forum. Do you have the lights installed? Do you have power for the lights? The only function for your Arduino is just to turn on and off when you want. You can't power the light from an Arduino.
Firstly, you only need one output for each LED pair. Wire the output to one LED, then resistor to +, same output to other LED to resistor to GND. When the output is high, one LED will be on, when the output is low, the other LED will be on. That small change lets you run 14 LEDs on seven sensors. Now, add in your timed light function on the remaining outputs. Forget the second Arduino. If at some point you want both LEDs off, just set the pin as an INPUT.