Devices & Components
Arduino Uno Rev3
Male/Female Jumper Wires
Plastic Enclosure, Project Box
Relay Module (Generic)
5volt smps
digital sound sensor
Hardware & Tools
Soldering iron (generic)
Solder Wire, Lead Free
Hot glue gun (generic)
Project description
Code
code of the project
c_cpp
1int soundsensor = 7; 2int relay = 6; 3 4int clap = 0; 5long detection_range_start = 0; 6long detection_range = 0; 7boolean status_lights = false; 8 9void setup() { 10 pinMode(soundsensor, INPUT); 11 pinMode(relay, OUTPUT); 12} 13 14void loop() { 15 int status_sensor = digitalRead(soundsensor); 16 if (status_sensor == 0) 17 { 18 if (clap == 0) 19 { 20 detection_range_start = detection_range = millis(); 21 clap++; 22 } 23 else if (clap > 0 && millis()-detection_range >= 50) 24 { 25 detection_range = millis(); 26 clap++; 27 } 28 } 29 if (millis()-detection_range_start >= 400) 30 { 31 if (clap == 2) 32 { 33 if (!status_lights) 34 { 35 status_lights = true; 36 digitalWrite(relay, HIGH); 37 } 38 else if (status_lights) 39 { 40 status_lights = false; 41 digitalWrite(relay, LOW); 42 } 43 } 44 clap = 0; 45 } 46}
code of the project
c_cpp
1int soundsensor = 7; 2int relay = 6; 3 4int clap = 0; 5long detection_range_start 6 = 0; 7long detection_range = 0; 8boolean status_lights = false; 9 10void 11 setup() { 12 pinMode(soundsensor, INPUT); 13 pinMode(relay, OUTPUT); 14} 15 16 17void loop() { 18 int status_sensor = digitalRead(soundsensor); 19 if (status_sensor 20 == 0) 21 { 22 if (clap == 0) 23 { 24 detection_range_start = detection_range 25 = millis(); 26 clap++; 27 } 28 else if (clap > 0 && millis()-detection_range 29 >= 50) 30 { 31 detection_range = millis(); 32 clap++; 33 } 34 35 } 36 if (millis()-detection_range_start >= 400) 37 { 38 if (clap == 2) 39 40 { 41 if (!status_lights) 42 { 43 status_lights = true; 44 45 digitalWrite(relay, HIGH); 46 } 47 else if (status_lights) 48 49 { 50 status_lights = false; 51 digitalWrite(relay, LOW); 52 53 } 54 } 55 clap = 0; 56 } 57}
Downloadable files
Diagram of the project
Diagram of the project

Comments
Only logged in users can leave comments