Devices & Components
Arduino Uno Rev3
Ultrasonic Sensor - HC-SR04 (Generic)
Jumper wires (generic)
Buzzer
Software & Tools
Arduino IDE
Project description
Code
hardware
c_cpp
// 6 trig , 5 echo
1 2#include <Ultrasonic.h> 3Ultrasonic ultrasonic(6,5);// 6 trig , 4 5 echo 5 6 7const int buzzer = 7; // pin buzzer 8 9void setup(){ 10 pinMode(buzzer,OUTPUT); 11 12} 13 14void 15 loop(){ 16 int dist = ultrasonic.Ranging(CM); 17if (dist < 100) { 18 tone(buzzer,1000); 19 20 delay(40); 21 noTone(buzzer); 22 delay(dist*4); 23 } 24 delay(100); 25 26} 27
Downloadable files
hardware
hardware

hardware
hardware

Comments
Only logged in users can leave comments