0% found this document useful (0 votes)
11 views1 page

Arduino

This document contains an Arduino code that measures distance using an ultrasonic sensor and displays the result on an LCD screen. It initializes the sensor and LCD in the setup function, then continuously measures distance in the loop function, updating the display only when the distance changes. The code utilizes the Wire and LiquidCrystal_I2C libraries for I2C communication with the LCD.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Arduino

This document contains an Arduino code that measures distance using an ultrasonic sensor and displays the result on an LCD screen. It initializes the sensor and LCD in the setup function, then continuously measures distance in the loop function, updating the display only when the distance changes. The code utilizes the Wire and LiquidCrystal_I2C libraries for I2C communication with the LCD.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include <Wire.

h>
#include <LiquidCrystal_I2C.h>
const int trigPin = 9;
const int echoPin = 10;
long duracion;
int distancia;
int ultimaDistancia = 0;
LiquidCrystal_I2C lcd(0x27,16,2);
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
[Link](9600);
[Link]();
[Link]();
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duracion = pulseIn(echoPin, HIGH);
distancia = (duracion * 0.034) / 2;
[Link](distancia);
if(distancia != ultimaDistancia)
{
[Link]();
[Link](0, 0);
[Link]("Distancia: "); // Prints string "Distance" on the LCD
[Link](distancia);
[Link](" cm");
ultimaDistancia = distancia;
}
delay(500);
}

You might also like