Sunday, 4 March 2012

Wireless sensor node - enclosures (10)

I now have all of the basic hardware prepared to allow me to deploy my wireless sensor network. However, I still need to work out the best way to package the various parts.

I have ordered a couple of plastic boxes which I am planning to use to package my nodes. In particular, I want a plastic box to put my base station in so that I can screw down the usb breakout board. One of the boxes should be a perfect size to contain the base station. The smaller box will contain a wireless sensor node.

However, in the mean time I decided to try my hand at making a cheaper enclosure out of some red cardboard which I already had at home. I drew the following template using Inkscape.


The source svg file is available here. The only joint which requires glue is the tab on the left. The top and bottom are designed to be folded in on themselves without glue.

I was quite pleased with the results.


This is now sitting on top of my kitchen cupboard broadcasting the temperature every 5 minutes. I don't have my base station setup yet but since the sensor node has an expected battery life of over a year I have plenty of time to deploy the base station!

There are two main next steps:
  • Sort out the base station enclosure.
  • Write more code on the base station to log a history of readings, spot when readings are missing and expose this information over the serial port.

Wednesday, 29 February 2012

Wireless sensor node - prototype node (9)

It's finally time to build my first proper prototype wireless sensor node. The components are as follows:
  • CR2032 3V battery + battery holder
  • ATtiny85 MCU + 8 pin socket
  • TMP36 temperature sensor + 3 pin female header
  • 315MHz RF TX module + 4 pin female header
  • A small amount of tripad board
The process of soldering these parts together went quite smoothly. And yes, that is some beer brewing beside me!


 The results without any parts in place looks like this.


And this is what it looks like with all the parts in place.


I'm fairly pleased with how neat the soldering turned out.


Sadly having built this I found that the RF TX no longer worked reliably and the temperature sensor wasn't reporting accurate readings! This required some software fixes!

1) Fixing the RF TX

I have historically used a scheme where I sent three 16 bit values and then combined them at the receiver. However, the Manchester lib now supports sending longer messages so I've retired my pointless message combining code and simply send a single longer message.

2) Getting accurate readings out of the TMP36

The basic method for getting temp readings is as follows.

  int sensorValue = analogRead(TmpPin);
  // Constant: 5000 / 1024
  float milliVolts = sensorValue * 4.8828125;
  float tempC = (milliVolts - 500) / 10;
  return tempC;


The crucial change to make when running on an ATtiny85 is to change the constant which adjusts for the reference voltage being used which in my case is certainly not 5V!

First, add the following to your setup method. This tells the ATtiny85 to use the internal 1.1V reference voltage in preference to the VCC which will change as our battery runs down.

  // Select the 1.1V internal ref voltage
  analogReference(INTERNAL);


Secondly, update the temp reading code as follows.

  int sensorValue = analogRead(TmpPin);
  // Constant: 1100 / 1024
  float milliVolts = sensorValue * 1.07421875;
  float tempC = (milliVolts - 500) / 10;
  return tempC;

3) Getting more accurate readings out of the TMP36

The ATtiny85 internal 1.1V reference voltage isn't very accurate so it's worth calibrating the constant you are using. To do this I took a temperature reading from the TMP36 when connected to my ATtiny85 and when connected to an Arduino Uno. I then used the following formula:

V_calib = V_base * ((T_ref + 50) / (T_base + 50))
V_base = 1100
T_ref = temp as measured on Arduino Uno
T_base = temp as measured on ATtiny85

I ended up with V_calib = 1028 which gave me fairly accurate temp readings.

The results?

A working wireless sensor node! (I have added a ~20cm antenna wire since the previous pictures)



I have tested this node briefly but I won't deploy it until I do some more work.

For the wireless sensor node I want to build an enclosure.

For the base station I want to build an enclosure and write code to handle storing readings and allowing download over bluetooth.

As ever, the Arduino code is available on Github:

Monday, 27 February 2012

Wireless sensor node - watch battery (8)

Back in part 4 I made some improvements and did some sums and convinced myself that I could run my TX node on 3x AA batteries for more than a couple of years. Here are the sums I used.

Entering the following figures into this website:
  • Battery capacity: 1700mAh
  • Sleep current consumption: 0.006mA
  • Wake current consumption: 8.5mA
  • Duration of wakeup: 2000ms
  • Number of wakeups per hour: 12 (once every 5 minutes)
The result: 2.6 years.

It occurred to me that the wakeup time of two seconds is pretty long. I used this time to allow for 3 transmissions with high power sleeps between them. However, if I use low power sleeps between retransmits I can be running at high power for a much shorter time and hence get a much better battery life. The results are pretty impressive.
  • Battery capacity: 1700mAh
  • Sleep current consumption: 0.006mA
  • Wake current consumption: 8.5mA
  • Duration of wakeup: 100ms
  • Number of wakeups per hour: 36 (once every 5 minutes * 3 transmissions of each reading)
The result: 11.38 years! It seems pretty unlikely that my batteries would actually last for a decade but this long battery life means that I could get away with a much smaller battery. A single CR2032 watch battery is very cheap, 3V and usually has a capacity of 225mAh.
  • Battery capacity: 225mAh
  • Sleep current consumption: 0.006mA
  • Wake current consumption: 8.5mA
  • Duration of wakeup: 100ms
  • Number of wakeups per hour: 36 (once every 5 minutes * 3 transmissions of each reading)
The result: 1.51 years! That's an ideal length of time - I think I'll be using CR2032 batteries with my wireless TX node.

Sunday, 26 February 2012

Wireless sensor node - new hardware (7)

In my last wireless sensor node post I described the compact breadboard layout which I had come up with for prototyping. This layout allowed me to program my ATtinty85, run my ATtiny85 RX TX and run my Arduino RX. However, this was really cumbersome and I don't want to tie up my Arduino Uno for ever. It's time to break out my TX and RX nodes into their own circuits.

Firstly I have my base station RX node based around my new Arduino Pro Mini. This has the following parts:
  • Breadboard
  • RF RX module
  • Arduino Pro Mini
  • One of:
    • FTDI cable for programming + power
    • USB breakout board for power + Bluesmirf Silver Bluetooth module for wireless comms with the board
The results look like this with the FTDI cable.


The extra bit of tripad board here is because I don't have any double sided male headers.



 The base station looks like this with the Bluetooth module and USB power.


The wireless TX sensor node itself continues to be based around an ATtiny85. However, now that I have a dedicated USBtiny programmer I can use the following circuit for conveniently prototyping the TX board. This has the following parts.
  • Breadboard
  • RF TX module
  • ATtiny85
  • One of:
    • USBtiny for programming + power
    • Battery pack for power
The results look like this with the USBtiny programmer:


The TX node looks like this with the battery pack.

Saturday, 25 February 2012

Making it easier to program an ATtiny85

Ever since I got started with an ATtiny85 I have been using my Arduino Uno to do the programming. One of my friends has been through several iterations to make programming an ATtiny as easy as possible. This culminated in him building something he called the "Frankentiny".

I have finally invested in a dedicated USBtiny programmer (~£10).


This exposes a standard 6 pin programming header. This requires you to build a circuit to interface between the 6 pin connector and an ATtiny85. The pins are as follows.


I built the following circuit on some tripad board:


This includes a 4 pin header to expose pins 3 and 4 which are unused and expose VCC and GND.

Friday, 24 February 2012

Oculus Robot

I just came across a cool product called the Oculus Robot. This reminded me of the Big Bang Theory episode where Sheldon builds himself a Mobile Virtual Presence Device.


For around £175 you can get yourself a remote controllable platform for your netbook.


Thursday, 23 February 2012

Arduino Pro Mini serial pins

In my previous post I described the Arduino Pro Mini. I have now bought one of these and want to get started with it. However, the Pro Mini does not include a built in USB to serial connection. 

To get started you need to get an external USB to serial connector. This can come in the form of a cable or a breakout board. These will often be referred to as FTDI cables or FTDI breakout boards. This is actually an abbreviation for the name of the company (Future Technology Devices International) which makes the most common USB to Serial chips. 

The latest breakout boards come with a female header, older versions featured through hole connections which required you to solder on your own header. The cable normally comes with a female header. In both cases the Pin out should match up with the 6 pins on the end of a Pro Mini to allow for a direct connection to be made. 

The headers which you use for the FTDI connections on your Pro Mini will depend on the way that you intend to use the Pro Mini.

Here are some pictures of possible solutions from these pages.

Right angle male header with an FTDI breakout:


Regular male header with an FTDI cable:


I chose to attach female headers to my Pro Mini so that I could use my non Mate Bluesmirf Bluetooth module which I have previously soldered wires to. 


If you have a Bluesmirf Mate then you can connect the pins directly. The non Mate version requires that you flip a couple of the pins as described in this excellent blog post.