Raspberry Pi, Arduino, Sensors and the data they produce

Category Archives: Sensors

A Shift in Tools – The 8266 and the Arduino IDE

Well winter came around, and time in the workshop got shortened, so I got back to the electronics and computers in the nice warm house.  I was still struggling with both range and setup of the NRF24L01+ with the Arduino.  It just seemed too complex and getting the sensor power down to a usable level required dropping components.

I was looking around the web for ideas, and I got distracted by a little OLed / 8266 Weather device.  Well, it was available on Amazon Prime and I was stuck on the problem at hand, so I placed my order, and two days later this device showed up at my door.   Note: I am not an agent for Amazon, I just think this is a great little project!


When you purchase this unit, the developer / blogger gives you a great tutorial PDF link that you can download and build from.  He has a great blog site too, so give it a read:


Now, because of the tutorial, I was able to get this item up and running in just a short time, and it opened my eyes to a new device, while delivering a good product!  IN fact, I immediately went back to Amazon, and ordered a couple more of the NodeMCU / 8266 prototyping boards.  Then I dove off the deep end with out my floaties!

You know how Google, Bing or Duck Duck go searching happens, and then you surface a few hours later?  That happened.

What I found was a huge eco-structure around this 8266 chip.  There were two directions that this led me, and that cost several more hours.  Maybe this post will help you if you get started down this same path.

Direction One is what I went with due to the Squix path, which goes the route of modifying the Arduino IDE which I think you are probably familiar with if you are reading this blog and following any of the experiments I have previously presented.

In short you add libraries into the IDE that allows reprogramming of the NodeMCU.

WARNING: I DO NOT YET KNOW HOW TO RETURN THE CHIP TO IT”S ORIGINAL PROGRAMMING – So I will take no responsibility if you follow this path and re-program with the Arduino IDE and any code presented here.

Direction Two:

This is the original effort and most of the NodeMCU chips come pre-programmed with this code/environment. It is called NodeMCU/Lua.  Lua is a programming language that you can do further searches to get more details on. While I like this environment, I think I have not dug into it far enough to get a real feel for this approach.

That explanation completed, I learned the IDE modification while making my little weather station.  In the same tutorial, it was mentioned that to go beyond the simple receipt of weather info from use of the wunderground API, you would need an external sensor.  Well, I did have a couple extra NodeMCU’s to play with so off I went.  The really cool thing here was that there was code ready built if you chose to take this challenge.  And it was easy, since in the prior posts we experimented with PIR sensors and DHT-11 temp/humidity sensors, I had the needed parts already.  Not to mention the 500 or so jumper wires in my parts bin.

Then build again was quite simple, and I quickly had the nodeMCU programmed.  Now the operation strayed a bit, and I needed to set up an account on Thingspeak.  Thingspeak is an on-line cloud service that offers a free section, and some analytic tools that are pretty cool. It has ties to MATLAB, so they definitely want you to grow your data and find you way onto a paying service, it all depends on volume.  I went ahead and signed up, so I could “see” the data coming out of my little oLed.  You set an API key here, and put that in your programming code so your little device can transmit it out to the cloud, then the weather display can go get that same data and bring it back down.


THis was great, I was able to build both parts of this, get an oLed displaying the weather, and the authors code displayed my local sensors temp/humidity from two place in my house, how cool is that, right?

Okay, so in all of this writing, I forgot something. Some. Thing. BIG.

Why did this little device grab my attention in the first place:  It has wifi on board, similar to the nrf24L01+.  But this was so much easier! Why you ask, because of this little snnipet of code:

#include <ESP8266WiFi.h>
#include TheDudeParams.h // Change this file params
const char* ssid = MY_SSID;
const char* password = MY_PWD;
const char* host = MY_HOST;
const char* hostIP = MY_HOSTIP;
String url = /getIP.php?psswd=;
WiFiServer server(80);

So why does this excite me so?  Simple:  You can use your existing wifi to send the data across, and that really plays into my GRAND DESIGN of having everything  I want on my sensor network.  Woot!

