This is a project come true for me after about a dozen years. Let me tell you the story. A long time ago, as a toddler, I watched a movie where a man used a clap to switch off a lamp and it made more than excited. I so wanted to be able to do the same. Fast forward to today, I am building an Arduino project around that old dream of mine and I will show you how you can easily replicate it yourself.
It is a very simple project, at least when you are shown how to do it.
Before we begin, note that this project works with high voltage. Do it with adults and always double check before applying power. If you are not sure what you are doing, please skip this project.
Here is a list of what we need for this project:
- 1 x Arduino Uno board
- 1 x Relay
- 1 x Microphone module
- 1 x 230V lamp
- Jumper wires
- 1 x Cable with a plug and a socket
Here is the connection diagram. At this point, you don’t have to connect the cable with the plug and the socket to the relay.
First, we have to connect the microphone and the relay. Make sure to use the analog output of your microphone. I connected the microphone to the analog pin 0 (A0). I did connect the relay to the digital pin 2.
When you are done connecting, let’s upload the code below that turns the lamp ON with a clap. If everything works fine, you can now connect the plug to the relay. BE CAREFUL!!
The code we have just uploaded to the Arduino works, but it has a big downside.
When you turn ON loud music, your lamp will blink. We have to make the system more robust and able to ignore such noise.
How do we do it?
The idea I’ve got is to store the last few reads of the microphone output, then if a clap is detected (read from the microphone is high) check if there were a previous High and if it didn’t change the lamp state if it was quiet change the lamp state.
Yes, this is not perfect, and there are some more advanced ways to do this, but I think this is good enough for us at the moment.
Here is how we will do this:
- We will have a long long int
- Every few milliseconds we will shift this value by one (like this: value = value << 1) it will shift all bits by one to the left and add 0 at the beginning
- Then if the microphone will be bigger than some value we will increment our value by one
- At the same time if the microphone output is bigger than some values we will switch the lamp state but only when our value with long long int value is == 0, why 0? because it means that for the last reads, there was no loud sound detected.
Hope it makes sense. The code is way simpler than my explanation.
If you don’t get it from the text above, just check the code below and everything should be clear.
Thanks to this, our lamp will not react to, say a loud music
Simple and effective, just the way I love. Enjoy!
You might also like:
- Arduino hx711 tutorial
- Arduino magnetic switch
- Best Arduino Kits
- gifts for engineering students
- gifts for engineers
- mpu6050 Arduino projects
- Current sensor Arduino
- Soil Moisture Sensor With Arduino
- Arduino Count up Timer Using the Nokia 5110 LCD
- Arduino Yun: Integrating or Juxtaposing Arduino with Linux
- Arduino Projects: Line Follower Robot
- Arduino RFID Project for Beginners
- Arduino MOSFET Project
- Which Arduino Should You Buy
- What Can You Do With Arduino Boards?
- Great Alternatives to the Arduino Microcontroller
- Arduino Projects: Color Sensor
- Arduino IDE Alternatives
- Arduino Mega vs. Uno
- Arduino Projects: Arduino LCD Display
- Read Arduino Rotary Encoders
- A Selection of the Best Arduino Simulators
- Arduino Projects: IR Receiver
- Arduino Light Sensor Project
- Arduino Projects: Arduino Decibel Meter
- Arduino Stopwatch Project
- Arduino Bluetooth RC Car Project
- Arduino Temperature Logger Project
- Arduino Projects: Arduino 7 Segment Display
- Arduino Projects: Clap ON Clap OFF Light
- Arduino Relay Project
- Install a Library Onto the Arduino IDE
- Arduino Projects: Rainfall Detector
- Arduino Projects: RGB LED Arduino
- Arduino Stepper Motor Project
- Arduino Projects: Arduino DC Motor Control
- The Top Affordable Arduino Robot Kit
- Arduino 3D Printed Case
- Arduino Projects: Asynchronous LEDs Blink
- Arduino Projects: Ultrasonic Distance Sensor
- Arduino Projects: LED – 4X4X4 LED Cube
- Arduino Car Projects: Build an Obstacle Avoiding Robot With Less Than $30
- Arduino Projects: Servo Potentiometer Control
- Arduino LED Project: Knight Rider
- Arduino Projects: PIR Motion Sensor
- The Difference between Arduino and Raspberry Pi
- Top 9 Books Every Engineer Should Read
- Top Used Sensors for Arduino
- First Hand on the Arduino Uno Board