Last active
April 30, 2017 21:03
-
-
Save mamdouhmostafa/531bcb81e518f83b662a8e475dfabd32 to your computer and use it in GitHub Desktop.
this code for DHT22(temperature and humidity)sensor and Gaz sensor
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
//Libraries | |
#include <DHT.h> | |
//Constants | |
#define DHTPIN 2 // what pin we're connected to | |
#define DHTTYPE DHT22 // DHT 22 (AM2302) | |
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino | |
//Variables | |
int chk; | |
float hum; //Stores humidity value | |
float temp; //Stores temperature value | |
const int gasPin = A0; //GAS sensor output pin to Arduino analog A0 pin | |
void setup() | |
{ | |
Serial.begin(9600); //Initialize serial port - 9600 bps | |
dht.begin(); | |
} | |
void loop() | |
{ | |
Serial.println(analogRead(gasPin)); | |
delay(1000); // Print value every 1 sec. | |
//Read data and store it to variables hum and temp | |
hum = dht.readHumidity(); | |
temp= dht.readTemperature(); | |
//Print temp and humidity values to serial monitor | |
Serial.print("Humidity: "); | |
Serial.print(hum); | |
Serial.print(" %, Temp: "); | |
Serial.print(temp); | |
Serial.println(" Celsius"); | |
delay(2000); //Delay 2 sec. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment