Introduction: Arduino Clap Sensitive Light Control (The Clapper)
The requirements are on the next page.
Also Please vote for me in the contests ive entered if you like this project.
Step 1: Requirements
Arduino, needs two digital I/O
Jumpers (M-M)
Relay(necessary for the mains voltage)
Breadboard
Resistor*
LED*
Computer (I just happened to use my Pi for this one)
Arduino IDE
Attiny (not essential but for compact-ness)
*For testing.
Step 2: Breadboard Setup. (No Relay)
Step 3: The Code
Some very simple code just copy and paste into the Arduino IDE which can be found here.
const int buttonPin = 2;
const int ledPin = 0;
int buttonstate = 0;
int ledstate = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop(){
buttonstate = digitalRead(buttonPin);
ledstate = digitalRead(ledPin);
if (ledstate == HIGH && buttonstate == LOW) {
delay(250);
digitalWrite(ledPin, LOW);
}
if (ledstate == LOW && buttonstate == LOW) {
delay(250);
digitalWrite(ledPin, HIGH);
}
}
Step 4: Troubleshooting
As a point of reference when i clap a little LED on the microphone board lights up, if you have a constant flashing LED adjust the onboard potentiometer till it stops, from this point on the sensitivity can be adjusted to your preference.
If nothing happens at all when you clap check all your connections and check that your LED is wired Correctly.
Step 5: Relay Setup
IF YOU ARE WIRING THIS TO MAINS VOLTAGE BE EXTREMELY CAREFUL, MAINS CAN KILL INSTANTLY, I AM IN NO WAY RESPONSIBLE OR LIABLE FOR ANY INJURY OR FATAL HARM THAT MAY BEFALL YOU AS A CONSEQUENCE OF FOLLOWING THIS TUTORIAL.
PURSUE AT YOUR OWN RISK
The relay version varies very little but to begin with, check your relay is for 5V.
Then check if your landlord or home owner is accepting of this project.
Switch the outlet/light switch off in the switchbox for your home, to reduce risk of electrocution.
Test your relay board before hooking it up to mains, a circuit like the one below should work.
Step 6: Condensed Version (Attiny85)
Steps on how to bootload and program your Attiny will be uploaded at a later date, in the mean time there are many tutorials out there on how to do it.
One fairly simple method that requires no extra hardware is using your arduino as an isp.
The Attiny pinout is below.
Step 7: Watch This Space
Inbox me if you have any questions.