But then I crashed again.  I really did not want to have to depend on a cloud service to send my data to, and if I got as many sensors as I dream  up built, I might have to pay for the service, and that was not what I wanted. I also considered what if the cloud server was off-line, or worse, went away completely?

Now I had to go and learn more,  if these devices could send data across my wifi,  there must be ways to work with that data separately from the cloud (note: I still have a few devices sending to the cloud.)

Well, back to the internet, back to searching and searching and searching.  IN my next post I’ll get into the tools and techniques  I found, and what I did with that info.  Stay tuned for more.



A Python Zone Sentry Program


This post presents ZoneSentry.py. As the name implies it is a sentry application that uses a Passive Infrared (PIR) sensor in the same manner as the PIRLEDeMail.py program does. ZoneSentry.py is a total rewrite and renders PIRLEDeMail.py obsolete.
Read more of this post

Attaching a Samba Share at Startup / fstab

Working through the efforts to install my Raspberry Pi (RPi) with camera and  pi-timolo, I ran across a problem getting attached to the SAMBA share on the PiNAS, before the application starts up and then tries to send pictures to the share.  Remember that the base instructions show how to set the program to start on boot (  init.d & update-rc.d setup ), but I was finding I had a failure to write due to the fact that the NAS share was not in my mounted devices list.

Read more of this post

PIR Based Raspberry Pi Camera and Programming

One of our group is a very experienced programmer, (we have all programmed to an extent) and has come to love the Raspberry Pi (RPi) along with the rest of us.  Although his first taste of python was not well received, he has become somewhat of a fan (well that might be stretching it).  In his endeavor to reach new levels of programming proficiency as well as become more familiar with the hardware aspects of the RPi, he chose to write from scratch a program to automate the use of a PiCamera, along with accessing the GPIO ports of the RPi.  While he was at it he chose to add an LED indicator to show when movement was detected.
Read more of this post

A Python sensor program for Raspberry Pi


This page presents a Python program that is designed to be a proximity sensor operating on a local network using WIFI. This sensor employs a Passive Infrared sensor (PIR), an LED to give a visual indication that movement has been detected by the PIR, a Picamera and the program presented here.

When the program, PIRLEDeMail.py detects movement, it will turn on the green LED, take a photo using the camera and then send an email with the jpg file attached to the intended recipient.
Read more of this post

openHAB Rules

When we last visited, I gave you a quick view of the details of the openHAB installation process for the Raspberry Pi, and we started configuration of the environment, but left when we got to the rules.  Rules are how openHAB lets you know about sensor data.  While there are lots of options here, let’s keep this look simple and stick to a simple sensor, the DHT11/DHT22 as built from the MySensors.org web site.

To begin, if you are where we left off – good. If not, you will need to be in the configurations directory, under /opt/openhab.

Now, you will need to make some entries.  I copied this from the mysensors.org forum, from user TimO:

cd rules
sudo nano demo.rules

Demo Rules – demo.rules

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.joda.time.*
import java.util.*
import org.eclipse.xtext.xbase.lib.*
import org.openhab.core.items.*

String ArduinoUpdate = “”
var String sketchName = “”

var int V_TEMP = 0
var int V_HUM = 1
var int V_LIGHT = 2
var int V_DIMMER = 3
var int V_PRESSURE = 4
var int V_FORECAST = 5
var int V_RAIN = 6
var int V_RAINRATE = 7
var int V_WIND = 8
var int V_GUST = 9
var int V_DIRECTION = 10
var int V_UV = 11
var int V_WEIGHT = 12
var int V_DISTANCE = 13
var int V_IMPEDANCE = 14
var int V_ARMED = 15
var int V_TRIPPED = 16
var int V_WATT = 17
var int V_KWH = 18
var int V_SCENE_ON = 19
var int V_SCENE_OFF = 20
var int V_HEATER = 21
var int V_HEATER_SW = 22
var int V_LIGHT_LEVEL = 23
var int V_VAR1 = 24
var int V_VAR2 = 25
var int V_VAR3 = 26
var int V_VAR4 = 27
var int V_VAR5 = 28
var int V_UP = 29
var int V_DOWN = 30
var int V_STOP = 31
var int V_IR_SEND = 32
var int V_IR_RECEIVE = 33
var int V_FLOW = 34
var int V_VOLUME = 35
var int V_LOCK_STATUS = 36
var int V_DUST_LEVEL = 37
var int V_VOLTAGE = 38
var int V_CURRENT = 39
var int msgPresentation = 0
var int msgSet = 1
var int msgReq = 2
var int msgInternal = 3
var int msgStream = 4
var int alarmArmor = 1

