Tag Archives: LCD

Seven segment display interface with Arduino (Without library)

A seven-segment display is a form of electronic display device for displaying decimal numerals that is an alternative to the more complex dot matrix displays. In this tutorial you will learn about seven segment display interface with Arduino, its possibilities & Arduino code. Seven-segment displays may use a liquid crystal display (LCD), a light-emitting diode (LED) for each segment, an electrochromic display, or other light-generating or controlling techniques such as cold cathode gas discharge (Panaplex), vacuum fluorescent (VFD), incandescent filaments (Numitron), and others.

In a simple LED package, typically all of the cathodes (negative terminals) or all of the anodes (positive terminals) of the segment LEDs are connected and brought out to a common pin; this is referred to as a “common cathode” or “common anode” device. Hence a 7 segment plus decimal point package will only require nine pins, though commercial products typically contain more pins, and/or spaces where pins would go, in order to match standard IC sockets.

Characters on seven segment display

The segments of a 7-segment display are referred to by the letters A to G, where the optional decimal point (an “eighth segment”, referred to as DP) is used for the display of non-integer numbers.

You can display 0-9 decimals on seven segment display. The most common patterns used for each of these is:

To display hexadecimals, you have to turn on segments to represent A, B, C & D. Same can be displayed as;

So, using seven segment display you can easily display hexadecimal numbers from 0 to F. To represent same, you can refer following table:

Digit Display gfedcba abcdefg a b c d e f g
0 0 0x3F 0x7E on on on on on on  
1 1 0x06 0x30   on on        
2 2 0x5B 0x6D on on   on on   on
3 3 0x4F 0x79 on on on on     on
4 4 0x66 0x33   on on     on on
5 5 0x6D 0x5B on   on on   on on
6 6 0x7D 0x5F on   on on on on on
7 7 0x07 0x70 on on on        
8 8 0x7F 0x7F on on on on on on on
9 9 0x6F 0x7B on on on on   on on
A A 0x77 0x77 on on on   on on on
b b 0x7C 0x1F     on on on on on
C C 0x39 0x4E on     on on on  
d d 0x5E 0x3D   on on on on   on
E E 0x79 0x4F on     on on on on
F F 0x71 0x47 on       on on on

Apart from hexadecimals, there are few characters which are being used to display on seven segment display which are as below;

Case A B C D E F G H I J K L M N O P Q R S T U V W X Y
Upper A   C   E F G H I J   L     O P     S   U        
Lower   b c d       h i         n o   q r   t u       y

Few short messages giving some status information (e.g. “no dISC” on a CD player) are also usually represented on seven segment displays. In the case of such messages it is not necessary for every letter to be unambiguous, merely for the words as a whole to be readable. For example:

There are few decoder ICs available in market (like CD4511) which has BCD as input (4 pins) & seven segment pins as output. First we will see how to connect a seven segment display with Arduino without any external IC.

Seven segment display pinout

7 segment pinout

As you can see, all segment LEDs are connected with common pin & separate pinout pins for each LED. Above diagram is common cathode seven segment display, if it is common anode then LED polarity will be reversed compared to common cathode.

Seven segment display interface with Arduino

Seven segment display interface with Arduino

In above connection diagram, common cathode type seven segment is used to interface with Arduino. If you have common anode type seven segment display, you have to connect 

Usually, the display may run without any current limiting resistors. So it is advised to use for protection against high current & display segments burnout. Usually for a commonly used red color seven segment display, each LED segment can draw around 15 mA to illuminated properly, so for 5 volt digital logic circuit, the value of the current limiting resistor would be about 200Ω (5v – 2v) / 15mA, or 220Ω to the nearest preferred value. SO resistor value may vary as per seven segment display technical specifications. You can test each segment LED of your seven segment by applying +1.5V to 5V on each pin and common pin to ground.

Arduino code for seven segment display test without library

You can download above code from here.

