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

Gesture Controlled Smart Home
Gesture Controlled Smart Home
Design for a Wideband, Differential Transimpedance DAC Output
Design for a Wideband, Differential Transimpedance DAC Output
Wrist thrusters let you fly through the water effortlessly
Wrist thrusters let you fly through the water effortlessly
Bertan/Spellman 225-20R HV power supply teardown
Bertan/Spellman 225-20R HV power supply teardown
Blinking Christmas Lights
Blinking Christmas Lights
Adjusting clock with alarm, hygrometer & thermometer on 1.8″ ST7735 display
Adjusting clock with alarm, hygrometer & thermometer on 1.8″ ST7735 display
Adding an “extra sense” with rangefinders
Adding an “extra sense” with rangefinders
This wireless game controller looks like a rug
This wireless game controller looks like a rug
How to run your ESP8266 for years on a battery
How to run your ESP8266 for years on a battery
Calibration of a 3-Phase Energy Meter Board on the ADE7754
Calibration of a 3-Phase Energy Meter Board on the ADE7754
Making beats on a tiny Arduino DJ controller
Making beats on a tiny Arduino DJ controller
Qinsi-QS5100 Sn63Pb37 solder profile
Qinsi-QS5100 Sn63Pb37 solder profile
Water Detection System
Water Detection System
Professional Hi-Fi 15W Tube Amplifier circuit
Professional Hi-Fi 15W Tube Amplifier circuit
This Arduino machine will judge how sick your ollies are
This Arduino machine will judge how sick your ollies are
Turn an old payphone into a boombox for ’90s hits
Turn an old payphone into a boombox for ’90s hits
Big F’n 3D printer build
Big F’n 3D printer build
Temperature alarm for boiling milk
Temperature alarm for boiling milk
QuadBot is a 3D-printable walking robot for everyone
QuadBot is a 3D-printable walking robot for everyone
MicroConverter I2C Compatible Interface
MicroConverter I2C Compatible Interface

Top


Shares