Clap to Turn On The Light!

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: p-maker-uno
  Sound Sensor : 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.