Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_Sensor.h>
- #include <DHT.h>
- //#include <DHT_U.h>
- //#include <DHT_U.h>
- #define DHTPIN 2 // what digital pin we're connected to
- #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
- // Connect pin 1 (on the left) of the sensor to +5V
- // NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
- // to 3.3V instead of 5V!
- // Connect pin 2 of the sensor to whatever your DHTPIN is
- // Connect pin 4 (on the right) of the sensor to GROUND
- // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
- DHT dht(DHTPIN, DHTTYPE);
- void setup() {
- Serial.begin(9600);
- Serial.println("DHTxx test!");
- dht.begin();
- }
- int tempsensorValue=0;int compareValue=1022;
- int p=0;int result;
- void loop() {
- // Wait a few seconds between measurements.
- delay(2000);
- // Reading temperature or humidity takes about 250 milliseconds!
- // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
- float h = dht.readHumidity();
- // Read temperature as Celsius (the default)
- float t = dht.readTemperature();
- // Check if any reads failed and exit early (to try again).
- if (isnan(h) || isnan(t) ) {
- Serial.println("Failed to read from DHT sensor!");
- return;
- }
- // Compute heat index in Celsius (isFahreheit = false)
- float hic = dht.computeHeatIndex(t, h, false);
- int sensorValue = analogRead(A0);
- Serial.print(sensorValue);
- if(p!=5){
- result=(result+sensorValue);
- Serial.print(" %\t");
- Serial.print(result);
- }
- if(p==5)
- {
- result=result/p;
- Serial.print(" %\t");
- Serial.print(result);
- if(compareValue-200>result){
- Serial.print(" %\t");
- Serial.print("Rain");
- compareValue=result;
- }
- if(compareValue+50<result){
- Serial.print(" %\t");
- Serial.print("Drying");
- compareValue=result;
- }
- result=1022;
- tempsensorValue=0;
- p=0;
- }
- p++;
- Serial.print(" %\t");
- Serial.print(p);
- Serial.print("Humidity: ");
- Serial.print(h);
- Serial.print(" %\t");
- Serial.print("Temperature: ");
- Serial.print(t);
- Serial.print(" *C ");
- Serial.print(" %\t");
- Serial.print("Heat index: ");
- Serial.print(hic);
- Serial.print(" *C ");
- Serial.print(" %\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement