The code for the Arduino UNO + W5100 + HC-SR04


This is my code for HC-SR04.
Distance is measured in cm.

Cayenne-HC-SR04.txt (2.3 KB)


Awesome, thank you for sharing it with the community. Do you have any plans in mind for that sensor?


hi @tad.dvor,

Woohoo! Thanks for sharing this :slight_smile: I have this sensor and now you make it easy for me to connect it with your code.



I have not any plans.


The code for Arduino UNO + W5100 + HC-SR04 + OLED.

Cayenne_HC-SR04_OLED.txt (2.1 KB)


The code for ESP8266 and HC-SR04
I used a converter logic levels between ESP8266 and HC-SR04.

Cayenne_ESP8266_HC-SR04.txt (1.6 KB)


The code for Arduino UNO + W5100 + HC-SR04 + 16*2 LCD.

Cayenne_HC-SR04_LCD.txt (2.1 KB)


Nice project Tad.dvor!

    I would like to know if this code will also work on an Arduino Mega or do I need to change the code and can you let us know which LCD display you used for this project? Thanks


With Arduino MEGA should also work.


Let us know if you make anything @futureoils :slight_smile:



It works perfectly I have adapted it a bit to let it work on a USB connection (I do not yet have a WiFi Shield). You have to remove all the writes on the serial port.

Thank you very much for sharing.



Glad to here @paolo.capitelli. If you create a project, share it with the Cayenne community :slight_smile: