DHT22 Humidity Sensor with OLED Display for Arduino

DHT22

See The blog using an Si7021 here.
See the blog using a DHT11 here.

The sketch for this project on my GitHub page here.

This is the third in a series of Humidity/Temperature sensors for the Arduino and using an OLED Display. The DHT22 is more accurate than the DHT11, has a wider humidity range and can measure negative temperatures.

There is an in depth discussion of humidity sensors sensors here and the relative accuracy of different sensors as well as methods used to test them is shown. There are a number of libraries available for using this sensor with an Arduino, but I found the one used in the Arduino Playground and available on GitHub here to work well and is the one I have used.

The OLED Display shows temperature in both Centigrade and Fahenheit as well as Humidity in percent and Dew Point in centigrade. I have used the U8Glib library for the OLED Display and the code uses much of the code used for the Si7021 project.

Connect the OLED AS follows, taking care to connect the power supply to the display correctly, Vcc to 5 volts and Gnd to Gnd, as reversing the power will destroy the display. Connect SDA to Arduino pin A4 and SCL to Arduino pin A5. Connect Vcc on the DHT22 to Arduino 5volts, the Gnd to Arduino Gnd. Connect the Data Out on the DHT22 to Arduino pin 2.

Upload the sketch and the display should be as shown in the picture at the top of this page. The reading is updated every 2 seconds as this is the fastest recommended for this sensor.

Comparison with the Si7021

The first obvious difference is size, the Si7021 is a fraction of the size of the DHT22. The DHT22 can only be read once in 2 seconds, but the Si7021 seems to have no such restrictions. Although the Si7021 is about three times more expensive than the DHT22 on eBay, it is about the same cost as the DHT22. Without a doubt the Si7021 wins hands down and the extra accuracy provided makes it the sensor of choice, even though it is more expensive.

Advertisements

DHT 11 Humidity Sensor with OLED Display

 

See the blog using the Si7021 here.
See the blog using the DHT22 here.

The sketch for this project on my GitHub page here.

I wanted to see how the DHT11 compared with the Si7021 Humidity Sensor. As I already had the circuit set up for the Si7021 it did not take long to modify it for use with the DHT11.

There is an in depth discussion of humidity sensors here and the relative accuracy of different sensors as well as methods used to test them is shown. There are a number of libraries available for using this sensor with an Arduino, but I found the one used in the Arduino Playground and available on GitHub here to work well and is the one I have used.

The author of the library included a method to calculate Dew Point, using Humidity and Temperature, and I have included this in my sketch.

The OLED Display shows temperature in both Centigrade and Fahenheit as well as Humidity in percent and Dew Point in centigrade. I have used the U8Glib library for the OLED Display and the code uses much of the code used for the Si7021 project.

Connect the OLED AS follows, taking care to connect the power supply to the display correctly,  Vcc to 5 volts and Gnd to Gnd, as reversing the power will destroy the display. Connect SDA to Arduino pin A4 and SCL to Arduino pin A5. Connect Vcc on the DHT11 to Arduino 5volts, the Gnd to Arduino Gnd. Connect the Data Out on the DHT11 to Arduino pin 2.

Upload the sketch and the display should be as shown in the picture at the top of this page, the output is also sent to the Serial Monitor to help with debugging. The reading is updated every 2 seconds as this is the fastest recommended for this sensor.

Comparison with the Si7021

The first obvious difference is size, the Si7021 is a fraction of the size of the DHT11. The DHT11 can only be read once in 2 seconds, but the Si7021 seems to have no such restrictions. Although the Si7021 is about three times more expensive than the DHT11 on eBay, it is about the same cost as the DHT22. Without a doubt the Si7021 wins hands down and the extra accuracy provided makes it the sensor of choice, even though it is more expensive.

Si7021 High Accuracy Humidity and Temperature Sensor.

See the blog post for the DHT22 here.
See the blog post for the DHT11 here.

The sketch can be found at my GitHub page here.

