Connecting Ultrasonic Sensor Using ESP8266


I measuring in inch, and centimeters the distance between the sensor and some object.

I create this for measuring distance with an ESP8266 an make some test.

I connect an ESP8266 shield of Sparkfun, HCSR-4, and jumpers.

NO Triggers & Alerts

NO Scheduling

Here Dashboard Screenshots

The code here Cayenne_ECHO.txt (2,2 KB)

The video in my youtube channel here: Here Video

Share knowledge, it’s the best way to learn !!!




Nice little project @kwiek. Yes, sharing is the best way to help other to learn. Thank you posting your code, now anyone who is using same sensor has the code to make it work with Cayenne :slight_smile:

Do you think you can post the recent projects that you made to Cayenne’s page?



Hello @bestes

Thanks for the compliment, it is always a pleasure to share with all our knowledge.

Yes, I can post in the Cayenne’s page, I will arrange this as soon as possible.



My projects


Hi kwlek
I want to try your project.
My HW config is arduino uno + sparkfun 8266sheild + DHT

after install cayenne, I tried your code
BUT following compile error accured
"ESP8266WiFi.h: No such file or directory #include <ESP8266WiFi.h>

Could you give a opinion?

I installed esp8266library from git clone esp8266

If I choose esp8266module from arduino IDE/tools/borad then compile is OK


Using an ESP8266 as a shield is a bit different, give this a try and let us know if it works WifiShield with arduino uno compiling error


Hi cchamchi

If you want to use a DTH 11 with ESP8266, I suggest you look for the appropriate link because in this topic I am showing you how to use an ultrasonic sensor.

Another thing I think I should do, download this link is (below) the library for ESP8266

In the site this indicated the procedure that must follow to install, but if you have doubts please write here again.

I also do not recommend using the ESP8266 with Arduino to measure humidity and temperature because you can do this with no problem using only ESP8266 and DHT11.

See in the drawing a simple way to connect the DHT11 in ESP8266, Search here that you will find several code, search for ESP8266 + DH11, if you do not find any, please let me give you a code
I hope I can solve it but if not, we are here to help until you can.




Nice project Kwiek,
Thank you for sharing.


Thank you @eijuito