How To Ultrasonic Sensor With Buzzer

Required Hardware
For users who do not have Hackerspace Karachi Arduino Kit v1.0
- Arduino Board
- Breadboard
- Ultrasonic Sensor (HC-SR04)
- Buzzer
- Resistor 220 ohm
- Hook-up Wires
Circuit
For users who do not have Hackerspace Karachi Arduino Kit v1.0
Schematic
Code
1. /*
2. Reading Button with Arduino
3.
4. This example shows how to read button using Arduino.
5.
6. The circuit:
7. – BUTTON
8. Anode connected to VCC.
9. Cathode connected to digital pin 2.
10.
11. http://hackerspacekarachi.org/
12. */
13.
14. void setup() {
15. Serial.begin(9600); // beginning of serial monitor
16. pinMode(2, INPUT); // declaration of input
17.
18.
19. }
20. void loop() {
21.
22. int d = digitalRead(2); // read and store input
23.
24. if (d == 1)
25. {
26. Serial.println(“PUSH BUTTON on pin 2 is on”); // print push button state
either on or off
27. }
28. }