What you will make:
Today we are going to work with a very well known sensor in the Arduino community, the HC-SR04 Ultrasonic Sensor or Sonar Sensor. The sensor has a range from 2cm to 400cm, with up to 3mm of accuracy.
What you will need:
For this project you will need:
(When distance between obstacle and sonar sensor is less than 10cm then red led ON and when distance is greater than 10cm, then yellow light ON.)
Hint: make a new variable with name distance from Data&Blocks tab as shown below
- Connect the components as shown in schematic.
- Upload the code to Arduino.
The sensor includes an Ultrasonic Transmitter and a Receiver. The transmitter, controlled by Trig pin, sends a signal and it is received by the echo pin. The duration took by the signal to travel back after bouncing from the obstacle is measured through which the actual distance to the obstacle is calculated and stored.