Skip to main content

Seven Segment Display Interfacing with Arduino


In this tutorial, we will learn how to interface a 7 SEGMENT DISPLAY with Arduino. A 7 SEGMENT DISPLAY consists of 8 LEDs and 10 pins,2 common pins are shorted and supplied with 5 volts from Arduino through a resistor and other 8 pins are connected to digital and analog pins.

7 Segment Display can act as a substitute for LCDs if we want to display numbers.

Shown below is the internal architecture of a 7 segment display.

Now let’s interface the 7 SEGMENT DISPLAY.
Components required
  • Arduino Uno                       1No.
  • 7 Segment Display              1No.
  • Resistors                             1No.            100 ohms            
  • Connecting Wires
  • Breadboard
There are two types of LED 7-segment display
  • The common cathode (CC) 
  • Common anode (CA)
In CC type the cathode of all the LEDs is connected together and similarly in CA type.
In CC type we have to ground the common cathode pin and power up segments to illuminate it, the reverse happens for CA types. Here we have to power up the common anode pin and provide ground to segments according to our requirements of illuminations.

The below code can be used to display digits from Zero to Nine.

void setup() 
{
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
}

void loop() 
{ // ZERO
digitalWrite(2,LOW);
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
delay(1000);
// Zero off
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
delay(1000); // ONE
digitalWrite(4,LOW);
digitalWrite(6,LOW);
delay(1000);
//1 off
digitalWrite(4,HIGH);
digitalWrite(6,HIGH);
delay(1000);
//2 0N
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
delay(1000);
//2 0ff
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
delay(1000);
//3 0n
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(5,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
delay(1000);
//3 0ff
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(5,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
delay(1000);
//4 on
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(8,LOW);
delay(1000);
//4 0ff
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(8,HIGH);
delay(1000);
//5 0n
digitalWrite(2,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
delay(1000);
//5 off
digitalWrite(2,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
delay(1000);
//6 0n
digitalWrite(2,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
delay(1000);
//6 off
digitalWrite(2,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
delay(1000);
//7 0n
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(8,LOW);
delay(1000);
//7 off
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(8,HIGH);
delay(1000);
//8 on
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
delay(1000);
//8 off
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
delay(1000);
//9 0n
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(8,LOW);
delay(1000);
//9 0ff
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(8,HIGH);
delay(1000);
}
Video


Now try this out with multiple 7 segment displays.
  • You can also use IC 7446 which is a BCD to 7 segment decoder by which you can display all your digits with the combination of four inputs.Connect the IC as shown below.
      
                                                             Thinking?

Join our hands-on training courses.
To know more visit us at http://www.sudolearn.com/

Comments

Popular posts from this blog

Soil Moisture Monitoring using ESP8266 and Soil Moisture Sensor

Hey folks In this tutorial, we will learn how to interface LM393 module(Soil Moisture Sensor)with NodeMcu(ESP8266). LM393 is a simple water sensor can be used to detect soil moisture when the soil moisture deficit module plant waterer device, so that the plants in our garden without people to manage; Adjustable sensitivity adjust the digital potentiometer (shown in blue) Operating Voltage 3.3V-5V; Module Dual Output mode, a simple. LM393 Soli Moisture Sensor Module(over view)  Components Required: LM393 Soil Sensor  NodeMcu(ESP8266)  Connecting wires(male to male)  Breadboard  Follow the Image below for circuit connection reference:- (Interfacing all components)  Here Pin A0 of the moisture sensor module connects to pin A0 on the ESP8266 The GND pin on the moisture sensor module connects to a GND pin on the ESP8266 The VCC pin on the moisture sensor module connects to a 3v3 pin on the ESP8266 D0 pin remain disconnected After making th...

Servo Motor Control using ESP8266 and Blynk App

Hey folks,  In this tutorial we will learn how to interface Servo motor with NodeMcu(ESP8266)module and operate it with the Blynk app.  Servos  are controlled by sending an electrical pulse of variable width, or pulse width modulation (PWM), through the control wire. There is a minimum pulse, a maximum pulse, and a repetition rate. A  servo motor  can usually only turn 90° in either direction for a total of 180° movement. servo Motor (Back view)  Servo Motor (front view) Blynk  is a Platform with iOS and Android  apps  to control Arduino, Raspberry Pi and the likes over the Internet. It's a digital dashboard where you can build a graphic interface for your project by simply dragging and dropping widgets. (Blynk App) Components Required: Servo motor NodeMcu(ESP8266) Connecting wires(male to male) Breadboard    Follow the image below for circuit connection reference. (Servo Motor connecting wi...

Webcam Interfacing with Raspberry Pi

This tutorial is about the clicking photos and recording videos using "Logitech Webcam C110 with Raspberry Pi 3 Model B" Component Required: Rasberry Pi 3 Model B  Logitech Webcam C110  Adapter Charger micro USB-b Type 5v,2Amp  Connection Diagram: Step 1: Create a new folder First, we create a new folder just to store your photo and videos separately. Open the terminal. Command for creating new folder is "mkdir folder name" Step 2: Check everything is up-to-date To update your Raspberry Pi command is " sudo apt-get update ". And to upgrade your Raspberry Pi command is " sudo apt-get upgrade". Step 3: Check SSH and Camera enabled To make sure SSH and Camera enabled. Follow these two-steps. By this command, you can configure your SSH and Camera " sudo raspi-config ". Enable SSH. Enable Camera. Step 4: Check connection of Camera Make sure the camera is connected. Then run this command to make sure...