Clap to Turn On The Light!

INTRODUCTION

When I was young, I always have this kind of thought “Can I just switch off the light when I was about to sleep on the bed without going to the switch and turn it off?”. (I’m a bit scared when I sleep alone without my sibling) Hihi.. Then today, I found out that it’s actually doable to turn on and off the light by clapping my hand. Now, let’s have a look on how to do it! 

VIDEO

This is the video for this project.

HARDWARE PREPARATION

This tutorial use :

  1. Maker UNO
  2. Mini Microphone Module (Sound Sensor)
  3. Yellow LED
  4. 220 ohm Resistor
  5. Male to Male Jumper Wire
  6. Breadboard
  7. Micro B USB

You can make the hardware connection based on the diagram and table below.

Connection
Sound Sensor : VCCMaker UNO: 5V
Sound Sensor : GNDMaker UNO: GND
Sound Sensor : OutMaker UNO: pin 10
Yellow LED (+)Maker UNO: pin 4
Yellow LED (-)Maker UNO: GND with Resistor
Figure 1 : Hardware Connection
Figure 2 : The Sound Sensor Connection

SAMPLE CODE

This is the sample code used for this tutorial. Try it!

/*
  This example code is for Clap to Turn On The Light's Tutorial.
  Product page:
  Maker UNO: https://www.cytron.io/p-maker-uno
  Sound Sensor : https://www.cytron.io/p-so-mic-mod
  Created by:
  24/07/18  Suad Anwar, Cytron Technologies
*/

int SoundSensor = 10;
int yellow = 4;
int value = 0;
int flag = 0;

void setup() {
  pinMode(yellow, OUTPUT);
  pinMode(SoundSensor, INPUT);
}

void loop() {
  value = digitalRead(SoundSensor); // To get the Sound Sensor's value

  if (value == 1) {

    if (flag == 1) {
      digitalWrite(yellow, HIGH);
      flag = 0;
    }

    else if (flag == 0) {
      digitalWrite(yellow, LOW);
      flag = 1;
    }
    delay(200);
  }
}

The Museum

This is the template for the paper house. Kindly download it here. You can always check another house and building here.

Thank you

Thank you for reading this tutorial and we hope it helps your project development. If you have any technical inquiry, please post at Cytron Technical Forum.

7 thoughts on “Clap to Turn On The Light!”

  1. Hi Piyal, value is the state of the sensor. Seems both turn on and off using the same method (one clap), we used flag variable to toggle it. Thanks.

  2. Is it possible instead of using arduino, I used raspberry Pi 2? If can, may I get the semantic diagram and code used for raspberry pi.Thank you.

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorail

Display Temperature and Humidity on OLED using DHT22 and Arduino
Getting Started With Teensy Using Arduino IDE
Night Light
Arduino Device Tracker Using GSM GPS SIM7600E Module
Chocolate Box with Touch Sensor and Arduino
Scroll to Top