Summary of Ultrasonic Range detector using Arduino and the SR04 Ultrasonic sensor
This article provides a preliminary guide on connecting an SR04 ultrasonic sensor to an Arduino Uno R3 for use in a mini environment monitor, potentially housed in a Star Trek tricorder casing. It details the necessary wiring connections and the installation of the NewPing library within the Arduino IDE to enable distance measurement via the serial monitor.
Parts used in the SR04 Ultrasonic Sensor Project:
- Arduino uno R3
- SR04 Ultrasonic Sensor
- Breadboard
- Jumper Wires
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..
Step 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.
If 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
- What is the purpose of this project?
To connect and work with the SR04 ULTRASONIC SENSOR connected to the Arduino for a mini environment monitor. - How do I connect the VCC pin?
Connect the SR04 VCC pin to the Arduino 5v using a jumper wire. - Which digital pins are used for TRG and ECHO?
The TRG pin connects to Digital pin 12 and the ECHO pin connects to Digital pin 11. - Can I use an Arduino other than the Uno R3?
Yes, you can use any Arduino for that matter. - Why is a library needed?
You need to download another Library to get the Arduino to talk with the SR04 sensor because the sensor did not come with documentation. - How do I install the NewPing library?
Download the library, unzip it, install it in the Arduino libraries folder, and restart the Arduino IDE. - Where can I find the example sketch?
Select File > Examples > NewPing > NewPingexample sketch. - What indicates a successful upload?
Open the serial monitor and you should see the distance data stream coming from the sensor.