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

Pinned onto

Related Pins

Sonicare toothbrush teardown: microcontroller, H bridge, and inductive charging
Sonicare toothbrush teardown: microcontroller, H bridge, and inductive charging
Free PCB Sunday: Pick your PCB
Free PCB Sunday: Pick your PCB
App note: Using Vishay infrared receivers in a Wi-Fi environment
App note: Using Vishay infrared receivers in a Wi-Fi environment
Skill Sunday: Uploading to your Arduino via a Network
Skill Sunday: Uploading to your Arduino via a Network
One Phase Power Meter
One Phase Power Meter
WiFi Toilet Vacancy Sensor
WiFi Toilet Vacancy Sensor
HAL 9000 reimagined as a useless machine
HAL 9000 reimagined as a useless machine
Using the XMEGA Clock System
Using the XMEGA Clock System
An Arduino VU meter for classrooms
An Arduino VU meter for classrooms
DIY Calculator
DIY Calculator
Build your own robotic vacuum from scratch
Build your own robotic vacuum from scratch
An animatronic talking takeout container
An animatronic talking takeout container
Restoring a Xerox Alto day 7: experiments with disk and Ethernet emulators
Restoring a Xerox Alto day 7: experiments with disk and Ethernet emulators
IDE 1.6.12 released with Sierra support and more
IDE 1.6.12 released with Sierra support and more
IoT Propane Tank
IoT Propane Tank
Industry Standard Single-Ended Current Mode PWM Controller
Industry Standard Single-Ended Current Mode PWM Controller
Wifi enabled 8×64 pixel LED matrix display
Wifi enabled 8×64 pixel LED matrix display
Arduino Disco Lights
Arduino Disco Lights
PIXIE is an Arduino-based NeoPixel watch
PIXIE is an Arduino-based NeoPixel watch
How to run C programs on the BeagleBone’s PRU microcontroller
How to run C programs on the BeagleBone’s PRU microcontroller

Top


Shares