Safari browser sometimes has issues displaying images...

I.e: *you have to click on the images to see them...

For a better browsing experience on Brainy-Bits

Please use Chrome, Edge or Firefox browser.

  • Brainy-Bits

Using a 4 bits 7 segment LED display with an Arduino



OVERVIEW


Move away from the Serial Monitor to display values from your sensor by using this simple to use 4 Bits 7 segment LED module.


Thanks to the I2C Bus you can control it using only 2 wires, leaving more pins available on your MicroController to connect other things.


Using Arduino Modules is fast and easy since all the components needed are included on the pcb (resistors, capacitors, etc…).


To make things interesting we will use the DHT11 temperature and humidity sensor to display it’s reading on the Digital Tube Display.

PARTS USED

4 Digits 7 Segment Display

Amazon usa

Amazon canada


Arduino UNO

Amazon usa

Amazon canada


DHT-11 Temperature Sensor

Amazon usa

Amazon canada


These are Amazon affiliate links...

They don't cost you anything and it helps me keep the lights on

if you buy something on Amazon. Thank you!

CONNECTIONS




As mentioned before, since the Digital tube display uses the I2C Bus, we only need 2 connections.


The DHT11 uses only 1 pin.


Both module need 5v and Ground to operate, so we are using the breadboard to use it’s VCC and Ground Rails.


THE CODE


The code will make use of 2 libraries, one for the DHT11 and the other for the Display.


Download both of these and extract them to your Library folder, then restart your IDE software.

The code below assumes that the data received for the Temperature and the Humidity will always have 2 digits.

If you want to experiment you could modify the code with some IF statements if those values have more than 2 digits or add a minus sign for negative temperature values.


Example : -19 degrees Celsius or over 100 degrees.


As always you can have a look at the tutorial video for more information.


#include "dht.h"
#include "TM1637.h"

//{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
//0~9,A,b,C,d,E,F
 

 
#define dht_pin 2 // Pin sensor is connected to
#define CLK 3//Pins for TM1637       
#define DIO 4
 
TM1637 tm1637(CLK,DIO);
dht DHT;
 

void setup(){
  
  tm1637.init();
  tm1637.set(BRIGHT_TYPICAL); 
  //BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
 
  delay(1500);//Delay to let system boot

 
}//end "setup()"
 

 
void loop(){
 
  //Start of Program 
 
  DHT.read11(dht_pin);
 

 int temp = DHT.temperature;
 int humidity = DHT.humidity;
 
 int digitoneT = temp / 10;
 int digittwoT = temp % 10;
 
 int digitoneH = humidity / 10;
 int digittwoH = humidity % 10;
  

    tm1637.display(1,digitoneT); 
    tm1637.display(2,digittwoT);
    tm1637.display(3,12);  // put a C at the end
    
    delay (3000);
    
    tm1637.display(1,23); 
    tm1637.display(2,digitoneH); 
    tm1637.display(3,digittwoH);

    
  //Wait 3 seconds before accessing sensor again.
 
  //Fastest should be once every two seconds.
    delay(3000);
 
}// end loop() 


TUTORIAL VIDEO




DOWNLOAD


Copy and paste the above code in the Arduino IDE to program your Arduino.


Used Libraries:

Download the DHT11 library created by RobTillaart:  https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTlib


Download the TM1637 library created by Frankie.Chu here:  https://github.com/reeedstudio/libraries/tree/master/DigitalTube  

41 views

All my content is and will always be Free.

If you feel that my Videos / Tutorials are helping, and you would like to contribute...

 You can toss some coins in the Tip Jar via PayPal.

Select amount then click the “Donate” button.

©2020 by Brainy-Bits