100% found this document useful (2 votes)
283 views

Arduino Uno and LCD DISPLAY

The document discusses using an Arduino Uno board with an LCD display and ultrasonic sensor. It provides code examples to initialize a 16x2 LCD display, write text to the display, create custom characters, and read distance measurements from an ultrasonic sensor. Functions like lcd.begin(), lcd.write(), and lcd.createChar() are explained for controlling the LCD display. The ultrasound distance measurement code uses pulseIn() to determine the echo pulse duration and converts that to a distance in centimeters.

Uploaded by

MadanKumar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
283 views

Arduino Uno and LCD DISPLAY

The document discusses using an Arduino Uno board with an LCD display and ultrasonic sensor. It provides code examples to initialize a 16x2 LCD display, write text to the display, create custom characters, and read distance measurements from an ultrasonic sensor. Functions like lcd.begin(), lcd.write(), and lcd.createChar() are explained for controlling the LCD display. The ultrasound distance measurement code uses pulseIn() to determine the echo pulse duration and converts that to a distance in centimeters.

Uploaded by

MadanKumar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Arduino Uno and LCD DISPLAY

LCD 16x2
• LCDs (Liquid Crystal Displays) are used in embedded system
applications for displaying various parameters and status of the system.
• LCD 16x2 is a 16-pin device that has 2 rows that can accommodate 16
characters each.
• LCD 16x2 can be used in 4-bit mode or 8-bit mode.
• It is also possible to create custom characters.
• It has 8 data lines and 3 control lines that can be used for control
purposes.
• For more information about LCD 16x2 and how to use it, refer the topic
LCD 16x2 module in the sensors and modules section.
• lcd.begin(cols,rows)
• This function is used to define the number of rows
and columns the LCD has and to initialize the LCD.
• Needs to be called before calling other functions,
once the object is defined using the function in point
1.
• Example, for 16x2 LCD we write lcd.begin(16,2). lcd is
the name of the object of the class LiquidCrystal. 16 is
the number of columns and 2 is the number of rows.
• lcd.setCursor(col,row)
• This function positions the cursor of the LCD to a
location specified by the row and column parameters.
• col is the column number at which the cursor should be
at (0 for column 1, 4 for column 5 and so on).
• row is the row number at which the cursor should be at
(0 for row 1, 1 for row 2).
• Example, for setting the cursor at the 5th  column in the
2nd  row, lcd.setCursor(4,1). lcd is the name of the
object of the class LiquidCrystal.
• lcd.createChar(num,data)
• This function is used to create a new custom character for use on the LCD.
• num is the CGRAM location (0 to 7) at which the custom character is to be
stored.
• data is array of eight bytes which represent the custom character.
• Custom character can be of 5x8 pixels only.
• Each custom character is specified by an array of eight bytes, one for each row.
The five least significant bits of each byte determine the pixels in that row.
• To display a custom character on the screen, write() function needs to be used.
CGRAM location number (0 to 7) of the custom character which is to be
displayed on LCD is passed as an argument to the write function.
• Note : When referencing custom character "0", you need to cast it as a byte,
otherwise the compiler throws an error.
• Digital Temperature LCD with TMP36 and RGB
led Temperature : -40 - 125C
• Materials:
– RGB led
Link
– 220 Ohm
– LCD 1602
– wires
– breadboard
#include <LiquidCrystal.h>

// Connections:
// rs (LCD pin 4) to Arduino pin 12
// rw (LCD pin 5) to Arduino pin 11
// enable (LCD pin 6) to Arduino pin 10
// LCD pin 15 to Arduino pin 13
// LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

byte smiley[8] = {
B00000,
B10001,
B00000,
B00000,
B10001,
B01110,
B00000,
};

int backLight = 13; // pin 13 will control the backlight


void loop()
{
delay(1000);
// Turn off the display:
lcd.noDisplay();
delay(500);
// Turn on the display:
lcd.display();

// lee la entrada analógica desde el pin 0


int valor_sensor = analogRead(A0);
// muestra el valor que se leyó
Serial.println(valor_sensor);
delay(1); // retraso entre lectura y lectura, para la estabilidad
}
#include <LiquidCrystal.h>
/* Create object named lcd of the class LiquidCrystal */
LiquidCrystal lcd(13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3);
/* For 8-bit mode */ //
LiquidCrystal lcd(13, 12, 11, 6, 5, 4, 3);
/* For 4-bit mode */
unsigned char Character1[8] = { 0x04, 0x1F, 0x11, 0x11, 0x1F, 0x1F, 0x1F, 0x1F }; /* Custom
Character 1 */
unsigned char Character2[8] = { 0x01, 0x03, 0x07, 0x1F, 0x1F, 0x07, 0x03, 0x01 }; /* Custom
Character 2 */
void setup()
{ lcd.begin(16,2); /* Initialize 16x2 LCD */
lcd.clear(); /* Clear the LCD */
lcd.createChar(0, Character1); /* Generate custom character */ lcd.createChar(1, Character2); }
void loop()
{ lcd.setCursor(0,0); /* Set cursor to column 0 row 0 */
lcd.print("Hello!!!!"); /* Print data on display */
lcd.setCursor(0,1);
lcd.write(byte(0)); /* Write a character to display */
lcd.write(1); }
Arduino Uno with Ultrasonic Sensor
• Aim:
• To measure distances with an ultrasonic
rangefinder (distance sensor) and Arduino's digital
input
Ultrasonic Sensor
• ultrasonic / level sensors measure distance by
using ultrasonic waves.
• The sensor head emits an ultrasonic wave and
receives the wave reflected back from the target.
ultrasonic / level sensors measure the distance to
the target by measuring the time between the
emission and reception.
• The distance can be calculated with the following
formula:
• Distance L = 1/2 × T × C
• where L is the distance, T is the time between the
emission and reception, and C is the sonic speed.
(The value is multiplied by 1/2 because T is the time
for go-and-return distance.)
Features
• The following list shows typical characteristics enabled by the
detection system.
• [Transparent object detectable]
• Since ultrasonic waves can reflect off a glass or liquid surface and
return to the sensor head, even transparent targets can be detected.
• [Resistant to mist and dirt]
• Detection is not affected by accumulation of dust or dirt.
• [Complex shaped objects detectable]
• Presence detection is stable even for targets such as mesh trays or
springs.
This sketch reads a PING))) ultrasonic rangefinder and returns the distance to the closest object in range. To do
this, it sends a pulse
to the sensor to initiate a reading, then listens for a pulse to return. The length of the returning pulse is
proportional to
the distance of the object from the sensor.

The circuit:
* +V connection of the PING))) attached to +5V
* GND connection of the PING))) attached to ground
* SIG connection of the PING))) attached to digital pin 7

const int pingPin = 7;


const int ledPin = 9;

void setup() {
// initialize serial communication:
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
//pinMode();
}
void loop() {
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, cm;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): 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.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
// convert the time into a distance
cm = microsecondsToCentimeters(duration);
// Print the distance
Serial.print("Distance: ");
Serial.print(cm);
Serial.print("cm");
Serial.println();

// Turn on the LED if the object is too close:


if(cm < 100) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}

delay(100);
}

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;
}

You might also like