// Internal Commands

var int I_BATTERY_LEVEL = 0
var int I_TIME = 1
var int I_VERSION = 2
var int I_ID_REQUEST = 3
var int I_ID_RESPONSE = 4
var int I_INCLUSION_MODE = 5
var int I_CONFIG = 6
var int I_FIND_PARENT = 7
var int I_LOG_MESSAGE = 9
var int I_CHILDREN = 10
var int I_SKETCH_NAME = 11
var int I_SKETCH_VERSION = 12
var int I_REBOOT = 13
var int I_GATEWAY_READY = 14

// Mappings
var HashMap<String, String> sensorToItemsMap = newLinkedHashMap(
“4;0;” -> “livingHum01”,
“livingHum01” -> “4;0;”,
“4;1;” -> “livingTemp01”,
“livingTemp01” -> “4;1;”

//receiving msg from mysensors gateway
rule “Arduino sends to Openhab”
Item Arduino received update
var String lineBuffer = Arduino.state.toString.split(“\n”)
for (String line : lineBuffer) {
var String[] message = line.split(“;”)
var Integer nodeId = new Integer(message.get(0))
var Integer childId = new Integer(message.get(1))
var Integer msgType = new Integer(message.get(2))
var Integer ack = new Integer(message.get(3))
var Integer subType = new Integer(message.get(4))
var String msg = message.get(5)
if(msgType == 1 ){
if (subType == V_TEMP){
postUpdate(sensorToItemsMap.get( nodeId + “;” + childId + “;”), msg)
println (“Temp item: ” + sensorToItemsMap.get( nodeId + “;” + childId + “;”) + ” temp: ” + msg )
if (subType == V_HUM){
postUpdate(sensorToItemsMap.get( nodeId + “;” + childId + “;”), msg)
println (“Hum item: ” + sensorToItemsMap.get( nodeId + “;” + childId + “;”) + ” hum: ” + msg )
// Internal Command
if(msgType == 3){
if(subType == I_SKETCH_NAME){
println(“Sketch name: ” + msg )
if(subType == I_SKETCH_VERSION){
println(“Sketch version: ” + msg )
postUpdate(sensorToItemsMap.get( nodeId + “;” + childId + “;”), sketchName+” ” +msg )

A note here about the mappings entry above. You will need to modify this for the ID of your sensor. I modofied the mysensors.org code to statically assign the ID of each sensor. You can also let openHAB set these ID’s, which the sensor will store in eeprom. You will have to match those IDs when attempting to display their data, so the above mappting will have to be customized to your environment, or you will not get any data to display.

Now move up a directory, then go to the sitemap directory.
cd ..
cd sitemap

And the final step for the base configuration is to put in what is called the sitemap. This will give you a display that can be read in a web browser.

sudo nano demo.sitemap

Raspberry Pi Gateway -Send-Recieve

sitemap demo label=”My House”
Frame label=”Weather” {
Text item=livingTemp01
Text item=livingHum01

Now start up your environment if it is not running:

Change back to the /opt/openhab directory and run openhab:

sudo ./start.sh

Using either the RPi browser or one from another computer, and call up this :


if you are using a different computer, simply change localhost to the IP address of your RPi.

You should be greeted with this display:

FIrst Screen builtvar

You now have an operational MySensors / openHAB installation!

A Fork in the Sensor Road

As you have seen in the prior posts, our group has been delving into sensors that we can use to secure our homes, as well as provide knowledge about what is happening in the home environment.

To recap the efforts to date:

  1. Created a group of sensors based on the MySensors.org information:
    1. Sound Sensor
    2. Temperature  Sensor
    3. Motion Sensor
  2. Created a Gateway device, to aggregate the sensor data and deliver it to the “controller” product (PiDome, openHAB)

Controller – the GUI-Dashboard  and Data Processing Engine

After some research, the prior post was about PiDome as the Dashboard for a group of sensors we have build based on the MySensors.org site.  One of the guys also had looked at openHAB project, and suggested we also evaluate that application and compare it to the PiDome.

At the end of the last effort, I was struggling to get enough info on the PiDome / MySensors gateway connection, which left me a bit frustrated.  Both parts seemed to work, but ran into trouble with the integration, so I decided to create a parallel environment with openHAB.

Now, I don’t want to disparage PiDome, in fact, I think it is a solid product, and intend to continue to learn about it and build on it, I just need to dig in and get better with it.

So the fork in the road led me to look for information on the openHAB installation on a Raspberry Pi, and I was rewarded with several different methods on installation, and multiple sets of documentation on how people did so (blogs, instructables, etc).

I started with this instructable as a reference:


This got me the demo system on Raspberry Pi, and I was able to do the demo setup and play around with it. I then went looking for details on how to use mysensors units and gateway with openHAB.  A “google” later, and I had a dozen good links to work with.

My next step was to delete the environment, and I  used the rmdir -Rf to wipe out the openHAB directory.

I then followed the installation steps (I will detail these in the next post) to get a much new release installed.  Basically requiring a directory creation, download of two zip files, and then hooking up the sensor “gateway” to the usb port on the Raspberry Pi.

Next, you need to setup the items & rules for the sensors you are monitoring.  A couple links here for reference materials:



All that being said, it is fairly easy, once you know the secrets!

Here are the basics to get you started (assumption you have loaded the demo configuration):

Check out the directory /opt/openhab/configurations

Note the sub-directories, /items & /rules, you will need to make sure they have what we need to get rolling.

TO “bind” the mysensor gateway, openHAB need to know about the device, and how to talk to it. TO do this you bring in the appropriate .jar file, in my case I brought in the entire group of these. I hope that later in the effort I can remove those I do not think are necessary.  so I have deployed the following:


These are all the components that are necessary to get the environment up and running.  Additional details to follow on the configuration needed to get this off the ground, but we can start by updating the demo.items to include a couple of sensors. we label them and give them an ID. Next we update the demo.rules to define the variable names for these items, as well as what to do when an item (sensor) delivers data.

Once that is completed, you start up the server, plug in the arduino gateway, and do some checks to make sure we are “seeing” the gateway, and then receiving the data:

Here is an example:

2015-04-02 20:19:47.057 [INFO ] [runtime.busevents ] Arduino state updated to 0;0;3;0;9;read:1011010s=0,c=1,t=1,pt=7,l=5:44.7 101;0;1;0;1;44.7 2015-04-02 20:19:47.114 [INFO ] [runtime.busevents ] livingHum01 state updated to 44.7 Hum item: livingHum01 hum: 44.7

Finally, you create the Dashboard page that relays the received sensor data to the user by configuring the “sitemap”.

Once this is completed, you can open a browser and see your data. It is running on Port 8080, which is a standard port.


SO that is in a nutshell what it takes to get openHAB up and running.  There is a bit of configuration to do to get a final setup completed, but most of those steps are just repeats of what was outlined above.  The next post will give the nitty-gritty detail of this installation.





Sensor Network –First Deployment

Well, you have to start somewhere, so while this code is neither clean nor fully functional, it does demonstrate the functionality of the effort underway. This code reflect two sensors basically streaming their name and current info, and the receiver RPi scrolling the received info across the screen.

Also my first attempt at putting code in the blog, so we’ll see how it works.

The next code iterations will remove all the screen displays and move to writing a file with the sensor node name and accompanying data from the sensors to a comma deliminated file (.csv).

Arduino based sensors transmitting to the Raspberry Pi via NRF24L01+

This post shows two code blocks, one for any Arduino sensor node and the second is the RPi receiving code.
The Arduino Sensor Node Transmitter -Send-Recieve

#include #include #include // ce,csn pins RF24 radio(9, 10); void setup(void) { while (!Serial); Serial.begin(9600); radio.begin(); radio.setPALevel(RF24_PA_MAX); radio.setChannel(0x76); radio.openWritingPipe(0xF0F0F0F0E1LL); const uint64_t pipe = 0xE8E8F0F0E1LL; radio.openReadingPipe(1, pipe); radio.enableDynamicPayloads(); radio.powerUp(); } void loop(void) { radio.startListening(); Serial.println(“Starting Loop. Radio on.”); char receivedMessage[32] = {0}; if (radio.available()) { radio.read(receivedMessage, sizeof(receivedMessage)); Serial.println(receivedMessage); Serial.println(“Turning off the Radio.”); radio.stopListening(); String stringMessage(receivedMessage); if (stringMessage == “GETSTRING”) { Serial.println(“Looks like they want a string!”); const char text[] = “Hello World!” ; radio.write(text, sizeof(text)); Serial.println(“We sent our message.”); } } delay(1000); }

Raspberry Pi Gateway -Send-Recieve

import RPi.GPIO as GPIO from lib_nrf24 import NRF24 import time import spidev GPIO.setmode(GPIO.BCM) pipes = [[0xE8, 0xE8, 0xF0, 0xF0, 0xE1], [0xF0, 0xF0, 0xF0, 0xF0, 0xE1]] radio = NRF24(GPIO, spidev.SpiDev()) radio.begin(0,17) radio.setPayloadSize(32) radio.setChannel(0x76) radio.setDataRate(NRF24.BR_1MBPS) radio.setPALevel(NRF24.PA_MIN) radio.setAutoAck(True) radio.enableDynamicPayloads() radio.enableAckPayload() radio.openWritingPipe(pipes[0]) radio.openReadingPipe(1, pipes[1]) radio.printDetails() #radio.startListening() message = list(“GETSTRING”) while len(message) 2: print (“Timed out.”) break receivedMessage = [] radio.read(receivedMessage, radio.getDynamicPayloadSize()) print(“Received: {}”.format(receivedMessage)) print(“Translating our received Message into unicode characters…”) string = “” for n in receivedMessage: if (n >= 32 and n <=126): string += chr(n) print(“Our received message decodes to: {}”.format(string)) radio.stopListening() time.sleep(1)

Thermisistors and the Raspberry Pi



It has been a fun week, what with colder weather and less leaves to rake, so I got back to the workbench and have been playing with all sorts of Pi projects. The main one over the past couple of weeks has been a PiBBQ monitor, with three probes. One of my buddies and I found a link, and based on some cheapo probes he had from some single temp. monitors, we started the build. We broke it up after I spent an evening trying to get the software loaded on a pi, and another evening building up the ADC circuit on a adafruit pi prototyping board.

The project site has all the details, and you can visit it here:


Now, I will caution you that when you go to build the software, I did run into some problems, but once I failed, we went back to his github page and read the revised readme doc, realized he had a cleaner set of instructions inside that worked much better than the ones on the blog.

I also was pleased to find that he both published his schematic as well as had created an actual pcb that you could purchase. I was extremely pleased to find that when I ordered the board set (3 boards for 13.75 including free shipping), that the turnaround was under two weeks! The board vendor was oshpark.com, and they were responsive and nice to deal with!!

Our project is not yet done, we are still having a little trouble and working on getting our thermistors calibrated. We have a plan to get that accomplished, and I wanted to mention several interesting pages that we visited to get a better understanding of what we were learning:


. We did find that the prototype board works just like the purchased pcb, so that was gratifying too.  we will do another update once we get the unit operating with calibrated sensors.

Lower Power Sensors

Well, I lied. I said I would write about the MySensor.org Gateway device next, but my groups discussion tonight has been about getting longer output from batteries for sensors.  Several posts in forums have provided lots of options.  One we really liked was manicbug’s solution with custom programmed chips and custom made boards.  This approach really appeals if we can find everything we need, and his total cost per sensor module is about 12.00!!!


You can read his posting with the details on his wordpress site.  maniacbug – low power sensors .

He has posted his board artwork for free, and the studio he used will do ten boards for 10.00!!


More research will have to be done, but for the temp/humidity and PIR boards this may be too good to pass up. He also explains his sleep library to get the longest time from his batteries, good stuff!