Skip to main content

Latest Post

What is Industry 4.0?

  What is Industry 4.0 and what are some of the technologies that are driving it? Industry 4.0 is a term that refers to the fourth industrial revolution, which is characterized by the integration of digital technologies, such as artificial intelligence, cloud computing, big data, the internet of things, robotics, and 3D printing, into the manufacturing sector. Industry 4.0 aims to create smart factories that are more efficient, flexible, and responsive to customer needs and market changes. Some of the technologies that are enabling Industry 4.0 are: - Artificial intelligence (AI) : AI is the ability of machines to perform tasks that normally require human intelligence, such as reasoning, learning, decision-making, and problem-solving. AI can help optimize production processes, improve product quality, reduce costs, and enhance customer satisfaction. - Cloud computing: Cloud computing is delivering computing services, such as servers, storage, databases, software, and analytics, over t

Seven Segment Display Interfacing with Arduino

Seven-Segment Introduction 

Let’s start the main part of this tutorial by answering a question: what is a seven-segment display? As its name suggests, a 7-segment device consists of 7 light-emitting diodes. These light-emitting diodes are arranged and packed inside a single display with a specific pattern in mind. If this pattern is controlled in a specific way by turning on and turning off LEDs, a seven-segment device will display a unique number. There is also an extra eighth LED on a seven-segment display which is used to display dots. This dot is sometimes used as a decimal point when we want to display a fractional value. 

The picture below shows a seven-segment display and its pinout. The string of eight LEDs on the left side shows the internal connection and a picture on the right side shows how these LEDs are arranged to make a seven-segment display. Pin3 and 8 are common pins. These pins are used to provide either 5 volts or ground in common-anode and common cathode type displays respectively. 


Types of Seven Segment Displays 

There are two types of seven-segment displays such as common anode and common cathode.


Common Anode Display

In a common anode display, all the anodes terminals of eight light-emitting diodes are common and connect with a 5-volt power supply. In normal conditions, we apply logic high from Arduino to each segment. Therefore, each segment remains off or does not glow. Similarly, when we want to turn on a specific LED of a seven-segment device, we provide the logic low signal. Because LED glows only when there will be a logic high signal on the anode side and a logic low signal on the cathode side such is the case of a common anode type display. 

Common Cathode Display

In a common cathode segment display, all the cathodes of eight light-emitting diodes are common and connect with the ground. To turn off any segment of 7-segment, we apply logic low from Arduino to this segment. Similarly, when we want to turn on a specific LED of a seven-segment device, we provide a logic high signal from an Arduino digital output pin. Because LED glows only when there will be a logic high signal on the anode side and a logic low signal on the cathode side such is the case of a common cathode type display. 



7 Segment Display Interfacing with Arduino

So far in this tutorial, we talked about the internal structure, interfacing logic, and how we can write logic signals to control LED segments of a 7-segment device. In this section, we will learn to interface an Arduino development board with a single seven-segment display. 

We will need a breadboard, a few connecting wires, 220-ohm resistors, and an Arduino development board. First, connect a 7-segment device to a breadboard and connect a 220ohm resistor with each LED segment except a common terminal. 


As you see the pinout of a common anode 7-segment display by facing a dot point towards the upper side, pins 1-5 are on the upper side, and pins 10-6 are on the lower side of the module. Now make the connection according to the schematic diagrams given below. 

This table shows the connections of a segment display with Arduino. 

Arduino pins7-Segment display pins
5V3 or 8
2
3b
4c
6d
7e
8f
9g
5DP

After you complete the connections, your interfacing diagram will look like these:

Circuit Diagram:

Note: You should connect digital output pins of Arduino with LED segments pins of a 7-segment display using a 220-ohm resistor. Your display might work fine without these resistors, but it is better to use current limiting resistors to avoid any damage to Arduino digital pins. Because, when you use multiple or multiplex 2-digit, 3-digit, and even 4 digit displays, it will damage your Arduino pins without the use of current limiting resistors. 
Common Anode type seven segment display interfacing with Arduino

Common Cathode type seven segment display interfacing with Arduino

The only difference between a common anode and common cathode type 7-segments displays interfacing is common pins connection. For common anode type, connect common pins 3 or 8 with a 5-volt pin of Arduino. For the common cathode type, connect common pins 3 or 8 with the ground pin of Arduino.
It is also recommended to use a separate current driver IC if you want to interface multiple digits seven-segment displays with Arduino. 

Arduino Library

Now let’s write an Arduino code to control a single-digit 7-segment display. There are two ways to write a code. One is using an Arduino library and the other way is to write your own code from scratch. First, we will see an Arduino library method where we will use an Arduino library for a seven-segment display. 

.First, click on the button below and download the seven-segment library. 


After that add the library in Arduino IDE. To add the library, open your Arduino IDE, go to menu>>sketch>include the library as shown in the figure below:


Select the library SevSeg ZIP file and click on add. Library files will be included automatically in Arduino IDE. 

Arduino Code with Library

Now let’s see the example code. This code is a counter that counts from 0-9 by displaying the counter value on 7-segment. 

#include "SevSeg.h"
SevSeg sevseg;

void setup()
{
  //define number of seven-segment digits to one
  byte sevenSegments = 1;
 
  //variable used to define the number of seven segment and common pins
  //but we are using only one 7-segment. Hence leave it empty
  byte CommonPins[] = {};

  //array to store arduino pin connections with LED segments in order: A, B, C, D, E, F, G, DP
  byte LEDsegmentPins[] = {2, 3, 4, 6, 7, 8, 9, 5};
  bool resistorsOnSegments = true;

  //Initialize sevseg object that created above with input arguments defined already
  sevseg.begin(COMMON_ANODE, sevenSegments, CommonPins, LEDsegmentPins, resistorsOnSegments);
  //uncomment the following line for common cathode type display and comment the above
  //sevseg.begin(COMMON_CATHODE, sevenSegments, CommonPins, LEDsegmentPins, resistorsOnSegments);

  sevseg.setBrightness(90);
}

void loop()
{
   //loop display counter values from 0-9
   for(int i = 0; i < 10; i++)
   {
     sevseg.setNumber(i);  // Display counter value
     sevseg.refreshDisplay(); // refresh required
     delay(1000); // delay of one second
   }
}

Copy this code to Arduino IDE and try this code the schematic diagram you designed in the last step. You will get counter output on a seven-segment display and the value of the counter will be updated after every one second.


Popular

Playing with Buttons

Button Pushbuttons or switches connect two points in a circuit when you press them. This example turns on the built-in LED on pin 13 when you press the button. Hardware Arduino Board Momentary button or Switch 10K ohm resistor hook-up wires breadboard Circuit diagram Code // constants won't change. They're used here to // set pin numbers: const int buttonPin = 2 ;     // the number of the pushbutton pin const int ledPin =   13 ;      // the number of the LED pin // variables will change: int buttonState = 0 ;         // variable for reading the pushbutton status void setup () {   Serial . begin ( 9600 );   // initialize the LED pin as an output:   pinMode (ledPin, OUTPUT);   // initialize the pushbutton pin as an input:   pinMode (buttonPin, INPUT); } void loop () {   // read the state of the pushbutton value:   buttonState = digitalRead (buttonPin);   // Show the state of pushbutton on serial monitor   Serial . println (buttonState);   // check if the pushbutton is p

Home Automation

A smart system made by using Node MCU dev board. What is Node MCU? NodeMCU is an open-source firmware for which open-source prototyping board designs are available. The name "NodeMCU" combines "node" and "MCU" (micro-controller unit). The term "NodeMCU" strictly speaking refers to the firmware rather than the associated development kits.  Both the firmware and prototyping board designs are open source. Requirments Node MCU 4 channel relay toggle switch * 4 Hi-links (220v ac to 5v dc) Circuit Diagram Program #ifdef ENABLE_DEBUG         #define DEBUG_ESP_PORT Serial         #define NODEBUG_WEBSOCKETS         #define NDEBUG #endif #include <Arduino.h> #include <ESP8266WiFi.h> #include "SinricPro.h" #include "SinricProSwitch.h" #include <map> #define WIFI_SSID         "your wifi name"     #define WIFI_PASS         "your wifi pass" #define APP_KEY           "this code is prov

Turn LED On and Off Through LDR

  LDR An LDR ( Light Dependent Resistor ) is a component that has a (variable) resistance that changes with the light intensity that falls upon it. This allows them to be used in light sensing circuits. A photoresistor is made of a high resistance semiconductor. Hardware Required Arduino Board LED 220 ohm resistor LDR 10k ohms resistor Circuit Diagram Code int ldr=A0; //Set A0(Analog Input) for LDR. int value= 0 ; void setup () { Serial . begin ( 9600 ); pinMode ( 3 ,OUTPUT); } void loop () { value= analogRead (ldr); //Reads the Value of LDR(light). Serial . println ( "LDR value is :" ); //Prints the value of LDR to Serial Monitor. Serial . println (value); if (value< 300 )   {     digitalWrite ( 3 ,HIGH); //Makes the LED glow in Dark.   }   else   {     digitalWrite ( 3 ,LOW); //Turns the LED OFF in Light.   } }

Temperature sensor

About the LM35 The LM35 is an inexpensive, precision Centigrade temperature sensor made by  Texas Instruments . It provides an output voltage that is linearly proportional to the Centigrade temperature and is, therefore, very easy to use with the Arduino. The sensor does not require any external calibration or trimming to provide accuracies of ±0.5°C at room temperature and ±1°C over the −50°C to +155°C temperature range. One of the downsides of the sensor is that it requires a negative bias voltage to read negative temperatures. So if that is needed for your project, I recommend using the DS18B20 or TMP36 instead. The TMP36 by Analog Devices is very similar to the LM35 and can read temperatures from -40°C to 125°C without any external components Note that the sensor operates on a voltage range of 4 to 30 V and that the output voltage is independent of the supply voltage. The LM35 is part of a series of analog temperature sensors sold by Texas Instruments. Other members of the series i

MQ2 Gas Sensor

 About Gas Sensor The MQ series of gas sensors use a small heater inside with an electrochemical sensor. They are sensitive to a range of gasses and are used indoors at room temperature. The output is an analog signal and can be read with an analog input of the Arduino. The MQ-2 Gas Sensor module is useful for gas leakage detection in homes and industries. It can detect LPG, i-butane, propane, methane, alcohol, hydrogen, and smoke. Some modules have a built-in variable resistor to adjust the sensitivity of the sensor. Note:  The sensor becomes very hot after a while, don't touch it! Required  Arduino UNO Breadboard MQ-2 Gas sensor module Red, Green led 5mm 220 Ohm Buzzer The connections are pretty easy: The MQ-5 sensor Pin-> Wiring to Arduino Uno A0-> Analog pins D0-> none GND-> GND VCC-> 5V other components Pin-> Wiring to Arduino Uno D13-> +ve of buzzer GND-> -ve of buzzer D12-> anode of red light D11-> anode of green light GND-> cathode of red li

Play a melody with a Piezo speaker

  Play a Melody using the tone() function This example shows how to use the  tone()  command to generate notes. It plays a little melody you may have heard before. Hardware Required Arduino board piezo buzzer or a speaker hook-up wires Making header file To make the pitches.h file, either click on the button just below the serial monitor icon and choose "New Tab", or use Ctrl+Shift+N. Then paste in the following code: /************************************************* * Public Constants *************************************************/ # define NOTE_B0 31 # define NOTE_C1 33 # define NOTE_CS1 35 # define NOTE_D1 37 # define NOTE_DS1 39 # define NOTE_E1 41 # define NOTE_F1 44 # define NOTE_FS1 46 # define NOTE_G1 49 # define NOTE_GS1 52 # define NOTE_A1 55 # define NOTE_AS1 58 # define NOTE_B1 62 # define NOTE_C2 65 # define NOTE_CS2 69 # define NOTE_D2 73 # define NOTE_DS2 78 # define NOTE_E2 82 # define NOTE_F2 87 # de

Mini Oscilloscope via Arduino Nano

What is an oscilloscope?   An  oscilloscope , formerly known as an oscillograph, is an instrument that graphically displays electrical signals and shows how those signals change over time. It measures these signals by connecting with a sensor, which is a device that creates an electrical signal in response to physical stimuli like sound, light, and heat. For instance, a microphone is a sensor that converts sound into an electrical signal. Oscilloscopes are often used when designing, manufacturing, or repairing electronic equipment. Engineers use an oscilloscope to measure electrical phenomena and solve measurement challenges quickly and accurately to verify their designs or confirm that a sensor is working properly. Scientists, engineers, physicists, repair technicians, and educators use oscilloscopes to see signals change over time. An automotive engineer might use an oscilloscope to correlate analog data from sensors with serial data from the engine control unit. Meanwhile, a medical

Fade an LED

  Fade This example demonstrates the use of the  analogWrite()  function in fading an LED off and on. AnalogWrite uses  pulse width modulation (PWM) , turning a digital pin on and off very quickly with different ratio between on and off, to create a fading effect. Hardware Required Arduino board LED 220 ohm resistor hook-up wires Circuit Diagram Code int led = 9 ;           // the PWM pin the LED is attached to int brightness = 0 ;    // how bright the LED is int fadeAmount = 5 ;    // how many points to fade the LED by // the setup routine runs once when you press reset: void setup () {   // declare pin 9 to be an output:   pinMode (led, OUTPUT); } // the loop routine runs over and over again forever: void loop () {   // set the brightness of pin 9:   analogWrite (led, brightness);   // change the brightness for next time through the loop:   brightness = brightness + fadeAmount;   // reverse the direction of the fading at the ends of the fade:   if (brightness <= 0 || bri

Fire Alarm with arduino

Flame Sensor A  flame detector  is a sensor designed to detect and respond to the presence of a flame or fire. Responses to a detected flame depend on the installation but can include sounding an alarm, deactivating a fuel line (such as a propane or a natural gas line), and activating a fire suppression system. The IR Flame sensor used in this project is shown below, these sensors are also called  Fire sensor modules  or  flame detector sensors  sometimes. There are different types of flame detection methods. Some of them are Ultraviolet detector, near IR array detector, infrared (IR) detector, Infrared thermal cameras, UV/IR detector, etc. When fire burns it emits a small amount of Infra-red light, this light will be received by the Photodiode (IR receiver) on the sensor module. Then we use an Op-Amp to check for a change in voltage across the IR Receiver, so that if a fire is detected the output pin (DO) will give 0V(LOW), and if the is no fire the output pin will be 5V(HIGH). In thi