Arduino Sensor Node

More sensor types, code improvements, and how to add everything in OpenHAB

On this page

The Sensors

There's more to life than temperature sensors. On this page you'll find how to poll the following hardware and how to set everything up in OpenHAB:

  • Temperature & humidity (DHT22 from the main project)
  • A photoresistor to measure light intensity (this one came with the Arduino Starter Kit)
  • A motion sensor (also known as PIR)
  • Door open/closed (reed switch)
  • And we'll use an Arduino Micro because it fits on a breadboard and can be powered with a USB micro charger, which most people have lying around for their phones and tablets

SensorNode front view
Four sensors connected to an Arduino Micro, plus an nRF24l01 module.

We'll also improve the hasender code from the main project and add some new concepts:

  • Support multiple sensors
  • Only send data when there are significant changes
  • Use an internal pull-up resistor for the door switch
  • Use constrain and map to convert the number reported by the light sensor to a percentage
  • Better file name :-)


For the DHT22 sensor, see the main project: left-most pin to 5V; second pin to D2 and also to 5V via a 10k resistor; right-most pin to Ground.

With the light sensor, connect one leg to 5V and the other to an analog pin (eg. A3). Also connect it to Ground with a 10k (pulldown) resistor.

The PIR sensor has 3 legs that should be labeled: connect VCC to 5V, GND to Ground, and Out to a digital pin (eg. pin 9)

And finally the door sensor has 1 wire to Ground and 1 wire to a digital pin (eg. 13)

The nRF24l01 is wired similarly as in the main project. If you're using the Arduino Micro then you'll notice it has specific pins for SCK, MISO & MOSI. So connect SCK to SCK, MISO to MISO and MOSI to MOSI instead of to D11-13.

SensorNode top view
Here's a top view picture that might help and/or confuse you more.

Code Improvements

The code for the Arduino can be downloaded here or you can use the codebender plugin below to send it directly to your Arduino.

There are comments throughout the code to explain what's going on. Also remember to check the variables declared at the top and change them if you use different pins.

Go Back

MQTT Controller