Leeland Heins
Published © GPL3+

Esquilo Air & HC-SR04 + 1602 LCD Tutorial

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.

BeginnerProtip1 hour736
Esquilo Air & HC-SR04 + 1602 LCD Tutorial

Things used in this project

Hardware components

Esquilo Air
Esquilo Air
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
10k pot
×1
Breadboard (generic)
Breadboard (generic)
×1
Male/Male Jumper Wires
I used: 5 red, 5 black, 2 white, 3 orange, 1 yellow, 2 green, 2 blue
×20

Story

Read more

Schematics

Esquilo HC-SR04 1602A wiring diagram

Esquilo HC-SR04 1602A wiring diagram

Esquilo HC-SR04 Ultrasonic library

Port of Arduino Ultrasonic library to Esquilo

Esquilo 1602A library

Port of Arduino LiquidCrystal library to Esquilo

Code

Esquilo HC-SR04 1602A example code

Plain text
Esquilo HC-SR04 1602A example code
// HC-SR04 Ultrasonic Range Finder output to 1602A LCD

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

dofile("sd:/LiquidCrystal.nut");

trigPin <- GPIO(13);  // HC-SR04 trigger pin (output)
echoPin <- Capture(1);  // HC-SR04 echo pin (input)

trigPin.output();

local duration;
local distance;

local lcd = LiquidCrystal(0x00, 12, 0, 11, 5, 4, 3, 2, 0, 0, 0, 0);

// set up the LCD's number of columns and rows: 
lcd.begin(16, 2, 0);

while (true) {
    lcd.clear();
    lcd.home();
    trigPin.low();
    delay(2);
    trigPin.high();
    delay(10);
    trigPin.low();
    echoPin.arm(0, CAPTURE_EDGE_RISING);
    duration = echoPin.read(0);
    //print("duration=" + duration);
    distance = (duration / 2) / 29.1;
    //print("distance=" + distance);
    // Print a message to the LCD.
    lcd.print("distance=" + distance);
    delay(500);
}

Credits

Leeland Heins

Leeland Heins

4 projects • 0 followers
Hardware & Software H4x0r

Comments