Touchless Lamp –

What should you pick when you want to build a touchless lamp or light switch? A sensor of course! This is a design of a touchless lamp with a common and cheap reflective optical sensor. With a Digispark Attiny85 microcontroller core, this project allows you to create your own enhanced version.

Setting up the hardware:

The following figure depicts the full circuit diagram for this project. The circuit is powered by a compact switch mode power supply module, and the reflective sensor is used to control an external dc lamp wired to the circuit’s output. The digital toggle switch action can be induced by bringing your forefinger (or thumb) close to the sensor’s eye.

The TCRT5000 reflective sensor (SENS-1) is connected directly to the P0 input of the Attiny85 microcontroller development board (DIGISPARK) with one 56K resistor (R2) and one 2.2uF capacitor (C1) to set the sensitivity and to suppress noise. The first 220Ω resistor (R1) limits the operating current of the 950nm infrared emitter inside the reflective sensor. The HLK 5M-05 power supply module (HLK1) provides clean 5VDC supply voltage for the entire electronics. Two red LEDs pre-soldered on the Digispark board are utilized to indicate the status of the power supply and toggle switch. The sensor’s eye responds to hand gestures within 30mm range. That is enough for this application.

Only a ‘small’ power mosfet is needed here. The common IRLZ44 power mosfet (T1) is a handy component at that time. There is an important thing you have to pay attention to if you substitute the power mosfet with another one. A standard power mosfet is not directly suitable for power driving (switching loads) with a microcontroller – you should pick a ‘logic-level’ type power mosfet as the drop-in replacement. As you can see in the schematic, P1 output of the Digispark board is routed to the gate of the power mosfet through resistors R3 and R4.

As mentioned before, the design is prepared primarily to drive external LED lamps (of course 5VDC types), and you simply need your fingertip for a touch-free toggle. Driving USB LED bulbs/strips is a typical example.

For this project, I designed a single-sided demo PCB. The download link of the Eagle and Gerber files will be posted. That way you can have your PCBs made by a professional PCB manufacturer of your choice. I avoided the use of chip parts to make it easy for one-offs home-brewers. On the other hand, if you want to go a step further and design your own PCB, you may use my PCB artwork for quick reference (or inspiration).

The proposed PCB layout lets you plug the Digispark board into headers soldered on the board. There can be no confusion as it can only be mounted the right way. Despite its compact dimensions, the HLK 5M-05 switch mode power supply module fulfills all requisites about isolation distances and clearances for use with AC line voltage. By contrast, the inputs pins are closer together. You may provide slots in the PCB to fulfill the clearance distance requirements. Although the IRLZ44 power mosfet can switch high currents, the actual current must be limited due to the width of the PCB tracks. Since some fiddling with the quick layout may be required to get a perfect PCB, you need to give it a hand.

Uploading the sketch

The code loaded into the Digispark determines the function of the toggle switch. The following Arduino Sketch has been prepared. The code can easily be adapted to add or modify functions. If you are new to Arduino and Digispark take a closer look at all the related articles published here. You will find an incredible amount of information.


* Touchless LED Lamp

* Author: T.K.Hareendran/ 06.2020

* Publisher:

* Adapted code - Thanks to Martyn Currey

* Centered on a Digispark Attiny85 microcontroller development board

* An LED lamp that can be toggled by means of hand gestures rather than by flipping a switch


int pin_LAMP = 1; // P1

int pin_SENS = 0; // P0

boolean oldSwitchState = LOW;

boolean newSwitchState1 = LOW;

boolean newSwitchState2 = LOW;

boolean newSwitchState3 = LOW;

boolean LampState = LOW;

void setup()


pinMode(pin_LAMP, OUTPUT);


pinMode(pin_SENS, INPUT);


void loop()


newSwitchState1 = digitalRead(pin_SENS);


newSwitchState2 = digitalRead(pin_SENS);


newSwitchState3 = digitalRead(pin_SENS);

if (  (newSwitchState1==newSwitchState2) && (newSwitchState1==newSwitchState3) )


if ( newSwitchState1 != oldSwitchState )


if ( newSwitchState1 == HIGH )


if ( LampState == LOW ) { digitalWrite(pin_LAMP, HIGH);  LampState = HIGH; }

else                    { digitalWrite(pin_LAMP, LOW);   LampState = LOW;  }


oldSwitchState = newSwitchState1;




First in-service test

Due to certain limitations, I started off with a mini breadboard prototype, and used a 1W star white LED (plus a 5.1Ω series resistor) as the ‘touchless lamp’. All tests were done inside my lab using a regulated 5VDC (1A) power supply module. The first prototype of my little system was now fully functional (watch the quick test movie)!

A few more details

The electronics must be housed in a strong, plastic enclosure so that it can be mounted on a wall neatly and securely. This a sample artwork of the proposed front panel layout. Although the whole circuit was originally put together quickly as a proof-of-concept, it has been in use for quite some time. I would recommend that the circuit be constructed in a safer way and in a tamper-proof enclosure if you intend to build yours as a ‘fit and forget’ model running unattended.

There are many solutions to turning AC230V electric lamps on and off through this touchless light switch device while leaving its core electronics intact. Here I cover the ways I was after to do with add-on circuits. The basic idea is to use a solid-state ‘power strip’ along with the actual lamp cable. In some cases, you cannot use a mechanical relay although it costs ten times less and bearing currents and voltages above a typical solid-state switch. In some cases, you may use a mechanical relay, but only a solid-state switch can give complete safety, to perfectly isolate the logic from electrical disturbances and sparks caused by certain heavy loads.

This is the circuit idea for the high-voltage (AC230V) solid-state switch (there are no problems up to a hundred watts). Be very careful, for safety reasons, you should use an insulated enclosure.

This is not an original solution. I published related thoughts on the web in the past and now recalled these links. Sadly, I cannot remember where I put those SSRs in, so no way for a demo now!

Another neat idea on paper is the employment of the robust ac solid-state switch with zero-cross circuitry, the PS2401(

On a side note, by means of a zero-crossing photo-coupler, the switching times are always at the exact moment of the transition of the zero. Then the commutations are clean, and the electromagnetic interference are absent.

Fire it up!

Sometimes you want to have enticing features in your own hobby-level automation system that are not readily available with any low-priced commercial gizmo. That is why I decided to develop this poor man’s model. As you noticed, this adaptive project is formulated in such a way that its invisible sensor can detect the presence of a fingertip. It is also responsive to tiny movements of an opaque object in its proximity. Is this a nice project to work with? If so, now it is time to get your hands dirty!


This article describes the design and build tips of a simple touchless lamp/light switch device for the sole purpose of personal home/office use, and for demonstrating what is easily possible with a handful of off-the-rack components. Also note that the ideas shared here have not been fully thought through and do not adhere to any strict safety standards. The device is neither suitable nor intended for any commercial production yet, apart from the above pointed limited hobby applications. This project involves working with fatal mains electricity, so replicate at your own risk!

Leave a Comment