Skip to content

Instantly share code, notes, and snippets.

@mamdouhmostafa
Last active April 30, 2017 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamdouhmostafa/531bcb81e518f83b662a8e475dfabd32 to your computer and use it in GitHub Desktop.
Save mamdouhmostafa/531bcb81e518f83b662a8e475dfabd32 to your computer and use it in GitHub Desktop.
this code for DHT22(temperature and humidity)sensor and 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