This project will show you how to use an ultrasonic sensor with an Arduino.What is an ultrasonic sensor?
An ultrasonic sensor is a module which uses ultrasound (you didn't expect that, did you?).
It allows to detect a presence or to measure a distance via ultrasounds.
He sends an ultrasound pulse via his trig terminals and receives them via his echo terminals.
The ultrasonic sensor sends 8 pulses of 40KHz via the trig terminals (inaudible to humans, it's ultrasounds).
The ultrasonic pulses collide an object and leaves in the other direction.*
The echo terminals receives the ultrasound pulses and the sensor calculates the distance based on the time of the pulses.
Speed of the ultrasounds: 340 meters per second.Code
We will use the serial monitor with this line of code:
Serial.print("Distance in cm : ");
The serial monitor is a separate window that will appear when you click on the button " serial monitor " top right.
The serial monitor is used for receive or send data to the Arduino card.
So the program will print on the monitor " Distance in cm: " and the distance after.
Note : this window can't be clear so you must close it to clear what you write.Connections
I don't find ultrasonic sensor in Fritzing for the schematics so I will say the connections here:
Pin 11 (Arduino) -----> Echo
Pin 12 (Arduino) ------> Trig
GND (Arduino) -------> GND (Sensor)
5V (Arduino) -----> VCC (Sensor)