Organize and Share your Electronics the way you want. Sign-Up for a free account now. It takes only 30 seconds!

ESP8266 Peripherals: 5$ RCW-0001 Ultrasonic Range Sensor

ESP8266 Peripherals: 5$ RCW-0001 Ultrasonic Range Sensor

There are many applications for distance measuring: in robotic as a cheap way to sense the environment and detect obstacles, in IoT applications to measure fill levels of containers containing food and in alarm systems to detect intruders – to name just a few.

I have been trying to use the popular HC-SR04 ultrasonic sensor together with the ESP8266 in the past but I wasn’t succesful. I guess this sensor needs 5V for proper operation and in order to do that I would have to add a voltage divider for the response pin to accommodate for the 3.3V of the ESP8266. So I went looking for a distance sensor working easily with the ESP8266 and I found it on Banggood for less than USD $5.

RCW-0001: 3.3V compatible distance sensor

Get it to work

To get it to work with the ESP8266 in the Arduino IDE you need a library or write the code yourself. The first library that I tried worked almost immediately. Just download the library from here: https://bitbucket.org/teckel12/arduino-new-ping/downloads

Then go to Sketch > Include Library > Add Zip library.. and you are good to go. Sadly the library doesn’t seem to be listed in the Arduino Library manager but the download and import by ZIP is easy enough. Now go to File > Examples > NewPing > New Ping Example which opens a new Sketch window. Now just change the pins according to your wiring. I think most GPIO pins will work but I used D4 and D3 on the NodeMCU. Connect

  • VCC with 3.3V
  • GND and GND,
  • TRIG and D4 and
  • ECHO and D3

My Sketch looks like this:

#include <NewPing.h>;

#define TRIGGER_PIN D4 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN D3 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 400 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

void setup() {
 Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
}

void loop() {
 delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
 Serial.print("Ping: ");
 Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
 Serial.println("cm");
}

Then open the serial console and you get a wonderful stream of distance measurements!

Summary

The sensor works very realiably with the ESP8266, is easy to program and to wire and the price of less than USD 5$ is very moderate. I bought mine here: http://www.banggood.com/NAZE32-Flight-Controller

Read more Here

 

More Articles to Read

Estimating Power for ADSP-BF561 Blackfin® Processors
Estimating Power for ADSP-BF561 Blackfin® Processors
Teach Your Arduino to Switch Itself Off!
Teach Your Arduino to Switch Itself Off!
Control a tracked robot with your mind (or joystick)
Control a tracked robot with your mind (or joystick)
A 400W (1kW Peak) 100A electronic load using linear MOSFETs
A 400W (1kW Peak) 100A electronic load using linear MOSFETs
Shirt Pocket Transceiver with the Si5351 and OLED
Shirt Pocket Transceiver with the Si5351 and OLED
All metal C930e webcam
All metal C930e webcam
The Soldering Tools That Make Your Life Easier
The Soldering Tools That Make Your Life Easier
App note: Operation evaluation of ultra low ON resistance MOSFET supporting quick charge for 1 c ...
App note: Operation evaluation of ultra low ON resistance MOSFET supporting quick charge for 1 cell Lithium ion battery protection
Synthesized Sidetone
Synthesized Sidetone
App note: Application precautions: Power MOSFET application notes
App note: Application precautions: Power MOSFET application notes

Top