Smart Automatic Backup Lamp With Touch-Dimming

by abtAmit in Circuits > Microcontrollers

156 Views, 1 Favorites, 0 Comments

Smart Automatic Backup Lamp With Touch-Dimming

WhatsApp Image 2026-03-02 at 2.44.38 AM.jpeg

Have you ever fumbled in the dark looking for a switch during a sudden power outage? Current market solutions for power outages fall into two categories, both of which have significant limitations:

  1. Standard Emergency Lamps: These are entirely manual. If left on by mistake, they drain the battery completely, and when the power goes out, you still have to hunt for the switch.
  2. Commercial Rechargeable Bulbs (Inverter Bulbs): To charge the internal battery, your wall switch often needs to be kept in the 'ON' position. This leads to situations where the light is ON when not needed just to ensure it charges, resulting in a significant waste of electricity.


Supplies

1x Arduino Nano (any microcontroller)

1x LDR (Light Dependent Resistor / Photocell)

1x Standard Resistor

1x 3.7V Lithium Polymer Battery

1x TP4056 Battery Charging Module

1x TTP223 Touch Sensor

1x IRFZ44N MOSFET

1x High-brightness LED

Features

Before wiring it up, here is what makes this lamp "smart":

  1. Intelligent Automation: The LDR constantly monitors the room's light levels. It only kicks on when the environment is actually dark.
  2. Touch Dimming: The TTP223 sensor is more than just an on/off switch. By long-pressing the sensor, you can adjust the brightness via PWM, allowing you to save battery or set a mood.
  3. Soft-Off (Grace Period): Sensitive touch sensors often cause accidental blackouts. To prevent this, when you tap to turn the lamp off, it blinks and waits 5 seconds before cutting the power. If you touch the sensor again during this countdown, the shutdown is canceled!


Wiring the Power Supply


The TP4056 module handles charging the battery safely and supplies power to the Arduino. Because the ATmega328 on the Nano can run from 1.8V to 5V, the 3.5V–4.2V range of the Li-ion battery can be connected directly to it.

Connections:

  1. Battery (+) ➔ TP4056 B+
  2. Battery (-) ➔ TP4056 B-
  3. TP4056 OUT+ ➔ Arduino Nano 5V Pin (This will also connect to the LED Anode)
  4. TP4056 OUT- ➔ Arduino Nano GND


Connecting the Sensors

smartLamp.jpeg
IMG-20260116-WA0010.jpg
IMG-20260116-WA0006.jpg
IMG-20260116-WA0008.jpg
IMG-20260116-WA0004.jpg


LDR (Light Sensor):

  1. LDR Leg 1 ➔ Arduino 5V
  2. LDR Leg 2 ➔ Arduino A1
  3. Resistor Leg 1 ➔ Arduino A1 (Shares the pin with LDR Leg 2)
  4. Resistor Leg 2 ➔ Arduino GND

TTP223 Touch Sensor:

  1. VCC ➔ Arduino 5V
  2. GND ➔ Arduino GND
  3. I/O Pin ➔ Arduino D6


Connecting the LED & MOSFET

WhatsApp Image 2026-03-01 at 5.15.08 PM.jpeg


You can control one or two led directly but the Arduino pins cannot supply enough current to directly power a bright powerful LED, we use the IRFZ44N MOSFET as an electronic switch.

MOSFET & LED Connections:

  1. Gate (Pin 1) ➔ Arduino D11
  2. Drain (Pin 2) ➔ LED Negative
  3. Source (Pin 3) ➔ Arduino GND
  4. LED Positive TP4056 OUT+


Working of Code


Stable Readings: The Arduino reads the LDR sensor 50 times rapidly (with a 1ms delay) and calculates the average to get a stable, reliable value. A higher value (> 800) means Dark, and a lower value means Bright. The lamp turn on or off according to these values.


Anti-Flicker Mechanism: This is the most important part of the code! When the lamp turns on in a dark room, the room suddenly becomes bright. If the Arduino checked the light level normally, it would think, "It's bright now!" and turn the lamp off, causing endless flickering.

The Fix: Immediately after turning the LED on, the code waits 500ms for the system to stabilize. It then takes a new brightness reading which also includes the lamp's own light and saves it as a current_reference variable. This value effectively becomes the new baseline. The Arduino is now saying, "Okay, this brightness level is the new 'Dark'. I will ignore this much light."


code: SmartLamp

Downloads

Testing the Prototype

Smart Lamp demo

Before adding the circuit inside lamp i need to test it so that if any problem occur i can fix it easily


The Final Assembly

Diy SmartLamp
F4PPJG5MM59MEEY.jpg

Placing all the circuit inside the lamp to give it a better look.

make sure that you place the LDR slightly above the LED other wise the LDR will be overwhelmed by the led light.

In the second video you can see that you can also turn ON the lamp in Daylight also but it wont automatically turn OFF.