Multi Light Sensor Switch

by corich417 in Circuits > Arduino

40 Views, 0 Favorites, 0 Comments

Multi Light Sensor Switch

Screenshot 2025-05-01 at 5.04.50 PM.png

I created a project that combines a DIP switch and a photoresistor to control three LEDs using an Arduino Uno R3. This project merges two smaller concepts—the use of DIP switches and light sensors—into a single interactive lighting system. I was inspired to combine these elements to explore how conditional input from both a sensor and manual switches can control output behavior in a smart way.

Supplies

  1. 1x 3-position DIP switch (or 3 individual SPST slide switches)
  2. 1x Photoresistor (LDR)
  3. 3x LEDs (preferably in different colors)
  4. 17x Male-to-male jumper wires
  5. 1x Small breadboard
  6. 1x Arduino Uno R3
  7. 7x Resistors (appropriate values for LEDs and the photoresistor circuit)

Upload the Code

Multi_light_sensor.png

Upload the following code to your Arduino using the Arduino IDE:


// These sections of code are here to make sure the Arduino Uno knows where the LEDs are on the breadboard
const byte CABIN_LIGHTS_PIN = 10;
const byte STORAGE_LIGHTS_PIN = 11;
const byte COCKPIT_LIGHTS_PIN = 12;

const byte CABIN_LIGHTS_SWITCH_PIN = 2;
const byte STORAGE_LIGHTS_SWITCH_PIN = 3;
const byte COCKPIT_LIGHTS_SWITCH_PIN = 4;

// Analog sensor input, and that the code knows that a sensor value should exist
const byte SENSOR_PIN = A0;

//The void setup is here to make sure that this section of code is only in effect when the code starts, and that the value of the sensor begins at 9600, and then the value decreases from there
void setup() {
Serial.begin(9600);
pinMode(CABIN_LIGHTS_PIN, OUTPUT);
pinMode(STORAGE_LIGHTS_PIN, OUTPUT);
pinMode(COCKPIT_LIGHTS_PIN, OUTPUT);

pinMode(CABIN_LIGHTS_SWITCH_PIN, INPUT);
pinMode(STORAGE_LIGHTS_SWITCH_PIN, INPUT);
pinMode(COCKPIT_LIGHTS_SWITCH_PIN, INPUT);
}

//The void loop is here to make sure that this section of code is in effect forever
void loop() {
int sensorValue = analogRead(SENSOR_PIN);
Serial.println(sensorValue);

bool sensorCondition = sensorValue <600; // Change threshold as needed, and when the sensor value is less than 600, the LEDs will trigger to turn on if both the switch is on, and if you are touching the photoresistor, if you are touching the photoresistor and the switch is not on, then the LED will not light up


if (digitalRead(CABIN_LIGHTS_SWITCH_PIN) == HIGH && sensorCondition) {
digitalWrite(CABIN_LIGHTS_PIN, HIGH);
} else {
digitalWrite(CABIN_LIGHTS_PIN, LOW);
}

if (digitalRead(STORAGE_LIGHTS_SWITCH_PIN) == HIGH && sensorCondition) {
digitalWrite(STORAGE_LIGHTS_PIN, HIGH);
} else {
digitalWrite(STORAGE_LIGHTS_PIN, LOW);
}

if (digitalRead(COCKPIT_LIGHTS_SWITCH_PIN) == HIGH && sensorCondition) {
digitalWrite(COCKPIT_LIGHTS_PIN, HIGH);
} else {
digitalWrite(COCKPIT_LIGHTS_PIN, LOW);
}
}


This code ensures that each LED only turns on if both the corresponding DIP switch is in the ON position and the photoresistor detects a light level below the threshold.

Connect the Jumper Wires

Multi_light_sensor (1).png

Use 17 male-to-male jumper wires:

  1. 9 wires connect the Arduino to the breadboard (for LEDs, switches, and the sensor).
  2. 8 wires are used on the breadboard to interconnect components.

Color-coding your wires can help you keep track of connections more easily.

Insert the LEDs

Multi_light_sensor (2).png

Place three LEDs into the breadboard. Use different colors (e.g., red, green, and blue) to represent different zones or labels (e.g., cockpit, storage, cabin). Connect each LED in series with a resistor (typically 220Ω) to prevent them from burning out.

Install the DIP Switch

Multi_light_sensor (4).png

Insert your 3-position DIP switch into the breadboard. Connect each of the three pins on one side to digital pins 2, 3, and 4 on the Arduino (using a pull-down resistor if needed). Connect the corresponding opposite side pins to 5V so that each switch acts as a simple HIGH/LOW toggle.

The DIP switch allows you to manually enable or disable each LED, and it must be ON (HIGH) along with the proper light condition for the LED to light up.

Connect the Photoresistor

Multi_light_sensor (5).png

Place the photoresistor (LDR) into the breadboard. Connect one leg to 5V and the other to both analog pin A0 and a pull-down resistor (10kΩ) going to GND. This setup forms a voltage divider, enabling the Arduino to read light levels.

Insert the Resistors

Multi_light_sensor (6).png

Install seven resistors total:

  1. 3x resistors (220Ω) for the LEDs
  2. 1x 10kΩ resistor for the photoresistor voltage divider
  3. 3x resistors (10kΩ) as pull-downs for the DIP switch pins (unless using INPUT_PULLUP in software)

Resistors ensure proper functionality and protect components from excess current.

Upload and Test

  1. Paste the code into the Arduino IDE and upload it.
  2. Flip the DIP switches to ON.
  3. Cover or touch the photoresistor to simulate low light conditions.
  4. The corresponding LEDs should light up only if:
  5. The switch for that LED is ON.
  6. The light level is below the threshold.

If it’s not working:

  1. Use the Serial Monitor to read sensorValue and adjust the threshold.
  2. Double-check wiring and resistor values.