The TinyTX is my Open Source wireless IoT sensor node, designed to be compatible with OpenEnergyMonitor, Nanodes and Jeenodes. It uses the Atmel ATtiny84 microprocessor and a HopeRF RFM12B transceiver module and is coded using the Arduino IDE with the arduino-tiny core.
Initially devised with the DS18B20 digital temperature sensor in mind it can also easily be used with a dual temperature/humidity sensor such as the DHT22 or an analogue temperature sensor such as the TMP36 or many other kinds of sensors, some examples are included below.
To power it I use two AA or AAA batteries, a 3v coin cell can also be used but as they don’t have a lot of capacity I don’t think they really make a lot of sense unless size really is that critical. Another option would be to use a LiPo battery.
The maximum voltage is 3.8v and minimum for the RFM12B to work is around 2.2v although the operational minimum for a complete sensor will depend on the characteristics of the actual sensing device used, for example a DS18B20 worked down to around 2.3v in my real word tests (data sheet value 3v) but the DHT22 only worked down to 2.96v (data sheet value 3v).
New: TinyTX3 is here, that’s the red one on the right, it now has 6 available I/O and prototyping holes. I will update this page with more details soon.
- Temperature Sensor using a DS18B20 digital sensor and a 4K7 resistor (blog post, code)
- Temperature/Humidity Sensor using a DHT22 and a 10K resistor (blog post, code)
- Temperature Sensor using a TMP36 analogue sensor, fit the sensor in the reverse orientation compared to DS18B20 and don’t fit a resistor (blog post, code)
- Flood/water leak sensor using a 100K resistor and wire probes, also code to use a TinyTX as a receiver (tx code, rx code)
- Light sensor using an LDR (Light Dependant resistor) and a 10K resistor (code)
- Electricity consumption meter using an LDR and a 4K7 resistor (blog comment by Troels, code)
- Reed switch for door/window monitoring with pin change interrupt to wake from sleep (code)
- Hall effect sensor (magnetic field detector) using an A3214EUA-T or A3213EUA-T to monitor gas usage (code)
- Rain gauge using a tipping bucket rain gauge (code)
- BMP085 air pressure/temperature sensor (code)
- Or many other digital or analogue inputs or switch contacts.
Open Source Hardware
The hardware design and software are completely open source, you can get the schematic, Eagle design files and Gerbers from the links at the bottom of the page or from SolderPad and the latest code is always available on GitHub here, you can also find a layout for the stripboard version of the TinyTx here.
It is all licenced under a Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) licence, see the link for the full details but basically you can copy or adapt it for your own use as long as you credit me and share the results under the same kind of licence. It’s not necessary but if you do use it, it would be nice to hear from you in the comments or by email, it’s always interesting to hear what others are doing with this stuff and sharing ideas is one of the key benefits that open source can bring.
Thanks must go to to JeeLabs, OpenEnergyMonitor and Nanode (in no particular order) for inspiration and for opening their designs as well as all the people who have commented in my blog posts on the development of the TinyTX and its predecessors. I’m pleased to see that my work has in turn inspired others such as Martin with his great TinySensor and Phil’s Multi purpose ATtiny84 PCB, this is what Open Source Hardware is all about.
Components, what to buy and where
I usually buy my ATtiny chips from RS Components, I use the picoPower version, the ATtiny84A-PU which works down to 1.8v but the older ATtiny84V-10PU would work just as well, both will be slightly out of spec at 8MHz once the voltage drops below 2.4v but this seems ok in practice, a DS18B20 starts dropping out below that anyway and the RFM12B will give up below 2.2v so we’ll never get too far from spec. Don’t get the ATtiny84-20PU as that only works down to 2.7v at 10MHz.
You can also get the RFM12B from RS Components but SK Pang can be a little cheaper if you are only ordering a few, most recently I have been getting them from JeeLabs who do a pack of 6 for €29.50 (433MHz and 868MHz). The RFM12B is available in three frequencies but bear in mind that some of them can only legally be used in certain countries. The antenna will need to be sized for the board you choose and you will also need to change the #define freq line in the code if using something other than the 433MHz that I’m using.
|Frequency||Can be used in||1/4 Wave Antenna Length|
|915MHz||USA & Australia||78mm|
I chose 433MHz back when I first started playing with the OpenEnergyMonitor stuff as I wanted to retain compatibility with what they were using, I’ve heard anecdotal evidence that 433MHz passes through walls better but I don’t have any real evidence to back that up and it is a busy frequency so one of the others may be a better choice, you’ll have to make that decision yourself.
For DS18B20 and DHT22 sensors the cheapest I have found by far is eBay. Don’t be tempted by the cheaper DHT11 sensor, the humidity accuracy is poor, it will only return integer values and only covers 0-50°C compared to -40 to 125°C for the DHT22.
If you want to get PCBs made up I can recommend the Chinese site SeeedStudio, for 10 boards in green (other colours are more expensive) it costs 9.90 USD + shipping which worked out at £9.01 including UK delivery (90p each) and it will only take a couple of weeks. They don’t take Eagle files directly but Eagle can export the Gerber files that they need and they have an Eagle design rules file that makes it easy to check that your board fits with what they are capable of producing and a job file for the Gerber export to make sure everything is setup correctly for them. It’s still worth double checking the resulting Gerber files in a viewer such as Gerbv to make sure everything has come out as intended, I found that some of the silkscreen text that looked fine in Eagle had overflowed the board in the Gerber files. If you don’t want to get 10 boards made up you could always build the stripboard version or the guys at Circuits.io were also kind enough to import the Eagle files into their site for me so you can order boards in a pack of 3 from them for $14.67 plus $5 for international shipping. Unfortunately they don’t support adding text to the silkscreen so you will lose all the labelling with their boards. I’m not selling any boards myself at the moment but might have something in the pipeline soon.
You will need the Arduino IDE of course and to use it with the ATtiny84 also requires installing the arduino-tiny core. To install arduino-tiny you just need to create a directory under your Arduino sketchbook directory called hardware and unzip the latest arduino-tiny from here into it. Now restart the Arduino IDE and you should see the new ATtiny entries under the Tools > Board menu.
You will also need to put the necessary libraries in your Arduino libraries directory, for each variation (eg. DS18B20, DHT22 etc.) I have linked to the required libraries in the comments next to the includes near the top. All variations will require the JeeLib library for driving the RFM12B.
If using the DS18B20 you will need to make a small change to the OneWire library to enable it to work with the ATtiny84, just open OneWire.h and below the line:
#include “Arduino.h” // for delayMicroseconds, digitalPinToBitMask, etc
#include “pins_arduino.h” // for digitalPinToBitMask, etc
Getting the code onto the ATtiny84
To get the code onto the ATtiny we need to use ICSP (In Circuit Serial Programming), you can use an ICSP programmer if you have one, otherwise a spare Arduino will do. I made up the little Arduino shield on the right using a scrap of stripboard and a ZIF socket to make it easier.
To use an Arduino as an ICSP programmer you need to load the ArduinoISP sketch on the Arduino and connect the SPI pins and reset between it and the ATtiny. A version of the ArduinoISP sketch is included in the examples directory with the Arduino IDE but it seems to be broken, if it doesn’t work download this one instead and load it onto the Arduino in the normal manner.
To wire it up on breadboard connect the Arduino to your ATtiny as follows:
I’ve been using a cheap USB ASP programmer with an IC test clip which allows programming without removing the chip which also means that the chip can be soldered directly to the board without the need for an IC socket.
Once you’ve got the programmer sorted the first thing to do is set the ATtiny’s internal oscillator to 8MHz, to do this you need to go to Tools > board and select “ATtiny84 @ 8MHz (internal oscillator;BOD disabled)” and then use Tools > Burn Bootloader. Note that this isn’t actually burning a bootloader to the ATtiny (it doesn’t use one), it is just using this function to set the AVR fuses to configure the oscillator at 8MHz.
Now download the appropriate TinyTX code from Github, eg. TinyTX_DS18B20.ino if using a DS18B20 sensor and upload it using the Arduino IDE in the normal manner. If you are using an Arduino as the programmer the ArduinoISP sketch running on it will upload it on to the ATtiny transparently. You will probably get the following message twice:
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny84
but this can be safely ignored, as long as it says “Done uploading” at the end then you are good to go.
If you get some errors about “expected identifier or ‘(‘ before ‘double’“ then you need to comment out the following line in ~/sketchbook/hardware/tiny/cores/tiny/wiring.h
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
If you get “not in sync” or “protocol error” then try reducing the baud rate in the ArduinoISP sketch and in hardware/arduino/programmers.txt (under your Arduino IDE directory) as mentioned here, I had to do this to get it to work.
On the receiving end
At the receiving end I am now using OSWIN, my own design for an ATmega1284P based Arduino compatible, prior to that I used a prototype MAX1284 gateway and prior to that I used a Nanode. This relays the data to my installation of OpenEnergyMonitor’s emoncms which gives me nice graphs and visualisations of temperature, humidity, air pressure and rainfall as well as electricity and gas usage. Code for both is available below along with a simple receive example and an example to upload data to Cosm (what used to be called Pachube). I have also built a number of wireless graphical LCD displays that display the data and have their own temperature sensors built in and I’ve also experimented with the Raspberry Pi as a base station and that is also a good option if you want an all in one receiver and server.
Code for transmitters:
DS18B20 Digital Temperature Sensor
TMP36 Analogue Temperature Sensor
DHT22 Digital Temperature/Humidity Sensor
Light Sensor using LDR
Electricity consumption meter using an LDR
Reed Switch for door/window monitoring
Hall effect sensor (magnetic field detector)
Tipping Bucket Rain Gauge
BMP085 I2C Air pressure/temperature sensor
Code for receivers:
Simple serial console receive example
NanodeRF multiple TX to emoncms relay
NanodeRF single TX to Cosm relay
MAX1284 multiple TX to emoncms relay
Flood/leak alarm receiver
Code for graphical displays