Arduino UNO Controlled LED Lighting System with DIP Switch Control
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to control multiple LEDs using an Arduino UNO microcontroller and a 3-position DIP switch. The LEDs are connected through resistors to various digital pins on the Arduino. The DIP switch is used to select which LEDs are turned on based on the switch positions. The Arduino code reads the switch positions and controls the LEDs accordingly.
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
LED: Two Pin (red)
- Description: A red LED with two pins.
- Pins: cathode, anode
DIP Switch 3 Position
- Description: A 3-position DIP switch.
- Pins: 1, 2, 3, 4, 5, 6
Resistor
- Description: A resistor with varying resistance values.
- Pins: pin1, pin2
- Properties:
- Resistance: 10 Ohms, 200 Ohms, 220 Ohms, 10000 Ohms
Wiring Details
Arduino UNO
- 5V: Connected to pins 4, 5, and 6 of the DIP Switch.
- GND: Connected to pin1 of multiple resistors and cathode of multiple LEDs.
- D2: Connected to pin2 of a 10000 Ohms resistor and pin 3 of the DIP Switch.
- D3: Connected to pin2 of a 10000 Ohms resistor and pin 2 of the DIP Switch.
- D4: Connected to pin2 of a 10000 Ohms resistor and pin 1 of the DIP Switch.
- D6: Connected to pin1 of a 220 Ohms resistor.
- D7: Connected to pin1 of a 220 Ohms resistor.
- D8: Connected to pin1 of a 220 Ohms resistor.
- D9: Connected to pin1 of a 220 Ohms resistor.
- D10: Connected to pin1 of a 220 Ohms resistor.
- D11: Connected to pin1 of a 220 Ohms resistor.
- D12: Connected to pin1 of a 220 Ohms resistor.
LED: Two Pin (red)
- cathode: Connected to GND of Arduino UNO.
- anode: Connected to pin2 of various resistors.
DIP Switch 3 Position
- 1: Connected to pin2 of a 10000 Ohms resistor and D4 of Arduino UNO.
- 2: Connected to pin2 of a 10000 Ohms resistor and D3 of Arduino UNO.
- 3: Connected to pin2 of a 10000 Ohms resistor and D2 of Arduino UNO.
- 4: Connected to 5V of Arduino UNO.
- 5: Connected to 5V of Arduino UNO.
- 6: Connected to 5V of Arduino UNO.
Resistor
- 10 Ohms: Not used in this circuit.
- 200 Ohms: Not used in this circuit.
- 220 Ohms: Connected between various digital pins of Arduino UNO and anodes of LEDs.
- 10000 Ohms: Connected between DIP switch pins and digital pins of Arduino UNO.
Code Documentation
const int AREA_1_LIGHTS_PIN = 6;
const int AREA_2_LIGHTS_PIN = 7;
const int AREA_3_LIGHTS_PIN = 8;
const int AREA_4_LIGHTS_PIN = 9;
const int AREA_5_LIGHTS_PIN = 10;
const int AREA_6_LIGHTS_PIN = 11;
const int AREA_7_LIGHTS_PIN = 12;
const int PIN_1_SWITCH = 2;
const int PIN_2_SWITCH = 3;
const int PIN_3_SWITCH = 4;
void setup() {
// put your setup code here, to run once:
pinMode(AREA_1_LIGHTS_PIN, OUTPUT);
pinMode(AREA_2_LIGHTS_PIN, OUTPUT);
pinMode(AREA_3_LIGHTS_PIN, OUTPUT);
pinMode(AREA_4_LIGHTS_PIN, OUTPUT);
pinMode(AREA_5_LIGHTS_PIN, OUTPUT);
pinMode(AREA_6_LIGHTS_PIN, OUTPUT);
pinMode(AREA_7_LIGHTS_PIN, OUTPUT);
pinMode(PIN_1_SWITCH, INPUT);
pinMode(PIN_2_SWITCH, INPUT);
pinMode(PIN_3_SWITCH, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if ((digitalRead(PIN_1_SWITCH) == HIGH ) && (digitalRead(PIN_2_SWITCH) == LOW ) && (digitalRead(PIN_3_SWITCH) == LOW )){
digitalWrite(AREA_1_LIGHTS_PIN, HIGH);
} else {
digitalWrite(AREA_1_LIGHTS_PIN, LOW);
}
if ((digitalRead(PIN_1_SWITCH) == LOW ) && (digitalRead(PIN_2_SWITCH) == HIGH ) && (digitalRead(PIN_3_SWITCH) == LOW )){
digitalWrite(AREA_2_LIGHTS_PIN, HIGH);
} else {
digitalWrite(AREA_2_LIGHTS_PIN, LOW);
}
if ((digitalRead(PIN_1_SWITCH) == HIGH ) && (digitalRead(PIN_2_SWITCH) == HIGH ) && (digitalRead(PIN_3_SWITCH) == LOW )){
digitalWrite(AREA_3_LIGHTS_PIN, HIGH);
} else {
digitalWrite(AREA_3_LIGHTS_PIN, LOW);
}
if ((digitalRead(PIN_1_SWITCH) == LOW ) && (digitalRead(PIN_2_SWITCH) == LOW ) && (digitalRead(PIN_3_SWITCH) == HIGH )){
digitalWrite(AREA_4_LIGHTS_PIN, HIGH);
} else {
digitalWrite(AREA_4_LIGHTS_PIN, LOW);
}
if ((digitalRead(PIN_1_SWITCH) == HIGH ) && (digitalRead(PIN_2_SWITCH) == LOW ) && (digitalRead(PIN_3_SWITCH) == HIGH )){
digitalWrite(AREA_5_LIGHTS_PIN, HIGH);
} else {
digitalWrite(AREA_5_LIGHTS_PIN, LOW);
}
if ((digitalRead(PIN_1_SWITCH) == LOW ) && (digitalRead(PIN_2_SWITCH) == HIGH ) && (digitalRead(PIN_3_SWITCH) == HIGH )){
digitalWrite(AREA_6_LIGHTS_PIN, HIGH);
} else {
digitalWrite(AREA_6_LIGHTS_PIN, LOW);
}
if ((digitalRead(PIN_1_SWITCH) == HIGH ) && (digitalRead(PIN_2_SWITCH) == HIGH ) && (digitalRead(PIN_3_SWITCH) == HIGH )){
digitalWrite(AREA_7_LIGHTS_PIN, HIGH);
} else {
digitalWrite(AREA_7_LIGHTS_PIN, LOW);
}
}
This code sets up the pins for the LEDs and the DIP switch. In the loop function, it reads the state of the DIP switch and turns on the corresponding LED based on the switch positions.