Maharashtra HSC Electronics Field Technician (NSQF F6) study materials
Maharashtra HSC Electronics Field Technician (NSQF F6) study resources

Street-Light Relay Chattering on an Arduino Controller

Maharashtra HSC Electronics Field Technician (NSQF F6) · Put your knowledge to work in context.

All case studies

Street-Light Relay Chattering on an Arduino Controller

A trainee builds an automatic street-light controller using an Arduino Uno, an LDR divider and an active-LOW relay module. The LDR forms a divider with a 10 kΩ resistor from 5 V, and the junction goes to A0. The program switches the relay on when the ADC value exceeds 500 and off when it falls below 500. At dusk the relay chatters for about two minutes as the sky darkens; the serial monitor shows ADC values fluctuating between 480 and 520. The relay coil draws 70 mA at 5 V and has no flyback diode. The Arduino is powered from a 9 V 500 mA adapter, and the relay module shares the same ground. A street light and a nearby shop's flickering sign are both supplied from the same phase. The trainee proposes increasing the ADC threshold to 700.

1. Explain why raising the threshold to 700 will not reliably stop the chattering, and write pseudocode with hysteresis and debounce that will.

Read the worked answer

A single threshold of 700 simply moves the decision point. The ADC still fluctuates as the sky darkens, and any value that crosses 700 will cause the same rapid switching. If 700 is above the normal dusk range (480–520), the lamp may never turn on. The correct fix is hysteresis: use a higher threshold to turn on and a lower threshold to turn off, plus a time delay to ignore short spikes.

onThreshold = 550; offThreshold = 450;
loop every 100 ms:
  read adc;
  if relay is OFF and adc > onThreshold:
     wait 2 s; read adc again;
     if adc > onThreshold: relay ON;
  if relay is ON and adc < offThreshold:
     wait 2 s; read adc again;
     if adc < offThreshold: relay OFF;

This creates a dead band and prevents chatter from headlights or sign flicker.

2. Identify two hardware causes of the unstable ADC readings and one protection component missing from the relay circuit.

Read the worked answer

Two causes are: (1) the relay coil has no flyback diode, so when it switches off the inductive kick appears on the 5 V/ground rail and corrupts the ADC; (2) the 9 V adapter and relay share the same supply and ground, so the 70 mA coil current causes rail sag and noise, especially with a long breadboard ground. The missing component is a flyback diode (for example 1N4007) connected across the relay coil, cathode to +5 V. Also add a 100 µF electrolytic plus a 0.1 µF ceramic capacitor across the relay module supply, keep the LDR wiring short, and consider a separate 5 V supply for the relay with a common ground. These measures reduce the noise that the software alone cannot cure.

3. Estimate the relay coil power and comment on powering it from the Arduino 5 V pin.

Read the worked answer

The coil power is P = V × I = 5 × 0.07 = 0.35 W, and the coil resistance is about 5/0.07 ≈ 71 Ω. The Arduino 5 V pin is not intended to supply 70 mA of inductive load, especially from a 9 V adapter through the on-board regulator; the rail may sag, reset the MCU, or overheat the regulator. Use a separate 5 V supply for the relay module, or drive the relay through a transistor with a base resistor and a flyback diode. Keep the logic ground common. If the module already has an opto-isolator and driver transistor, check its current requirement and still provide adequate decoupling. The relay contact circuit should be fused and kept physically separated from the low-voltage wiring.