Above code is for basic understanding seven segment display’s working operation by Arduino. Basically, it is just particular segment pin HIGH & LOW, but it may be more complex if you have more than one displays (that is different topic of seven segment display multiplexing and same will be posted on #beatyourbit in future). The code is to display 0-9 counts at interval of 1 second. The output will look like,

Thus, It may be little bit long but also without any library you can simply use seven segment display. Similar code you can write by directly writing on GPIO ports (Pure AVR method). Find below code with similar output as above:

You can download above code from here.

Understanding above code:

ATmega328p has total 3 No. of GPIO ports namely Port B, Port C & Port D. Port C is an analog port as it has total six pins which are usually used as A0 to A6 in Arduino. Port B & Port D are digital ports & each port has 7 pins hence total 14 digital pins (D0 to D13). here in above code we have used port addressing, the basic method of AVR programming.

I hope you will learn to use single seven segment display by this tutorial & it will be helpful to display some counts or characters in your DIY stuff. In future you can use external seven segment decoders ICs to run such seven segment displays using minimum pins and also multiplexing of multiple seven segment displays; such tutorials will be uploaded soon on #BeatYourBit website. If you like this tutorial, share it with your friends & any Arduino newbie you know. Give your feedback about this tutorial in Contact, Your feedback will be appreciated.

Like/Follow @beatyourbit on FacebookTwitterInstagram & Telegram for latest updates.

16×2 LCD interface with Arduino

A liquid-crystal display (LCD) is a flat-panel display or other electronically modulated optical device that uses the light-modulating properties of liquid crystals. Liquid crystals do not emit light directly, instead using a back-light or reflector to produce images in color or monochrome. LCDs are available to display arbitrary images (as in a general-purpose computer display) or fixed images with low information content, which can be displayed or hidden, such as preset words, digits, and 7-segment displays, as in a digital clock. They use the same basic technology, except that arbitrary images are made up of a large number of small pixels, while other displays have larger elements. In this tutorial, we are using 16×2 character LCD display where 16 is characters per line & there are two lines. It means each 16×2 LCD can represent 32 characters, you can represent more characters by scrolling the text.

LCD

LCD-RearIn this LCD each character is displayed in 5×7 pixel matrix. This LCD has two registers, command & data. Like its name, Command register stores command sent to LCD & data register stores the data to be displayed on LCD. Basically the data is ASCII characters which is sent to be displayed on LCD. For more details about LCD, check here.

Pinout

  • +Vcc: Supply voltage is 4.7V to 5.3V DC
  • GND: Ground (0V)
  • Contrast: Contrast adjustment of LCD, through variable resistor to +Vcc
  • RS: It means ‘Register Select’, Selects command register when low & command register when high
  • RW: It means ‘Read/Write’, Low to write the register and high to read from register
  • EN: It means ‘Enable’, sends data to data pins when a high to low pulse is given.
  • D0 to D7: 8 bit data pins
  • Back-light+ : Vcc (+5V) for LCD back-light
  • Back-light- : Ground (0V) for LCD back-light

Connection with Arduino UNO R3

There are two methods to interface 16×2 LCD with Arduino:

  1. Connect all pins of LCD to Arduino
  2. Use I2C module and connect to Arduino by two pins only

In first method, RS, R/W, EN and Data pins will be connected to Arduino;

As shown in above image, contrast pin is connected with pin 6 of Arduino hence contrast will be adjusted by value set in code. In the program ‘LiquidCrystal’ library so make sure you have same library installed in your Arduino IDE. (You can install libraries from Sketch>Include library>Manage libraries)

Code for direct connection method:

You can download above code from here.

In another method, an I2C module will be connected to LCD. By using I2C module only two pins SDA (Serial Data) & SCL (Serial Clock) will be used from Arduino so less wiring for this. LCD will receive commands from Arduino by I2C protocol

As shown in above image, I2C module is connected to LCD directly (For safer side, solder a female header strip on LCD and connect I2C on that so if somehow I2C module or LCD stops working then it can be easily replaced). You can connect multiple I2C device parallely on same pin. Actually A4 & A5 pins are SDA & SCL so same can be connected on A4 & A5 too(Check Arduino pinout first). There will be a jumper on I2C module which is used to turn on-off LCD backlight. You will find a potentiometer which is actually contrast set for LCD.

Code for I2C connection method:

You can download above code from here.

I2C module & its interface with LCD looks like this:

One more difference between both connection type is library. You need different library for I2C which is ‘LiquidCrystal_I2C’ and it is available here.

Before proceeding for I2C code download, you need to confirm I2C address. Each I2C module has an address which we need to mention in second line LiquidCrystal_I2C  lcd(0x3F, 16, 2); Here i’ve mentioned 0x3F because my I2C module has this address. To know your I2C module address you may need to run I2C scanner program in your Arduino and get I2C address on serial monitor like ths;

I2C scanner

Use this tutorial to know the address of your I2C device. Get I2C address, put in above code & eureka…!!!

After connecting LCD with Arduino you can display sensor & variable values, text messages & also can set values by interfacing keypad with Arduino. Give your feedback about this tutorial in Contact, Your feedback will be appreciated.

Join on FacebookTwitterInstagram & Telegram for latest updates.