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

Schematics of relay module
Schematics of relay module

Schematics of this projects
Schematics of this projects

Schematics of relay module
Schematics of relay module

Comments
Only logged in users can leave comments