The Si7021 device is one of Silicon Labs’ latest generation I2C relative humidity and temperature sensors. This device combines fully factory-calibrated humidity and temperature sensor elements with an analog to digital converter, signal processing and an I2C host interface. The device is tiny, especially when compared to the standard DHT11 or DHT22 normally used with the Arduino for humidity sensing. The device needs a maximum of 3 volts to power it and so cannot be directly connected to an Arduino.

The breakout board that I purchased had a 3.3 volt regulator to power the Si7021, but I suspect that there was no level shifting for the I2C connections so I used a level shifter for SDA and SCL just in case.

I found a library here and the humidity and temperature can be easily read with a single command. I decided to use an OLED to display both humidity and temperature.

Take great care when connecting the OLED as reversing the power connections will burn it out. Connect Vcc to Arduino 5 volts, Gnd to Arduino Gnd. Connect SDA to Arduino pin A4 and SCL to Arduino A5. The Si7021 board has four connections, connect Vcc to Arduino 5volts and Gnd to Arduino Gnd. I used a Logic Level converter like this one on eBay here.

Although the Si7021 is more expensive than the DHT11 and DHT22 it is far superior. It is smaller, easier to us and very fast and will certainly be my choice for Humidity sensor in the future.

MAX6675 Thermocouple with OLED Display

image

The code for this project can be downloaded from my GitHub page here.

In an earlier Blog I here used a MAX6675 Thermocouple board and used the Serial Monitor to display the results. I have now connected the board to an OLED display.

The output from the MAX6675 is very erratic (at least in my case) and to get a reasonably stable reading I read the output from the thermometer twenty five times to give an average reading. This slows down the screen update, but does not interfere with the thermocouple response. So, for example, put the probe into a hot cup of coffee and the display will jump in a number of steps to the final reading. This has not proved to be a problem in practice.

The OLED display is connected to 5 volts, Ground and SDA is connected Arduino pin A4 (on a UNO) with SCL connected to Arduino pin A5 (on a UNO). I have used the library from Adafruit for the MAX6675 and if pin2 and 3 are set as OUTPUTS they can be used to supply power to the MAX6675 and the board can be simply be plugged into header pins 2 to 6. Check that the connections on your board match the pins in the Sketch.

In particular check the OLED connections, I have had a number of these with various pin connections making it impossible to swap displays without changing the wiring. I have destroyed three displays this week by not paying enough attention. Reversing the power supplies kills the display immediately.

The MAX6675 library can be downloaded from the Adafruit GitHub here.

This thermometer can display in either Centigrade or Fahrenheit, a variable at the head of the code centigrade, if set to true will display temperature values in Centigrade. If set to false, values in Fahrenheit will be displayed. The line of code to change is


boolean centigrade = true; // set to false for readings in Fahrenheit

The maximum temperature reached is shown on the top left and the minimum temperature is shown on the top right.

MQ3 Gas Detector for Ethanol

  
The MQ3 is one of a series of gas detectors and is sensitive to alcohol (ethanol). The same sketch used for the MQ2 can be used and for a discussion on theses gas sensors see my post here.

When placed over a half full glass of wine it gave a reading around 200 and when placed over a small amount of whiskey a reading of around 450 was obtained. This reading over whiskey triggered the digital output.


/* GAS Sensor MQ-3
This sensor detects flammable gasses
the board has four pins
connect AO to Arduino pin A0
connect DO to Arduino pin 2
connect Gnd to Arduino Gnd
connect Vcc to Arduino 5 volts
*/
int sensorPin = A0; // select the input pin for the potentiometer
int DOPin = 2; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

int ledPin =13;
void setup() {

// declare the ledPin as an OUTPUT:
pinMode(DOPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
Serial.print("Analog Output = ");
Serial.println(sensorValue);
// turn the ledPin on if triggered
//
if (digitalRead(DOPin) ==HIGH){
digitalWrite(ledPin, LOW);
Serial.println("Digital Output = OFF");
}
else {
digitalWrite(ledPin, HIGH);
Serial.println("Digital Output = ON");
}
delay(1000);
}