Raspberry PI DHT22 humidity sensor with a LCD 16×2 display – Weather station

For a workshop I’m going to give about Raspberry PI and how to interact with the outside world, I thought for a start, why not something simple like some kind of a Weather Station.

Materials

1x Raspberry PI (I’m using b+)

1x LCD 16×2

1x DHT22 (or DHT11 or am2303) sensor

1x 10K potentiometer

1x 10K resistor

1x breadboard

Here’s the schematic in Fritzing

Weather_AICB

 

Connections

Sensor Arduino PINs
LCD display Board BCM
1 GND
2 5v
3 Potentiometer
4 7 GPIO27
5 GND
6 9 GPIO22
7
8
9
10
11 22 GPIO25
12 18 GPIO24
13 16 GPIO23
14 12 GPIO18
15 5v
16 7 GPIO4
DHT22
8  GPIO14
 GND
5v

After the wiring, time to connect the PI

Note: Using this wiring and the Adafruit’s LCD libraries, the LCD display will not light up when connecting the PI. After testing the example and running the python script, the LCD will light up and start displaying information

Software

DHT

dht22

For the sensor to work, we need the DHT libraries developed by Adafruit and setup the environment.

NOTE: As stated by Adafruit, this driver is work in progress

First, set up your development environment

Now, clone the Adafruit libraries

After cloned, enter the directory

Install the libraries

Everything now should be installed. Let’s try the sensor

Now, execute the test file without arguments to see the options available

We’re using DHT22 and connected to the GPIO PIN 4, so, our command line will be:

And the result:

LCD 16×2

LCD

With this method, we’re not going to use i2c or UART, but Adafruit’s libraries for LCD. They are easy to install and easy to work with.

Note: If you just want to connect the LCD, refere to this post.

Install the necessary packages

Upgrade distribute

Use PIP to install the GPIO packages

Install the necessary software modules

Try with an example

Now, you can see information on the LCD display

If you want to check the API of the LCD Adafruit’s Python Library:

 

The Code

The final product

Weather2

References

https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/

https://learn.adafruit.com/character-lcd-with-raspberry-pi-or-beaglebone-black/overview

Leave a Reply

Your email address will not be published. Required fields are marked *