Code for LDR testing : -
int ldrPin = 2; // LDR module digital output
int relayHigh = 8; // Relay 1 - High Beam
int relayLow = 9; // Relay 2 - Low Beam
void setup() {
pinMode(ldrPin, INPUT);
pinMode(relayHigh, OUTPUT);
pinMode(relayLow, OUTPUT);
// Default condition - Low Beam ON
digitalWrite(relayHigh, LOW);
digitalWrite(relayLow, HIGH);
}
void loop() {
int ldrState = digitalRead(ldrPin);
if (ldrState == LOW) {
// Bright headlight detected → Switch to LOW Beam
digitalWrite(relayHigh, LOW);
digitalWrite(relayLow, HIGH);
} else {
// Normal dark road → Switch to HIGH Beam
digitalWrite(relayLow, LOW);
digitalWrite(relayHigh, HIGH);
}
delay(100);
}
✅ 1. LDR Module Pin Description (3-pin type)
A typical LDR module has these pins:
| LDR Module Pin | Description | Connect To |
|---|---|---|
| VCC | +5V supply for module | Arduino 5V |
| GND | Ground | Arduino GND |
| DO (Digital OUT) | Becomes LOW when bright light hits the LDR; HIGH when dark | Arduino D2 |
(DO threshold is adjusted using the onboard potentiometer.)
✅ 2. Relay Module Pin Description (2-channel)
Relay module pins:
| Relay Pin | Description | Connect To |
|---|---|---|
| VCC | 5V relay coil supply | Arduino 5V |
| GND | Ground | Arduino GND |
| IN1 | Controls Relay 1 | Arduino D8 |
| IN2 | Controls Relay 2 | Arduino D9 |
Relay screw terminals (for each relay):
| Terminal | Meaning |
|---|---|
| COM | Common |
| NO | Normally Open (connected when relay ON) |
| NC | Normally Closed (connected when relay OFF) |
We will use COM and NO only.
⚡ Bike Headlight Wires (Typical)
| Bike Wire | Function |
|---|---|
| White | High Beam |
| Blue / Yellow | Low Beam |
| Green / Black | Ground |
⭐ Complete Step-by-Step Wiring Guide
🔹 STEP 1: LDR Module → Arduino
| LDR Pin | Arduino |
|---|---|
| VCC | 5V |
| GND | GND |
| DO | D2 |
DO pin logic:
-
Bright incoming headlight → DO = LOW
-
Normal dark road → DO = HIGH
🔹 STEP 2: Relay Module → Arduino
| Relay Pin | Arduino |
|---|---|
| IN1 | D8 |
| IN2 | D9 |
| VCC | 5V |
| GND | GND |
🔹 STEP 3: Bike Headlight → Relay (2-Relay Method)
We are supplying +12V to the relays, each relay powers one beam.
Relay 1 → High Beam
-
Relay1 COM → Bike +12V (through a fuse)
-
Relay1 NO → High Beam wire (White)
Relay 2 → Low Beam
-
Relay2 COM → Bike +12V
-
Relay2 NO → Low Beam wire (Blue/Yellow)
Ground Wire:
-
Headlight ground wire → Bike chassis ground
(No connection to relays)
🔹 STEP 4: Arduino Power
You must power Arduino using:
✔ USB 5V powerbank
OR
✔ Bike 12V → 5V converter (buck converter)
DO NOT connect bike 12V directly to Arduino 5V pin.
✔ Working Logic
-
When another vehicle shines light → LDR module output becomes LOW → Arduino activates Relay 2 → Low Beam.
-
When road is dark → LDR module output becomes HIGH → Arduino activates Relay 1 → High Beam.
No comments:
Post a Comment