Skip to content

Prepare RaspberryPi as temperature sensor node

Nico Waldispühl edited this page Jul 6, 2015 · 2 revisions

Raspberry Pi with AM2302 sensor

To have a RaspberryPi with the DHT22 / AM2302 temperature sensor prepared as sensor node for the SensorSamplor, you can follow these steps:

Obtain Hardware

You need to obtain:

  • Raspberry Pi board (e.g. the new model B+)
  • Micro SD memory card (e.g. one with 8 GB)
  • USB WiFi adapter (e.g. edimax)
  • AM2302 digital temperature/humidity sensor (incl. wires and stuff)
  • Some USB-cable and power adapter.

Install operating system to memory card

Either buy the memory card with preinstalled OS, or download an image (e.g. Raspbian, from here: http://www.raspberrypi.org/downloads/) and write it to the memory card by yourself.

You can follow this guide: http://www.raspberrypi.org/documentation/installation/installing-images/README.md

Set up the Raspberry Pi

Plug everything in

Then, plug in the memory card, the wifi adapter, the sensor and the power cable. Since your wifi is protected with password, you need to plug the Raspberry Pi into your network with a LAN cable (ethernet) for this time. After having done so, you can turn the power on and it should boot up.

Plug in AM2302 sensor

The AM2302 (http://www.adafruit.com/products/393) sensor is already equipped with cables and stuff. There are three cables going out of it, power, ground, and data. These should be marked on the case of the sensor and thus be identifiable. The Raspberry Pi has an array of communication pins (GPIO): https://www.raspberrypi.org/documentation/usage/gpio/

Connect the power cable to the 3V power pin, the ground cable to the ground pin (no, really?! :D) and the data cable to some GPIO data pin, e.g. the #4.

Connect to it

After some minutes, the Raspberry Pi should have booted up. Given your network supports DHCP, the Pi should have received an IP address for the LAN cable interface and is now visible in your network. You can obtain its IP address by scanning your local network like this (assuming you use the 192.168.1.x network):

$ nmap -sP 192.168.1.0/24

This should give a list of all devices in this subnet, e.g.:

Nmap scan report for 192.168.1.1
Host is up (0.0011s latency).
Nmap scan report for 192.168.1.2
Host is up (0.0071s latency).
Nmap scan report for 192.168.1.5
Host is up (0.00031s latency).
Nmap scan report for 192.168.1.8
Host is up (0.000094s latency).
Nmap scan report for 192.168.1.40

Pick the one which looks most like the new device and try to connect to it via secure shell:

$ ssh pi@192.168.1.40

The initial password is raspberry.

First time configuration

After having logged in, you are asked to run the first-time configuration:

$ sudo raspi-config

You can do some interesting things like resizing the memory card partition to its full size, set the language, or change the password. I'd suggest to do so. After a reboot, you are ready to go!

Install interesting software

We can now do a software update and install useful software. This may take quite some time, so you can get a coffee. First for the update:

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install vim

Configure WiFi

Then we can configure the WiFi dongle. We need to do two things:

Provide access point password

Edit the following file:

$ sudo vim /etc/wpa_supplicant/wpa_supplicant.conf 

Add your network:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="MyWifiAccessPointName"
    scan_ssid=1
    key_mgmt=WPA-PSK
    psk="myWifiPassword"
}

You could then restart the networking service with this command:

$ sudo service networking restart

This certainly disconnects you from the node. You could also just reboot the Pi.

Install the SensorSamplor temperature sensor driver

We need the SensorSamplor source to install the temperature sensor driver.

Clone git repository

$ cd
$ git clone https://github.com/nwaldispuehl/sensor-samplor.git
$ cd sensor-samplor

Install temperature sensor driver

You can compile and install the driver with this command:

$ ./gradlew installDht22Driver

The file libPiDht.so will be created and copied into the /var/lib directory.