How to make a Clap controlled lamp using the Arduino Nano board | Step by step

Hello and welcome back! In this project, we will learn how to make a clap-controlled lamp using the Arduino Nano board. This is a fun and simple home automation project that responds to sound. I mainly used a low-cost sound detection sensor to detect the clap sound. To control the lamp, I added a relay module. This allows us to turn ON or OFF any high-voltage device safely. I connected an AC bulb for testing, and it worked perfectly. You can connect any component you like as an LED strip, fan, or night lamp. It depends on your requirement. Please connect the suitable component for the relay ampere value.
For the circuit, I designed the PCB and ordered it from JLCPCB, which offers high-quality boards at an affordable price. You can also get a $70 coupon using the link below to order your PCBs. Also, I used a simple program for this project. If you’re a beginner, don’t worry. The code is easy to understand, and you can modify it as you like.
Ok, let’s do this project step by step. The required components are given below.
- Arduino Nano board — Our Store / Amazon
- Sound sensitive sensor — Our Store / Amazon
- Two-pin terminal x 1 — Our Store / Amazon
- Female header x 1 — Our store / Amazon
- 5v Relay x 1 — Our store / Amazon
- DC barrel jack x 1 — Our store / Amazon
- 102 SMD Resistor x 3 — Our store / Amazon
- 2A Transistor x 1 — Our store / Amazon
- 1N4148 diode x 1 — Our store / Amazon
- Red SMD LED x 1 — Our store / Amazon
- Green SMD LED x 1 — Our store / Amazon
- Bulb holder x 1 — Our store / Amazon
- Bulb x 1 — Our store / Amazon
Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.
Step 1
Firstly, identify these components.










Step 2
Secondly, let’s order PCBs for this project.


- Click the “Instant Quote” button and upload the Gerber file, which you can download from the link below.
- Gerber file – Download
- For this project, I ordered five Green PCBs. Next, select the build time and shipping method. Finally, click “Save to Cart” and complete the payment.





Step 3
Third, let’s unbox the PCB package and see what we got.






Step 4
Now, let’s solder the SMD components first. I used soldering paste and a hot air gun to make the process easier and cleaner.




Step 5
After that, solder the other components like headers, relay, and connectors onto the PCB.



Step 6
Next, connect the Arduino Nano board and the sound sensor to the PCB. Then, connect the Arduino Nano board to the computer.



Step 7
Now, copy and paste the following code into the Arduino IDE.
- Program — Download
#define relay 2
#define sensor 3
int clapCount = 0;
unsigned long firstClapTime = 0;
bool relayState = false;
void setup() {
pinMode(sensor, INPUT);
pinMode(relay, OUTPUT);
Serial.begin(9600);
digitalWrite(relay, HIGH); // Relay OFF (assuming LOW = ON)
}
void loop() {
bool pulse = digitalRead(sensor);
if (pulse == 0) { // Sound detected
Serial.println("Clap detected");
if (clapCount == 0) {
firstClapTime = millis();
clapCount = 1;
}
else if (clapCount == 1 && (millis() - firstClapTime) <= 1000) {
clapCount = 2;
}
// Debounce: wait until sound is gone
while (digitalRead(sensor) == 0);
delay(50);
}
// If 2 claps detected within 1 second
if (clapCount == 2) {
relayState = !relayState; // Toggle relay state
digitalWrite(relay, relayState ? LOW : HIGH); // LOW = ON
Serial.println(relayState ? "Relay ON" : "Relay OFF");
clapCount = 0;
}
// Reset if time expired
if (clapCount == 1 && (millis() - firstClapTime) > 1000) {
clapCount = 0;
}
}- Then, select the board and port. After, click the upload button.




Step 8
Once the code is uploaded, disconnect the USB cable. After that, connect the bulb to the relay module and power the circuit using a 5–9V DC supply. Alternatively, you can also power the circuit using USB. Please be very careful when working with AC voltage, as it can be dangerous.



Now, you can test your clap-controlled lamp by clapping your hands. Enjoy this project! The full video guide is below. We hope to see you in the next project. Have a great day!


How to make a Clap controlled lamp using the Arduino Nano board step by step