Printing the Distance on LCD 5110 Screen

by Azmi Deliaslan in Circuits > Arduino

329 Views, 1 Favorites, 0 Comments

Printing the Distance on LCD 5110 Screen

20190316_235222.jpg

Hey everyone. Today , ı am ganna show you how can you measure the distance and print the distance on the screen.

Let's look steps...

PARTS

Here is a list of parts that i used to make this project:

  • Arduino UNO
  • HC04 Ultrasonic Sensor
  • Breadboard
  • Jumper Wires (male to male and male to female)
  • LCD5110 Display

SCHEMA

Ekran Görüntüsü (13).png

CODE

code.jpg

The code has explanations of code functions. You will easly understand it. If you have a problem , you can contact me.

#include

LCD5110 lcd(8,9,10,11,12); //(clk,din,dc,rst,ce)

extern uint8_t MediumNumbers[]; //describe fonts extern uint8_t SmallFont[]; int echopin=6; //HC 04 ultrasonic sensor echopin int trigpin=5; //HC 04 ultrasonic sensor trigpin int BL=3; int TIME; //time int DISTANCE; //distance

void setup() { pinMode(echopin,INPUT); //echopin is ınput because it receives sound wave pinMode(trigpin,OUTPUT); //trigpin is output because it sends sound wave pinMode(BL,OUTPUT); //back light is output Serial.begin(9600); lcd.InitLCD(); //initilaze the lcd lcd.setContrast(55); //set contrast(0 to 125) }

void loop() { analogWrite(BL,300); digitalWrite(trigpin,LOW); //first, we start trigpin low delay(50); digitalWrite(trigpin,HIGH); //second, we open trigpin and send sound made delay(50); digitalWrite(trigpin,LOW); //then, we close again for other loop TIME = pulseIn(echopin,HIGH); //then, we open echopin and receive sound made //and measure the time with pulseIn() function. DISTANCE = sure/(2/29.1) ; //finally, we measure the distance

lcd.clrScr(); //clear screen lcd.drawRoundRect(0,0,70,43); //draw rectangle lcd.setFont(SmallFont); //set font lcd.print("DISTANCE",18,5); //print lcd.print("CM",40,30); //cm lcd.setFont(MediumNumbers); //set font lcd.printNumI(mesafe,2,22); //print distance delay(500); lcd.update(); //update }

THANKS FOR VIEWING