Things used in this project

Hardware components:
Esquilo Air
51gzz5eu9pl. sx425
Ultrasonic Sensor - HC-SR04 (Generic)
Kingbright wp7113srd d image
5 mm LED: Red
Kingbright wp7113sgd
5 mm LED: Green
Mfr 25fbf52 221r sml
Resistor 221 ohm
12002 04
Breadboard (generic)
Male/Male Jumper Wires
It is nice if you pick color coordinated ones. I used: 2 black, 2 red, 1 blue, 1 green, 1 yellow, 1 orange


Esquilo HC-SR04 wiring diagram
Suggested wiring diagram


Esquilo HC-SR04 sample codePlain text
Squirrel nut for using the HC-SR04 with an Esquilo
 * This is a demo of the HC-SR04 Ping distance sensor
 * connected to the Esquilo Air.
 * VCC to Esquilo 5V  (red)
 * GND to Esquilo GND  (black)
 * Echo to Esquilo 2 PWM0 CH0  (green)
 * Trig to Esquilo pin 13  (blue)
 * Red LED+ to Esquilo pin 11  (orange)
 * Green LED+ to Esquilo pin 10  (yellow)
 * 200 Ohm resistor to both LED- and GND
 * This code and wiring hookup was inspired by an Arduino sketch I found
 * online.


trigPin <- GPIO(13);  // Use digital pin 13 for the trigger.
echoPin <- Capture(0);  // PWM0 input.

trigPin.output();  // Set the trigger to output.

redLed <- GPIO(11);  // Set the pins to use for the LEDs.
greenLed <- GPIO(10);

redLed.output();  // Set both LEDs to output.

redLed.low();  // Turn off both LEDs.

local duration;
local distance;

while (true) {
    trigPin.low();  // Pulse the trigger off.
    trigPin.high();  // Pulse the trigger on.
    trigPin.low();  // Pulse the trigger off.
    echoPin.arm(0, CAPTURE_EDGE_RISING);
    duration =;
    //print("duration=" + duration);
    distance = (duration / 2) / 29.1;  // This may need to be adjusted for accurate distances.
    //print("distance=" + distance);
    if (distance < 4) {
        redLed.high();  // Turn on the red LED.
        greenLed.low();  // Turn off the green LED.
    } else {
        redLed.low();  // Turn off the red LED.
        greenLed.high();  // Turn on the green LED.
    delay(500);  // Delay 1/2 second before checking again.


Leeland Heins

Hardware & Software H4x0r



Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback


Similar projects you might like

Esquilo Grove Starter Kit Demos
  • 477
  • 9


This project includes a web-enabled demo for each module in the Grove Starter Kit for Arduino using the Esquilo Air.

Esquilo Air and 1602A LCD Tutorial
  • 105
  • 4


This is a very simple example setup to show how to hook a 1602A LCD panel up to an Esquilo Air.

Remote LCD
  • 767
  • 20

Full instructions

Remote LCD message display with RGB backlight using Esquilo, controlled by a NetIO mobile app.

You Forgot to Take Your Pill
  • 175
  • 2

Using an Esquilo and accelerometer attached to a pill box, alert me if my pill box didn't move during the time I am supposed to take it.

Esquilo Air & 5161AS 1 digit 7 segment LED Tutorial
  • 191
  • 0


This is a simple example setup to show how to hook a 5161AS 1 digit 7 segment LED display to an Esquilo Air.

Esquilo Air & HC-SR04 + 1602 LCD Tutorial
  • 133
  • 0


This is a simple example setup to show how to hook an HC-SR04 Ultrasonic Sensor and an 1602A LCD panel up to an Esquilo Air.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog