Things used in this project

Hardware components:
Esquilo%20top%20small
Esquilo Air
×1
51gzz5eu9pl. sx425
HC-SR04
×1
Kingbright wp7113srd d image
5 mm LED: Red
×1
Kingbright wp7113sgd
5 mm LED: Green
×1
Mfr 25fbf52 221r sml
Resistor 221 ohm
×2
12002 04
Breadboard (generic)
×1
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
×8

Schematics

Esquilo HC-SR04 wiring diagram
Suggested wiring diagram
38afwbomcke8j3rqh8xk

Code

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.
 */

require("GPIO");
require("Capture");

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.
greenLed.output();

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

local duration;
local distance;

while (true) {
    trigPin.low();  // Pulse the trigger off.
    delay(2);
    trigPin.high();  // Pulse the trigger on.
    delay(10);
    trigPin.low();  // Pulse the trigger off.
    echoPin.arm(0, CAPTURE_EDGE_RISING);
    duration = echoPin.read(0);
    //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.
}

Credits

27eae0443d051e9e246159707c1f2203
Leeland Heins

Hardware & Software H4x0r

Contact

Replications

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

Comments

Similar projects you might like

Esquilo Grove Starter Kit Demos
Easy
  • 469
  • 9

Protip

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
Easy
  • 100
  • 4

Protip

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

Remote LCD
Easy
  • 746
  • 20

Full instructions

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

You Forgot to Take Your Pill
Easy
  • 165
  • 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
Easy
  • 159
  • 0

Protip

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
Easy
  • 127
  • 0

Protip

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.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login