Created
November 29, 2017 04:38
-
-
Save elktros/b097a41e67ded4737121d7314f9aeecc to your computer and use it in GitHub Desktop.
Code for interfacing DHT11 Humidity and Temperature Sensor with Arduino.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <LiquidCrystal.h> | |
LiquidCrystal lcd(4, 5, 0, 1, 2, 3); | |
byte degree_symbol[8] = | |
{ | |
0b00111, | |
0b00101, | |
0b00111, | |
0b00000, | |
0b00000, | |
0b00000, | |
0b00000, | |
0b00000 | |
}; | |
int gate=11; | |
volatile unsigned long duration=0; | |
unsigned char i[5]; | |
unsigned int j[40]; | |
unsigned char value=0; | |
unsigned answer=0; | |
int z=0; | |
int b=1; | |
void setup() | |
{ | |
lcd.begin(16, 2); | |
lcd.print("Temp = "); | |
lcd.setCursor(0,1); | |
lcd.print("Humidity = "); | |
lcd.createChar(1, degree_symbol); | |
lcd.setCursor(9,0); | |
lcd.write(1); | |
lcd.print("C"); | |
lcd.setCursor(13,1); | |
lcd.print("%"); | |
} | |
void loop() | |
{ | |
delay(1000); | |
while(1) | |
{ | |
delay(1000); | |
pinMode(gate,OUTPUT); | |
digitalWrite(gate,LOW); | |
delay(20); | |
digitalWrite(gate,HIGH); | |
pinMode(gate,INPUT_PULLUP);//by default it will become high due to internal pull up | |
// delayMicroseconds(40); | |
duration=pulseIn(gate, LOW); | |
if(duration <= 84 && duration >= 72) | |
{ | |
while(1) | |
{ | |
duration=pulseIn(gate, HIGH); | |
if(duration <= 26 && duration >= 20){ | |
value=0;} | |
else if(duration <= 74 && duration >= 65){ | |
value=1;} | |
else if(z==40){ | |
break;} | |
i[z/8]|=value<<(7- (z%8)); | |
j[z]=value; | |
z++; | |
} | |
} | |
answer=i[0]+i[1]+i[2]+i[3]; | |
if(answer==i[4] && answer!=0) | |
{ | |
lcd.setCursor(7,0); | |
lcd.print(i[2]); | |
lcd.setCursor(11,1); | |
lcd.print(i[0]); | |
} | |
z=0; | |
i[0]=i[1]=i[2]=i[3]=i[4]=0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment