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.

CODE: SELECT_ALL_CODE
/*******************************************************************************
    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.
    Website: http://www.cytron.com.my
    Email: support@cytron.com.my
*******************************************************************************/

#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);

  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);

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

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

void loop()
{
  lcd.clear();
    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);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  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);

  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
 
lcd.print(7, 1, cm);

  Blynk.run();
  delay(1000);

}

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;
}
tiz
Fledgling
 
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.
http://www.cytron.com.my
User avatar
Idris
Moderator
 
Posts: 409
Joined: Thu Mar 22, 2012 5:28 pm
Location: Pulau Pinang

Re: Espresso lite v2.0 + ultrasonic sensor

Postby RonnieBenson » Thu Mar 17, 2022 6:19 pm

Is it a good coffee machine? :D
RonnieBenson
Greenhorn
 
Posts: 2
Joined: Thu Mar 17, 2022 6:16 pm


Return to Getting Started - IoT

Who is online

Users browsing this forum: No registered users and 11 guests