Ultrasonic Range detector using Arduino and the SR04 Ultrasonic sensor

his is a preliminary instructable that will take you through the steps I took to get the SR04 ULTRASONIC SENSOR Β connected Β and working to the Arduino. It will then be incorporated to my mini environment monitor.Β  Eventually, if it all fits, it will end up in a Startrek Β toy tricorder casing I found in my junk box..

Ultrasonic Range detector using Arduino and the SR04 Ultrasonic sensorStep 1: Connecting the SR04 Ultrasonic Sensor to the Arduino

Step 2: Parts List

1 Β  Β  Β  Β  Β  Β  Β  Arduino uno R3, or any Arduino for that matter
1 Β  Β  Β  Β  Β  Β  Β  SR04 Ultrasonic Sensor
1 Β  Β  Β  Β  Β  Β  Β  breadboard
4 Β  Β  Β  Β  Β  Β  Β  Jumper Wires

Step 3: Connect Ultrasonic Sensor to Arduino

You Need 4 Jumper wires to conect the SR04 Ultrasonic Sensor to the Arduino:

1 Β From the SR04 Β VCC pin to the Arduino 5v
1Β From the SR04Β  GND pin to the Arduino GND
1 From the SR04Β  TRG pin to the Arduino Digital pin 12
1 From the SR04Β  ECHO pin to the Arduino Digital pin 11

That’s All The wireing you need… Easy, Β no?

Next Step, load the Software library and sketches.

Step 4: Step 4 Download SR04 Library and install to Arduino IDE

You need to download another LibraryΒ  to get the Arduino to talk with the SR04 sensor. The sensor I got didn’t come with any documentation, so I Googled around until I found a library that works.
I found an optimized library here
Download the library unzip it,Β  and install it in the Arduino IDE. Place it inside your Arduino libraries folder , and restart the Arduino IDE. For convenience, I included the file Β in Β the files section below.

You should now be able to see theΒ  library and examples inΒ  select File > Examples > NewPing > NewPingexample sketch.
load the sketch to your Arduino.

Ultrasonic Range detector using Arduino and the SR04 Ultrasonic sensor SchematicIf you were successful at installing the libraries, and loading the NewPingexample sketch,Β  Compile the sketchΒ  by clicking on the verify button and make sure there are no errors.
It’s time to connect your Arduino to your PC using the USB cable.Β  Click on the upload buttonΒ  to upload the sketch to the Arduino.
Once uploaded to the Arduino, open the serial monitor, and you should see the distance Β data stream Β  coming from the sensor.

 

For more detail: Ultrasonic Range detector using Arduino and the SR04 Ultrasonic sensor

About The Author

Scroll to Top