Monday, December 1, 2025

MUD LED Headlight dimmer Sunil Negi

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 PinDescriptionConnect To
VCC+5V supply for moduleArduino 5V
GNDGroundArduino GND
DO (Digital OUT)Becomes LOW when bright light hits the LDR; HIGH when darkArduino D2

(DO threshold is adjusted using the onboard potentiometer.)


✅ 2. Relay Module Pin Description (2-channel)

Relay module pins:

Relay PinDescriptionConnect To
VCC5V relay coil supplyArduino 5V
GNDGroundArduino GND
IN1Controls Relay 1Arduino D8
IN2Controls Relay 2Arduino D9

Relay screw terminals (for each relay):

TerminalMeaning
COMCommon
NONormally Open (connected when relay ON)
NCNormally Closed (connected when relay OFF)

We will use COM and NO only.


⚡ Bike Headlight Wires (Typical)

Bike WireFunction
WhiteHigh Beam
Blue / YellowLow Beam
Green / BlackGround

Complete Step-by-Step Wiring Guide


🔹 STEP 1: LDR Module → Arduino

LDR PinArduino
VCC5V
GNDGND
DOD2

DO pin logic:

  • Bright incoming headlight → DO = LOW

  • Normal dark road → DO = HIGH


🔹 STEP 2: Relay Module → Arduino

Relay PinArduino
IN1D8
IN2D9
VCC5V
GNDGND

🔹 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 NOHigh Beam wire (White)

Relay 2 → Low Beam

  • Relay2 COM → Bike +12V

  • Relay2 NOLow 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

MUD Three Mode operation Manual Automatic GPS

 Code for three mode operation: /*   3-Mode Headlight Controller   - Manual mode (driver uses a toggle to pick high/low)   - Auto mode (LDR...