I'm relatively new to programming and I'm trying to get light sensors to activate an array of lights. The idea is to have 4 LDR (Light Dependent Resistors) capture light, and if any 3 out of the 4 LDRs are activated, then it will set off the array.
I keep running into an issue with the third sensor (buttonState3) routinely fails in the circuit.
In the MULTI SENSOR SWITCHING section.
When the third sensor (buttonState3) is used to activate the array the voltage is low. If the array is activated using the other 3 sensors then the array voltage is nominal. The problem is all in the program, because I switched the analog inputs for the third(A3) and forth(A4) sensors to the same result. The LDR in place for the third senor (buttonState3) would still cause a low voltage. Furthermore, using senor 3's LDR(A3) would still allow the forth sensor (buttonState4) to operate normally.
The program is attached, along with photographs of the test board and wiring diagram. The diagram does not include the additional LEDs for the individual INPUTS. They are only there for test-bench purposes. Each LED is sent to ground via a 220ohm resistor. I have omitted parts of the program that are irrelevant to shorten the post.
Due to file size restrictions the photos are on a google drive folder here:
https://drive.google.com/drive/folders/1uHbRg69BOpC7-nKW2-xNQy3I7CWcaBNX?usp=sharing
// MULTI SENSOR SWITCHING
//OUTPUTS
const int LDR1 = 7;
const int LDR2 = 9;
const int LDR3 = 11;
const int LDR4 = 13;
//INPUTS
const int LDR1IN = 6;
const int LDR2IN = 8;
const int LDR3IN = 10;
const int LDR4IN = 12;
// INPUT READS
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
//EXTERNAL POWER AND DISPLAY
const int HD_SW = 5;
const int PWR_ON = 4;
const int HD_ON = 3; //TEST LED
//LIGHT DEPENDENT RESISTEOR LEVELS
const int SENSOR1 = 0;
const int SENSOR2 = 0;
const int SENSOR3 = 0;
const int SENSOR4 = 0;
int val = 0;
int old_val = 0;
int LDRA1 = 0;
int LDRA2 = 0;
int LDRA3 = 0;
int LDRA4 = 0;
void setup() {
Serial.begin(9600);
pinMode(LDR1, OUTPUT);
pinMode(LDR2, OUTPUT);
pinMode(LDR3, OUTPUT);
pinMode(LDR4, OUTPUT);
pinMode(LDR1IN, INPUT);
pinMode(LDR2IN, INPUT);
pinMode(LDR3IN, INPUT);
pinMode(LDR4IN, INPUT);
pinMode(HD_ON, OUTPUT);
pinMode(PWR_ON, OUTPUT);
pinMode(HD_SW, OUTPUT);
}
void loop() {
// MULTI SENSOR SWITCHING
buttonState1 = digitalRead(LDR1IN);
buttonState2 = digitalRead(LDR2IN);
buttonState3 = digitalRead(LDR3IN);
buttonState4 = digitalRead(LDR4IN);
if ((buttonState1 == HIGH) && (buttonState2 == HIGH) && (buttonState3 == HIGH)){
digitalWrite(HD_ON, HIGH);
}
if ((buttonState2 == HIGH) && (buttonState3 == HIGH) && (buttonState4 == HIGH)){
digitalWrite(HD_ON, HIGH);
}
if ((buttonState3 == HIGH) && (buttonState4 == HIGH) && (buttonState1 == HIGH)){
digitalWrite(HD_ON, HIGH);
}
if ((buttonState4 == HIGH) && (buttonState1 == HIGH) && (buttonState2 == HIGH)){
digitalWrite(HD_ON, HIGH);
} else {
digitalWrite(HD_ON, LOW); //if none of the above statements are met the LED will default to LOW
}
}