User Tools

Site Tools


measuring_distance_with_arduino_and_ultrasound

This is an old revision of the document!


Measuring Distance with SR-04 Ultrasound Module

The SR-04 ultrasound module can be used for many applications. For example, it can be used to trigger Halloween decorations, as car back-up proximity alerts in garages, movement alarms in homes, or as a basement sump water level alarm.

Parts List

  • Arduino Uno $6
  • 5mm common anode RGB LED $0.05
  • Three 220 ohm resistors $0.03
  • SR-04 ultrasound module $1.50

About the SR-04

There are four pins: Vcc and GND, which supply power to the module, trigger, which is used to send an ultrasonic pulse when brought high by the Arduino, and echo, which is used to receive the echo of the pulse. The time it takes for the emitted pulse to echo back to the module is what's used to calculate the distance to the object or person. The formula is distance = echo time * speed of sound / 2. The SR-04 can measure distances from 2cm to about 400cm.

Wiring the SR-04

  • Plug the SR-04 into the breadboard so the pins are on different numbered rows. Do this so the sensors are facing out, away from the wiring (NOTE: this is the opposite the direction shown on the diagram)
  • Use a red jumper between the SR-04 Vcc and a breadboard power bus
  • Use a black jumper between the SR-04 GND and GND on the Arduino
  • Use a jumper between trigger and Arduino pin 13
  • Use a jumper between echo and Arduino pin 12

About Common Anode RGB LEDs

RGB LEDs come in two flavours: common anode (positive supply) and common cathode (negative). They are essentially three LEDs in one package, with either the positive or negative leads connected internally. As with all LEDs, we will add a current-limiting resistor to prevent the LED from drawing too much current and getting damaged. We are using the same value resistor for all 3 LEDs in this workshop, but if you were to do this for a long-term project you would want to calculate the optimum resistance for each LED.

Wiring the Common Anode RGB LED

  • Plug the LED into the breadboard so the pins are on different numbered rows
  • Use a red jumper between the common anode pin (the longest pin) and the power bus
  • For each of the remaining pins, plug a resistor to connect the row the pin is in to the same row, but the other side of the breadboard, as shown in the diagram.
  • Use a red, green, and blue jumper to connect the end of resistors opposite the LED to Arduino pins 9, 10 and 11. It doesn't really matter which is which for now.

Further resources

measuring_distance_with_arduino_and_ultrasound.1503948937.txt.gz · Last modified: 2017/08/28 19:35 by glassgiant