Skip to content

Instantly share code, notes, and snippets.

@mamdouhmostafa
Created April 30, 2017 20:53
Show Gist options
  • Save mamdouhmostafa/4d48ca64b59c48d90a24b1bb15c8613f to your computer and use it in GitHub Desktop.
Save mamdouhmostafa/4d48ca64b59c48d90a24b1bb15c8613f to your computer and use it in GitHub Desktop.
this code for sensors DHT22 (temperature and humidity) and for gaz sensor
//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