0% found this document useful (0 votes)
6 views

PWM LCD 7segment

Uploaded by

Himanshu Rohilla
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

PWM LCD 7segment

Uploaded by

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

Intro to the Arduino

Topics:
The Arduino
Digital IO
Analog IO
Serial Communication
Digital v/s Analog (Cont..)
•Microcontrollers are digital devices – ON or OFF. Also
called – discrete.
•analog signals are anything that can be a full range of
values. What are some examples? More on this later…

5V 5V

0V 0V
Digital v/s Analog & PWM
• A few (digital) pins (3,5,6,9,10,11) on the Arduino allow for us to
modify the output to mimic an analog signal.
• This is done by a technique called: Pulse Width Modulation (PWM).
• To create an analog signal, the microcontroller uses a technique
called PWM. By varying the duty cycle, we can mimic an “average”
analog voltage.

Pulse Width Modulation (PWM)


Pulse Width Modulation (PWM) Cont..

analogWrite(pin, val);
Eg. analogWrite(3, 0-255);

pin – refers to the OUTPUT


pin (limited to pins 3, 5, 6, 9, 10, 11.)
– denoted by a ~ symbol

val – 8 bit value (0 – 255).


0 = 0V | 255 = 5V
Example
How many PWM pins are available
in UNO
• A)3
• B)4
• C) 5
• D) 6
Arduino sketch (Eg. 1)
//Arduino sketch to adjust/control the brightness of LED using PWM, use map function

int ledPin = 9; // LED connected to digital pin 9


int analogPin = A3; // potentiometer connected to analog pin 3
int val = 0, val1 = 0; // variable to store the read value
void setup()
{
pinMode(ledPin, OUTPUT); // sets the pin as output
}
void loop()
{
val = analogRead(analogPin); // read the input pin
val1=map(val,0,1023,0,255);
analogWrite(ledPin, val1); //val1 values range is: 0- 255
//analogWrite(ledPin, val / 4); // analogRead values go from 0 to 1023,
// analogWrite values
from 0 to 255
}
Proteus design (Eg. 1)
Which pins are used to take analog
input from Arduino UNO?
• A) A0
• B) 0
• C) 9
• D) 6
WAP to change the LED intensity
using HC05.
WAP to change the intensity of Internal room light as change in
itensity outside the house.
7-segment Display

• The 7-segment display, also written as “seven segment


display”, consists of seven LEDs (hence its name) arranged in a
rectangular fashion as shown.

• Each of the seven LEDs is called a segment because when


illuminated the segment forms part of a numerical digit (both
Decimal and Hex) to be displayed.

• An additional 8th LED is sometimes used within the same


package thus allowing the indication of a decimal point, (DP)
when two or more 7-segment displays are connected together
to display numbers greater than ten.
7- segment Pin configuration
• Common Cathode
• Common Anode
Glowing of Leds of 7-segment display
// to test common anode 7 segment//
void setup()
{
// define pin modes
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
}
void loop()
{
// loop to turn leds od seven seg ON

for(int i=6;i<13;i++)
{
digitalWrite(i, LOW);
delay(600);
}
// loop to turn leds od seven seg OFF
for(int i=6;i<13;i++)
{
digitalWrite(i, HIGH);
delay(600);
}
delay(1000);
}
Seven Segment
Common Cathode Seven Segment
What will be the hex vaue to display eight
with dot on Seven segment using Common
annode Seven Segment?
• A) 7F
• B) FF
• C) 00
• D) 4F
Code
Driving Multi-digit 7-segment LEDs
• You want to display numbers using a 7-segment
display that shows two or more digits.
Liquid Crystal Display (LCD)
• Liquid crystal displays (LCDs) offer a
convenient and inexpensive way to provide a
user interface for a project.
4bit mode
4bit mode
LCD Interfacing
LCD pin details
Header files

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins


LiquidCrystal lcd (rs, enable, d4, d5, d6, d7)
LCD Library Commands
begin()

Description
Initializes the interface to the LCD screen, and specifies the dimensions (width
and height) of the display. begin()needs to be called before any other LCD
library commands.

Syntax

lcd.begin(cols, rows)

Parameters
lcd: a variable of type LiquidCrystal
cols: the number of columns that the display has
rows: the number of rows that the display has
setCursor()

Description
Position the LCD cursor; that is, set the location at which subsequent text
written to the LCD will be displayed.

Syntax
lcd.setCursor(col, row)

Parameters
lcd: a variable of type LiquidCrystal
col: the column at which to position the cursor (with 0 being the first column)
row: the row at which to position the cursor (with 0 being the first row)
write()

Description
Write a character to the LCD.

Syntax
lcd.write(data)

Parameters
lcd: a variable of type LiquidCrystal
data: the character to write to the display
print()

Description
Prints text to the LCD.

Syntax

lcd.print(data)
lcd.print(data, BASE)

Parameters
lcd: a variable of type LiquidCrystal

data: the data to print (char, byte, int, long, or string)

BASE (optional): the base in which to print numbers: BIN for binary (base 2),
DEC for decimal (base 10), OCT for octal (base 8), HEX for hexadecimal
(base 16).
cursor() noCursor()
Description:
Display the LCD cursor an Description
underscore (line) at the position to Hides the LCD cursor.
which the next character will be
written.

Syntax
lcd.cursor()
Syntax
lcd.noCursor()
noDisplay() display()

Description Description
Turns off the LCD display, without Turns on the LCD display, after it's been
losing the text currently shown on it. turned off with noDisplay(). This will
restore the text (and cursor) that was on
the display.

Syntax
Syntax
lcd.display()
lcd.noDisplay()
setCursor()

Description
Position the LCD cursor; that is, set the location at which subsequent text written to
the LCD will be displayed.

Syntax
lcd.setCursor(col, row)

Parameters
lcd: a variable of type LiquidCrystal
col: the column at which to position the cursor (with 0 being the first column)
row: the row at which to position the cursor (with 0 being the first row)
scrollDisplayLeft() scrollDisplayRight()

Description Description
Scrolls the contents of Scrolls the contents of
the display (text and the display (text and
cursor) one space to the cursor) one space to the
left. right.

Syntax Syntax
lcd.scrollDisplayLeft() lcd.scrollDisplayRight()
leftToRight() rightToLeft()

Description Description
Set the direction for text written to the
Set the direction for text written to the
LCD to right-to-left (the default is left-
LCD to left-to-right, the default. This to-right). This means that subsequent
means that subsequent characters characters written to the display will
written to the display will go from left go from right to left, but does not
to right, but does not affect affect previously-output text.
previously-output text.
Syntax
Syntax lcd.rightToLeft()
lcd.leftToRight()
clear()

Description
Clears the LCD screen and positions the cursor in the
upper-left corner.

Syntax
lcd.clear()

Parameters
lcd: a variable of type LiquidCrystal
Which lcd function help to clear
the data from its screen only?
• A) clear()
• B) clearit()
• C) display()
• D) noDisplay()
Example 1- Still Message Display On
LCD
// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins


LiquidCrystal (rs, enable, d4, d5, d6, d7)
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
void loop()
{
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins
with 0):
lcd.setCursor(0,1);
delay(250);
}
Arduino sketch
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // LiquidCrystal lcd(Rs,En,D4,D5,D6,D7)


void setup()
{
lcd.begin(16, 2);
}
void loop()
{
lcd.setCursor(0,0);
lcd.print(" **hello Class**");
lcd.setCursor(0, 1);
lcd.print(" Study Well ");
}
Example 2- Moving message display on
LCD
// include the library code:
#include <LiquidCrystal.h>
char message[]={"Lovely Professional University"};
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
}
void loop()
{
// set the cursor to (0,0):
lcd.setCursor(0, 0);

for (int i = 0; i <= 30; i++)


{
lcd.print(message[i]);
delay(200);
if(i>16)
{
lcd.autoscroll();
}
}
}
LCD Interfacing
LCD Custom Message
• The LCD display has two lines of characters, 16
characters per line.
• Each character is composed of matrix of pixels size 5x8.

DDRAM Memory (Display Data RAM)


Display data RAM (DDRAM) stores the information we
send to LCD in ASCII Code.
For each letter there is a special code that represents it.
For example, the letter A in ASCII code, “receives” a value
of 65 in base 10 or 01000001 in binary base, or 41 in the
base 16.
The memory can contain up to 80 letters.
CGRAM Memory (Character Generator RAM)
• Using CGRAM memory the user can “build” and store
their own letters.
• For 5x8 dots, eight character patterns can be written,
• And for 5x10 dots, four character patterns can be written.
• The difference between the memories is that the DDRAM
memory displays on the screen the “ready” characters in
accordance with the ASCII code, while the CGRAM
memory displays the special characters that the user has
created.
LCD Custom character code
void setup()
#include <LiquidCrystal.h>
{
// create a new custom character
// initialize the library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
lcd.createChar(0, customChar);
byte customChar[8] = {
// set up number of columns and
0b00000,
rows
0b00000,
0b01010,
lcd.begin(16, 2);
0b00000,
lcd.write((byte(0));
0b10001,
}
0b01110,
0b00000,
void loop()
0b00000
{
};
}
void setup()
{
// create a new custom character

lcd.createChar(0, customChar);

// set up number of columns and rows

lcd.begin(16, 2);
lcd.write((byte(0));
}

void loop()
{
}
WAP to display hello and bye on LCD received from HC05
WAP to display smiles as temperature is increasing and
decreasing.
• map(x,0,1023,0,255)

You might also like