Arduino Uno and LCD DISPLAY
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,
};
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
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();
delay(100);
}