primiddlegledel
Published

Control LCD and Ultrasound Sensor with Arduino

Learning how to control lcd using Arduino. Then I changed the code of the Arduino connected to the breadboard and connected the ultrasonic.

BeginnerShowcase (no instructions)1 hour1,636
Control LCD and Ultrasound Sensor with Arduino

Things used in this project

Code

code

Arduino
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
lcd.begin(16, 2);
lcd.print("hello, world!");
delay(2000);
lcd.clear();
}
void loop() {
lcd.setCursor(0, 0);
lcd.print("time : ");
lcd.print(millis() / 1000);
char second = 's';
lcd.print(second);
}
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int trigPin = 9;
int echoPin = 8;
long distance;
long duration;
void setup() {
lcd.begin(16, 2);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
ultra();
lcd.setCursor(0, 0);
lcd.clear();
lcd.print("UltraSonic");
lcd.setCursor(0, 1);
lcd.print("distance : ");
lcd.print(distance);
lcd.print("cm");
delay(200);
if(distance <=10){
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
digitalWrite(13, LOW);
}
void ultra(){
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
}

Credits

primiddle
6 projects • 0 followers
I'm bongilcheon high school student. And I want to doing arduino, 3D modeling well.
gledel
100 projects • 116 followers
Looking back on my childhood, I was happy when I was making something and I was proud of myself. "Making is instinct!"

Comments