Home Immobot

homesensor.bas (1751Bytes)
homerecv.bas (1811Bytes)
home.py_.txt (961Bytes)
sensor.py_.txt (3321Bytes)
homesensor.png (122989Bytes)

After having read so many interesting posts on the LMR I wanted to make also my contribution. The present project is not a mobile robot but rather an immobile one, the whole house. In the present stage I am just recording the information and on the final one I want my immobot to act e.g. rasing alarms, notify by emails, close/open shutters even regulate the central heating.

I have built a series of wireless sensors based on PICAXE 08M2 and the TX433 module that records temperature, humidity, light intensity, status of doors, shutters, garage door etc. All the information is collected with a receiver based on the RX433 and PICAXE 14M2 which in turn transmits the information to a RASPBERRY PI computer which acts as a data logger and the web interface.

Sensor module:

Sensor.jpg

I’ve tried to minimize the cost of each sensor as well the battery consumption. Each sensor has a unique ID (defined in the program) and it enters in the main loop which does the following (see: homesensor.bas and the PCB layout)

  1. Sleep for a random period of time up to two minutes. I am using random period in order to avoid interference patterns between sensors. Trying to avoid overlaps of various sensors waking up the same time.
  2. On wake up it powers the sensors via a BC547 transistor by setting the relative pin to high, and read their values. Two ADC channels and two buttons and calculates a checksum on the values.
  3. If the checksum of the last reading is different than the previous one then transmit the data. Just for security it transmits the data also after 5 readings anyway.
  4. To transmit the data, it sends first a repetitive pattern of 101010 bits to wake up the receiver and then try 5 times with the data package. The data are preceeded by a header “HNET”, followed by the raw sensor readings and the checksum. The TX433 module uses amplitude modulation therefore when the data-in is low, it doesn’t consume any power

Power consumption:

During each wake-up it consumes

  • Sensor reading 80mA * 1ms
  • Transmitting data: 30mA * 4ms

Total: 0.2 mAs = 5.5E-5 mAh

The battery should be about 2500mAh, which gives 45 million readings. On average the period of the reading is 30s, which should give 1000years of operation! However it will die much before since the sleep state consumes some tens of uA and there is an internal drain of the battery. Anyway if it last for a year I will be happy.

Tips:

  • I’ve printed the PCB schematic using the supermarket publicity magazine. Transfered to the PCB with the toner transfer method, and Hydroclorone - peroxide for etching.
  • I’ve cut in half a DIL08 socket to get two 4-pin sockets one for the TX433 and one for the programming port.

    DSCF1438.jpg

  • Using the standard cable/programming port from PICAXE but I've connected the pins facing downwards therefore 

    Connector.jpg


    I can insert easily in the half DIL08 and reprogram it at any time. With a small jumper I can use the serin pin as an additional input. The serout pin I use as the data-in for the TX433 module.

    DSCF1440.jpg

  • I've used a 4.5V flat battery with, which I've found as a cheaper solution (1.5EUR alkaline) rather than using 3 x 1.5V AA batteries adding a box and the cable connector.

Receiver module:

I've decided to have an intermediate module as a receiver, rather than connecting the RX433 directly on the Raspberry PI computer. The reasons are the following:

  1. The Raspberry PI is linux based, therefore not real time and the buffer of the UART is very small. Furthermore the RasPI has small memory and once a heavy application is loaded swaping starts and practically stops any process. Therefore it could lose data
  2. The GPIO of RasPI is unprotected, so I wanted to have some intermediate protection of the PI using a PICAXE uC

As a uC I've used the PICAXE 14M2 (because I run out of 08M2) and having in mind that in the future I want to be able to control devices in the house. The setup is very simple (presently still on breadboard)

Receiver.jpg

TX433 data-out is directly connected on Pin 1 of the 14M2 and the Pin 2 via a voltage divider (5V -> 3.3V) to the RX of RaspPi

The program uses two threads:

  1. First is listening the RX433 waiting for the correct data sequence to be send by any of the sensors. Using the checksum to reject unwanted noise, and remove any repetive data. Once it receives a valid packet, it records it on a cycle-buffer in the memory of the 14M2
  2. The second thread looks the cycle-buffer if something is available and if it finds anything it transmits it to the PICAXE

Tips: The senstivity of the RX433 is proportional to the input voltage. Initially I had the module running on batteries, and once the battery voltage was dropping below 4.3V it was unable to receive data from the far sensors (above 5m)! Now I am using a cheap 5V usb power supply (5 EUR) and it works perfectly.

Raspberry PI:

I am running a custom python script to read the data from the 14M2 and record them in individual files names sensor-$ID.dat for  each sensor. All the "advanced" logic happens here e.g. the conversion from temperature-adc reading to Celcius and currently I am working on the Humidity adc reading to humidity percent (a bit more complicated since it requires also the information on temperature).

For the moment I am just recording the data and I have a web interface to monitor the status of the sensors and make graphs with gnuplot

temperature.png

light.png

The external sensor I having inside a marmelade jar with holes, which behaves like a green house so the temperature goes to 40C during the day, while in shadow we should have only 20C. I can see the time when my wife cooks in the kitchen, when she opens the windows of the house, lights in the rooms (the sharp lines on the second plot) as well when clouds cover the sun!

Nice!

Nice!

Avoid Interference by Random Seeding Send-Timing

Is it correct that you use only one-way communication from the sensors to the controller?
And since you have 433MHz frequency it is possible that two sensors send their data at the same time - so you try to avoid this by seeding some randomity into the send timings?

Actually I am thinking about this for a while and like the 315MHz and 433MHz modules since they are cheap, easy to use, have a small footprint on the microcontroller (the code) and are quite efficient.

But since all sensors send on the same frequency interference or other data-losses are possible. You did not go down the path to avoid it 100% but make it less feasable that it happens. At least with the amount of sensors you plan right now.

So thank you for this share and welcome to LMR.

Terrific first project post

Thankyou for sharing. Good to see a Pi project explained in detail. I think a lot of us have one and are looking for uses to put them to. Your system seems well thought out.
Python is nice, I did the Udacity learning python course but when resources are limited then you realise what a luxury it is.
Interesting that they are now offering the Pi with 500mb of ram.

Thank you

Thank you

Thank you.I wanted to

Thank you.

I wanted to minimize the cost, so I chose one way communication with no feedback. Therefore the sensors have only a transmitter and they are not sure if the receiver accurately received the content. But it doesn’t really matter since in a few minutes they will send fresh information if something has changed, and if nothing has changed they will repeat the transmition about every (randomly) 5 minutes .

I chose a random interval (even the seed is different = equal to the ID of each sensor) to avoid any interference pattern, if the period was fixed, then it could have high chances due to slightly different clock (temperature variation) that two or more sensors transmit for a long period the data exactly the same moment.

Up to now I have 6 transmitters and the rejection rate is rather small. Almost one every 100 readings. I want to put also some filters for abnormal readings in the python (raspi) side. e.g. if the temperature jumps abruptly +/- 10C etc.

My plan is to add ~20 sensors in total. One in every room for temperature, humidity, illumination, as well sensors on current consumption, car presence in the garage, water and gas flow. And I want to find also a way to detect if the main door is locked or not. Many times when leaving on vacation I had to return back to verify if I properly closed the door :slight_smile:

Python is great, however is

Python is great, however is memory hungry. The main script eats about 10Mb for about 100lines of code! Another thing I’ve noticed was that if you dynamically allocate/deallocate a lot of objects, even though python frees internally the memory it doens’t give it back to the system, so slowly you could see that it eats a lot of memory while only a small fraction is actually used. In my code I’ve tried to minimize any object allocation.

RasPI is very nice, Initially I was hesitating between an old/cheap Android phone and the RasPI, but I ended with the RasPI. It has the ethernet plug available, USB host (not many android phones have a host), as well the GPIO that one can use it an any other uC, plus the serial (UART) port.

I plan to order the new model to use it as a brain for the Mobile robot I am currently working on.

Very cool project

This is exactly what I need to do for my own home.

Thanks for the inspiration.

I may need two way communication though…

In the final stage I want to

In the final stage I want to have something like loose “two-way” communication. I want to keep each sensor one way, and independent from the action that I want to transmit. I want to buy wireless controlled power-plugs and control them from the RasPI + PICAXE