4 Digit 7 Segment Display – Arduino

A 4 digit 7 segment display is used along with DHT11 which will display the sensed temperature. The IC TM1637 is attached beneath the 4 digits 7 segment display, which helps in the utilization of only two wires on the Arduino board. If this IC is not attached to the segment display, then utilization of 12 pins is required on the Arduino board. This will not allow us to add any further sensors with the display as there will be no pins left to attach the sensor over the board.

4 Digit 7 Segment Display with Arduino

Pin Configuration

4 digit 7 segment display

GND
Vcc
DIO
CLK

DHT11

GND
Vcc
Signal Pin

Arduino UNO

GND
5v
Digital pin 4
Digital pin 3

Arduino UNO

GND
5v
Digital pin 5

Schematics for 4 digit 7 Segment Display

The schematics is as follows, interfacing 4 digit 7 segment display along with DHT11 and Arduino UNO. 

4 digit 7 segment Display Circuit

Installing Library for 4 Digit Seven Segment Display

Download Arduino IDE first. On your Arduino IDE go to tools, then under tools find manage libraries and click it. Then search for TM1637 and install the TM1637 library by Avishay Orpaz. Once the library is installed, add the code below to your arduino IDE.

Code

				
					// Include the libraries
#include <TM1637Display.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>

// Define the connections pins
#define CLK 3
#define DIO 4
#define DHTPIN 5

// Create variable
int temperature_celsius;
int temperature_fahrenheit;

// Create °C symbol
const uint8_t celsius[] = {
  SEG_A | SEG_B | SEG_F | SEG_G,  // Circle
  SEG_A | SEG_D | SEG_E | SEG_F   // C
};

// Create °F symbol
const uint8_t fahrenheit[] = {
  SEG_A | SEG_B | SEG_F | SEG_G,  // Circle
  SEG_A | SEG_E | SEG_F | SEG_G   // F
};

// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11 

// Create display object of type TM1637Display
TM1637Display display = TM1637Display(CLK, DIO);

// Create dht object of type DHT:
DHT dht = DHT(DHTPIN, DHTTYPE);

void setup() {
  // Set the display brightness (0-7)
  display.setBrightness(5);
  
  // Clear the display
  display.clear();
  
  // Setup sensor
  dht.begin();
}

void loop() {
  // Read the temperature as Celsius and Fahrenheit
  temperature_celsius = dht.readTemperature();
  temperature_fahrenheit = dht.readTemperature(true);

  // Display the temperature in celsius format
  display.showNumberDec(temperature_celsius, false, 2, 0);
  display.setSegments(celsius, 2, 2);
  delay(1000);

  // Display the temperature in fahrenheit format
  display.showNumberDec(temperature_fahrenheit, false, 2, 0);
  display.setSegments(fahrenheit, 2, 2);
  delay(1000);
}
				
			

Conclusion

Temperature will be displayed on 4 digit 7 segment display with an update in temperature after every 1 second.

Leave a Reply

Your email address will not be published.