Arduino temperature sensor

#include "DHT.h"
#define DHTPIN 2 // what pin we're connected to

int led = 13;
int pinAlerta = 10;
unsigned counter;

#define DHTTYPE DHT11 // DHT 11

// Connect pin 1 (on the left) of the sensor to +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);
 pinMode(led, OUTPUT);
 pinMode(pinAlerta, OUTPUT);
 dht.begin();
}

void loop() {
 float h = dht.readHumidity();
 float t = dht.readTemperature();
 counter = counter + 1;
 if (isnan(t) || isnan(h)) {
 Serial.println("Failed to read from DHT");
 } else {
 Serial.print(counter);
 Serial.print(";");
 Serial.print(h);
 Serial.print(";");
 Serial.println(t);
 }
 if ( t > 25 ) {
 digitalWrite(pinAlerta, HIGH);
 }
 if ( t < 25 ) {
 digitalWrite(pinAlerta, LOW);
 }
 digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
 delay(1000); // wait for a second
 digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
 delay(1000); // wait for a second
 delay(1800);
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s