Temperature and Humidity Display using Arduino

This is a working device i made which displays temperature or humidity respectively by pressing a push button switch. If the switch is pressed it displays humidity otherwise it displays temperature.

This device incorporates seven segment displays as output for the value of temperature and humidity to be displayed.
The two seven segment displays works on the principle of multiplexing which saves a lot of I/O pins on Arduino and a lot of coding time.
There is also a switch to choose if you want to view temperature or humidity according to your choice.

Step 1: Items required

The items required are :-
1. 2 X 7 Segment Displays (COMMON ANODE)
2. 1 X PUSH BUTTON SWITCH
3. 1 X DHT11 Humidity And Temperature Sensor
4. 1 X ARDUINO (UNO,Mega,Nano etc.)
5.1 X Perfboard/BreadBoard

Step 2: Circuit Diagram

Step 3: CODE

Upload the code given to your Arduino and your device should work.
If any problems persists please message me or comment below.


#include <dht.h>
dht DHT;
int choice=0;
int dhtpin = A0;
int pin1 = 2;
int pin2 = 3;                                    //                            --6--
int pin3 = 4;                                    //                         5 |     | 7
int pin4 = 5;                                    //                           |--4--|
int pin5 = 6;                                    //                         1 |     | 3
int pin6 = 7;                                    //                            --2--
int pin7 = 8;
int gnd1 = 9;                                  // for temperature
int gnd2 = 10;                                 // for temperature 
const int pixellength = 100;                                

int pinstringA[11] = {                                     
  LOW,HIGH,LOW,LOW,HIGH,LOW,LOW,LOW,LOW,LOW};         
int pinstringB[11] = {                                      
  LOW,LOW,LOW,LOW,LOW,HIGH,HIGH,LOW,LOW,LOW};
int pinstringC[11] = {
  LOW,LOW,HIGH,LOW,LOW,LOW,LOW,LOW,LOW,LOW};
int pinstringD[11] = {
  LOW,HIGH,LOW,LOW,HIGH,LOW,LOW,HIGH,LOW,LOW};
int pinstringE[11] = {
  LOW,HIGH,LOW,HIGH,HIGH,HIGH,LOW,HIGH,LOW,HIGH};
int pinstringF[11] = {                                       
  LOW,HIGH,HIGH,HIGH,LOW,LOW,LOW,HIGH,LOW,LOW};            
int pinstringG[11] = {
  HIGH,HIGH,LOW,LOW,LOW,LOW,LOW,LOW,LOW,LOW};

void setup(){
  for(byte i=2; i<12; i++){                                  
    pinMode(i,OUTPUT);
  }
  pinMode(11,INPUT);
  Serial.begin(9600);
}


void loop(){
  DHT.read11(dhtpin);     //reading values
  choice=digitalRead(11);
  
  if(choice==1){
  int y=DHT.humidity;
  byte tensh;
  byte onesh;
  tensh = y / 10;
  onesh = y % 10;  
  
  for(int j = 0; j < pixellength; j++){                     
    digitalWrite(gnd1,HIGH);
    digitalWrite(gnd2,LOW); 
    digitalWrite(pin1, pinstringE[tensh]);
    digitalWrite(pin2, pinstringD[tensh]);    
    digitalWrite(pin3, pinstringC[tensh]);
    digitalWrite(pin4, pinstringB[tensh]);
    digitalWrite(pin5, pinstringA[tensh]);
    digitalWrite(pin6, pinstringF[tensh]);                    
    digitalWrite(pin7, pinstringG[tensh]); 
    delay(10);                                         
     PORTD = PORTD & B00000011;                       
    digitalWrite(gnd1,LOW);
    digitalWrite(gnd2,HIGH);
    digitalWrite(pin1, pinstringE[onesh]);
    digitalWrite(pin2, pinstringD[onesh]);    
    digitalWrite(pin3, pinstringC[onesh]);
    digitalWrite(pin4, pinstringB[onesh]);
    digitalWrite(pin5, pinstringA[onesh]);
    digitalWrite(pin6, pinstringF[onesh]);    
    digitalWrite(pin7, pinstringG[onesh]);
    delay(10);                                
     PORTD = PORTD & B00000011;              
  }
  }
  
  else{
    int x=DHT.temperature;
     Serial.println(x); 
  byte tens;
  byte ones;
  tens = x / 10;
  ones = x % 10;  
    
  for(int j = 0; j < pixellength; j++)
  {
    digitalWrite(gnd1,HIGH);
    digitalWrite(gnd2,LOW);
    
    digitalWrite(pin1, pinstringE[tens]);
    digitalWrite(pin2, pinstringD[tens]);    
    digitalWrite(pin3, pinstringC[tens]);
    digitalWrite(pin4, pinstringB[tens]);
    digitalWrite(pin5, pinstringA[tens]);
    digitalWrite(pin6, pinstringF[tens]);                    
    digitalWrite(pin7, pinstringG[tens]); 
    delay(10);
    PORTD = PORTD & B00000011;
    digitalWrite(gnd1,LOW);
    digitalWrite(gnd2,HIGH);
    digitalWrite(pin1, pinstringE[ones]);
    digitalWrite(pin2, pinstringD[ones]);    
    digitalWrite(pin3, pinstringC[ones]);
    digitalWrite(pin4, pinstringB[ones]);
    digitalWrite(pin5, pinstringA[ones]);
    digitalWrite(pin6, pinstringF[ones]);    
    digitalWrite(pin7, pinstringG[ones]);


    delay(10);
    PORTD = PORTD & B00000011;
  }  
}
  }

Final Step: Finished


Previous
Next Post »

1 comments:

Click here for comments
darren sammy
admin
Thursday, 27 October 2016 at 15:03:00 GMT+1 ×

I just couldn't leave your site before letting you know that I really appreciated the top quality information you present to your guests? Will be back again as often as possible to determine the status of new posts. Humidity Chamber

Congrats bro darren sammy you got PERTAMAX...! hehehehe...
Reply
avatar
3IG