Devices & Components
Arduino Uno Rev3
Jumper wires (generic)
Relay Module (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
Breadboard (generic)
Project description
Code
CODE
c_cpp
1//this project is made by Circuit Mania https://www.youtube.com/channel/UCJPKa558LvFFYOL3zfEmJ9g?view_as=subscriber 2const int pingPin = 7; 3//adjust this to set the min speed of wave gesture 4const int waveBackWait = 5000; 5//Range of detection from the sensor in cm 6const int range = 7; 7void setup() { 8 pinMode(10, OUTPUT); 9} 10void loop() { 11 long duration, cm; 12 pinMode(pingPin, OUTPUT); 13 digitalWrite(pingPin, LOW); 14 delayMicroseconds(2); 15 digitalWrite(pingPin, HIGH); 16 delayMicroseconds(5); 17 digitalWrite(pingPin, LOW); 18pinMode(pingPin, INPUT); 19 duration = pulseIn(pingPin, HIGH); 20 21 cm = microsecondsToCentimeters(duration); 22if(cm < range && cm > 1){ 23 for(int i=waveBackWait; i>0; i--){ 24 long new_duration, new_cm; 25 pinMode(pingPin, OUTPUT); 26 digitalWrite(pingPin, LOW); 27 delayMicroseconds(2); 28 digitalWrite(pingPin, HIGH); 29 delayMicroseconds(5); 30 digitalWrite(pingPin, LOW); 31 pinMode(pingPin, INPUT); 32 new_duration = pulseIn(pingPin, HIGH); 33 34 new_cm = microsecondsToCentimeters(new_duration); 35 if(new_cm < range && new_cm > 1){ 36 //ring the doorbell 37 digitalWrite(10,HIGH); 38 delay(500); 39 digitalWrite(10,LOW); 40 } 41 } 42 } 43} 44long microsecondsToCentimeters(long microseconds) { 45 return microseconds / 29 / 2; 46}
CODE
c_cpp
1//this project is made by Circuit Mania https://www.youtube.com/channel/UCJPKa558LvFFYOL3zfEmJ9g?view_as=subscriber 2const 3 int pingPin = 7; 4//adjust this to set the min speed of wave gesture 5const 6 int waveBackWait = 5000; 7//Range of detection from the sensor in cm 8const 9 int range = 7; 10void setup() { 11 pinMode(10, OUTPUT); 12} 13void loop() { 14 15 long duration, cm; 16 pinMode(pingPin, OUTPUT); 17 digitalWrite(pingPin, LOW); 18 19 delayMicroseconds(2); 20 digitalWrite(pingPin, HIGH); 21 delayMicroseconds(5); 22 23 digitalWrite(pingPin, LOW); 24pinMode(pingPin, INPUT); 25 duration = pulseIn(pingPin, 26 HIGH); 27 28 cm = microsecondsToCentimeters(duration); 29if(cm < range && 30 cm > 1){ 31 for(int i=waveBackWait; i>0; i--){ 32 long new_duration, new_cm; 33 34 pinMode(pingPin, OUTPUT); 35 digitalWrite(pingPin, LOW); 36 delayMicroseconds(2); 37 38 digitalWrite(pingPin, HIGH); 39 delayMicroseconds(5); 40 digitalWrite(pingPin, 41 LOW); 42 pinMode(pingPin, INPUT); 43 new_duration = pulseIn(pingPin, 44 HIGH); 45 46 new_cm = microsecondsToCentimeters(new_duration); 47 if(new_cm 48 < range && new_cm > 1){ 49 //ring the doorbell 50 digitalWrite(10,HIGH); 51 52 delay(500); 53 digitalWrite(10,LOW); 54 } 55 } 56 } 57} 58long 59 microsecondsToCentimeters(long microseconds) { 60 return microseconds / 29 / 2; 61}
Downloadable files
Schematics of this projects
Schematics of this projects

Schematics of this projects
Schematics of this projects

Schematics of relay module
if you do not have a relay module so don't worrie you can make your own by this Schematics
Schematics of relay module

Comments
Only logged in users can leave comments