Ahhh temperature sensing, something so simple yet can be integrated into so many different projects. How about a temperature controlled RGB LED? Or perhaps an Arduino controlled thermostat? Heck, even a full blown weather station! Your imagination is the limit.
There are a few different choices when it comes to temperature sensing such as a completely water proof analog temperature probe to digital sensors. I will be focusing on the DHT11 which is a very affordable (~$1) digital temperature and humidity sensor. Its good for sensing 20% to 80% humidity within 5% accuracy, and 0c to 50c within 2% accuracy, which is more than enough for any indoor projects. If you want something a little more capable and accurate, the DHT22 is another option for digital sensors.
The DHT11 has 4 pins in total as seen above (with 0.1″ spacing – perfect for breadboards). VCC, a Data pin, and Ground. Pin 3 is not used.
Wiring it up is fairly straight forward. Start by connecting VCC on the DHT11 to VCC on your Arduino, and Ground to GND. Next connect the DHT11 data pin to pin 10 on the Arduino. Lastly, we need a 10k (Brown Black Orange) resistor in parallel to the DHT11 connected between the VCC and Data pins. This is our pull up resistor.
Now its just a matter of uploading our sketch and checking the output in the serial monitor
//First we need to include the DHT Library
//Next we define which pin the DHT11 is connected to, in this case its 10
#define sensor 10
//We also need to define the type of sensor were using, which is the DHT11.
//Other options are DHT21, and DHT22 if you are using those sensors
#define sensorType DHT11
//Initialize the DHT sensor using the above variables
DHT dht(sensor, sensorType);
//Start our serial port and dht sensor
//Read the temperature sensor, in celcius
int curTemp = dht.readTemperature();
//Read the humidity, in percentage
int curHumidity = dht.readHumidity();
//Output the information to our serial monitor
Serial.print("°C / Humidity: ");
//Wait for a few moments as the sensor can only update so quickly
Now, with a little heavy breathing on the sensor, we should be able to see it change every few seconds (specifically the humidity… its a little harder to breath temperature changes), but they both will work!