Espresso lite v2.0 + ultrasonic sensor

Discussion on how to get started with various type of IoT projects

Espresso lite v2.0 + ultrasonic sensor

Postby tiz » Sat May 19, 2018 12:29 pm

Hi. I'm doing a project to read data value from ultrasonic sensor using espresso lite v2.0. And, I also link it to Blynk (LCD Settings). But, I keep getting 0 value in my reading. Can you tell what is wrong with my connection or programming? Here is my code. Thank you.

    Cytron IoT Workshop

    This example demonstrates how to control the ESPresso Lite from iOS
    and Anroid using the Blynk platform.

    Created by: Cytron Technologies Sdn Bhd.

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "4110d4dcf7724f3d867ae62136699bfe";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "etot";
char pass[] = "laici kang";

const int trigPin = 12;
const int echoPin = 13;

WidgetLCD lcd(V1);

void setup()
  pinMode(2, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);

  Blynk.begin(auth, ssid, pass);

    lcd.clear(); //Use it to clear the LCD Widget

  lcd.print(0, 0, "Distance in cm");

void loop()
    lcd.print(0, 0, "Distance in cm");

  // establish variables for duration of the ping,
  // and the distance result in inches and centimeters:
  long duration, inches, cm;

  // The sensor is triggered by a HIGH pulse of 10 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  digitalWrite(trigPin, LOW);
  digitalWrite(trigPin, HIGH);
  digitalWrite(trigPin, LOW);

  // Read the signal from the sensor: a HIGH pulse whose
  // duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  duration = pulseIn(echoPin, HIGH);

  // convert the time into a distance
  cm = microsecondsToCentimeters(duration);

lcd.print(7, 1, cm);;


long microsecondsToCentimeters(long microseconds)
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
Posts: 1
Joined: Wed Apr 18, 2018 5:56 pm

Re: Espresso lite v2.0 + ultrasonic sensor

Postby Idris » Thu May 24, 2018 8:50 am

Hi tiz,

Could you share a few clear photos of your hardware setup?
Cytron Technologies invest time and resources providing tutorial, training and support for STEM education and maker movement. We need your support by purchasing products from Cytron Technologies. Thanks.
User avatar
Posts: 388
Joined: Thu Mar 22, 2012 5:28 pm
Location: Pulau Pinang

Return to Getting Started - IoT

Who is online

Users browsing this forum: No registered users and 3 guests