The box ready with micro in the center |
Also it can come in handy for people with disabilities , although in that case it would be better a remote control.When at last I got with it, it occurred to me that surely someone had done it before, and bingo!one German commented how he had developed on his page , saving me hours of testing with micro.
A micro with an activatable certain volume output greatly simplifies things, so the theory is that the Arduino program simply be listening, and produced two (only two) high hits in less than 0.4 seconds , is likely they are two slaps.
3 component dupont few cables and the USB connector is all we need to prove |
Also I had thought of adding a ultrasonic sensor to light the lamp motion for a minute, but in a room that is impractical, plus it was complicate unnecessarily. Maybe you do, but today the infrared motion sensors are so cheap (about 10 €) not worth it.Another option is "sampling" the sound, so that the Arduino is to decide if there was a "plas plas" or not, could be more reliable, as explained in this post .I do not know what it will cost a device that does the same, but I think it cost me less than the next necessary equipment:
- An Arduino "Nano" with Atmel 328p 32KB Rom (2 Ks occupied by the bootloader).
- A relay "Keyes" , which will simply output 5V Arduino pin to activate.
- And a special microphone to clap , ( it does not, the potentiometer is unstable , but we can use the digital output), or this one , that detects sound levels above an adjustable value, one of the digital outputs (D0) that activates a volume set resistance, and other analog output (A0) for the detected sound level (50 to 1024 for the volume of noise). Well calibrated, we can assert to record the number of times the sound exceeds a certain limit per day, for example in a job.
- And a transformer 7 to 12V DC to power the Arduino.
A transformer without an output capacitor sad ... with what little they cost! |
/ *
* PROGRAM relay activation by slapping
* (C) Creative Commons
* Modified from http://en.code-bude.net/2014/12/08/how-to-build-a-clap-switch-using-arduino/
* With operating hours saved in EEPROM
* /
#include
soundSensor int = 7;
relay int = 4;
claps int = 0;
int pos = 0;
int value = 0;
long hours = 0;
long detectionSpanInitial = 0;
long detectionSpan = 0;
long millisPrevious = 0;
long millisNow = 0;
RelayState boolean = true; // Start with it enabled
void setup () {
pinMode (soundSensor, INPUT);
pinMode (relay, OUTPUT);
digitalWrite (relay, HIGH); // Turn on when you turn on the light
}
void loop () {
// For (int pos = 0; pos <256 all="" clear="" div="" eeprom="" once="" only="" pos="" run="" the="" to="">
// EEPROM.write (pos, 0);
//}
sensorState int = digitalRead (soundSensor);
if (sensorState == 0)
{
if (claps == 0)
{
detectionSpanInitial = detectionSpan = millis (); // Save the counter initial milliseconds
claps ++;
}
else if (claps> 0 && millis () - detectionSpan> = 50)
{
Millis detectionSpan = ();
claps ++;
}
}
// Turn off without it has been 6 hours (in case of false activation)
if (hours> 5) {// change this to the desired
= 0 hours;
RelayState = false;
digitalWrite (relay, LOW);
}
if (millis () - detectionSpanInitial> = 350)
{
if (claps == 2)
{
if (! RelayState)
{
RelayState = true;
digitalWrite (relay, HIGH);
= 0 hours; // Starts counting
}
else if (RelayState)
{
RelayState = false;
digitalWrite (relay, LOW);
}
}
claps = 0;
}
// While (1) {delay (500);} // infinite loop
// If it's been an hour, we keep on increasing eeprom first value to 1, and if = 255, increase the following
// What empowers us get to save 260,000 hours
Millis millisNow = ();
if (millisNow-millisPrevious> = 3600000)
{
++ hours; // Increment
millisPrevious = millisNow;
pos = 0;
while (EEPROM.read (pos) == 255) {
pos ++;
if (pos == 1024) {break;} // the Atmel328p has 1K EEPROM; 512 modified by minor versions
}
value = EEPROM.read (pos);
EEPROM.write (pos, value ++);
}
else
{
Millis millisNow = ();
}
}
256> |
And if you wonder how durable an Arduino running, the conclusion is that with a power supply quality, at least 50,000 hours; between 5 and 10 years. Here is a interesting discussion about its reliability . Its consumption is minimal; 1W reckon with this source of 7V; 50mA Nano, 20mA relay (without activating, activated spends more but will be shortly) and 15mA of micro and 60mA (minimum) source, but if you want to lower your consumption rather, it is best to put a switching power supply 5V (typ mobile charger), and can be in 0.5W when not in use. However, as it is after the light switch (the program does when the arduino is turned on, the relay is connected, it takes 1 sec. to turn it on), only when we consume off with slaps and leave the light switch connected. The potentiometer setting that brings the microphone to do with him up; I have loosened (counterclockwise to clockwise) until it is permanently activated the LED indicator sound, and then I pushed a couple of laps. Otherwise, their sensitivity was very small, and there was virtually hurt your hands to detect us. After thoroughly test it, I placed all (somewhat poorly organized, it must be said) in a recessed box next to the feed ceiling ., but can also put next to the switch, making a hole in the wall, that's because consumer tastes In the next picture connections are; Arduino down to the left. with a hole to connect the computer in case you want to adjust anything and everything stuck with some termoencoladora (not going to take a lot of heat in my case, but better usad silicone). For the microphone, I have welded the other side to pass through a small hole in the top, and you can hear good spanking. The power connections: As only two elements are of little use, it is best to feed the Arduino in its Vin (pin 30) 7 to 12V, and its 5V output (pin 22 I think), feed the relay and microphone. In case of using a relay voltage, would be fed directly to the source so that you can activate.
The transformer (red and yellow coil) I've put a good fat capacitor, for not wearing |
Put the lid ... and enjoy! |
Again, I recommend reading the page Raffi , not wasted, explains the whole process of problem analysis and technical solution that gives you.
/ *
Code to activate an LED with sound. You have to set the minimum so as to be sufficiently sensitive.
This type of sensors only work well with loud sounds.
You connect an LED to PIN13 and sound sensor to analog pin A0 * / #define DEBUG 1 ANALOG_PIN A0 #define #define LED_PIN 13 int threshold = 50; // Set this int volume; void setup () { pinMode (LED_PIN, OUTPUT); #if DEBUG Serial.begin (9600); // For debugging #endif } void loop () { volume = analogRead (ANALOG_PIN); // Read the value of the analog pin. #if DEBUG Serial.println ("Volume" + String (volume)); delay (100); #endif if (volume> threshold) { digitalWrite (LED_PIN, HIGH); Led Turn ON // } else { digitalWrite (LED_PIN, LOW); Led Turn OFF // } } |
And as always, if you liked it or have any questions, what are you waiting to comment! :)
The only downside I have is that also operated with coughs ... I put no bad! XD
References: How to build a clap switch using Arduino Sound Sensor stroke using a piezoelectric speaker and a resistor with Arduino Controller Sound Activated
No comments :
Post a Comment