I plan to build a Standalone Temperature Logger with the minimum components as I can, I’ll be using the ATtiny85 and Arduino software to program it. Firstly I’ll have it run on the Arduino to confirm it’s working, then migrate it to the ATtiny85, make it run on battery and make a PCB of it all. It sounds like a simple concept, but I know there’s going to be more to it that meets the eye.
- Use the minimum components possible
- Power the project with batteries
- Specify the logging delay time
- Write temperature to EEPROM on-board
- How to extract data from EEPROM
Now lets go through all these design characteristics.
Use the minimum components possible
So I don’t want this standalone temperature logger to be complex or having many working parts. I won’t be needing a real time clock or a external EEPROM or a crystal for the micro, etc. The minimum components I’ve come up with is an ATtiny85V micro-controller with a 10K thermistor, button and LED. Some other components include a battery connector and possibly some header pins.
According to this website it’s possible to program the ATtiny45/85 with an Arduino by having the Arduino act as an In System Programmer (ISP), sounds good. Now I’ve chosen the ATtiny85V because firstly it has 8K flash and the higher 512bytes EEPROM. It has 3 analog inputs and 2 PWM (digital) outputs.
For the component to measure the temperature, I’ve gone with the 10K thermistor that is referenced in the Arduino Thermistor example. It seems that the Thermistor is a Vishay part which has a range of -40C to +125C, something to keep in mind.
Why do we need a button and a LED? Well the single button will be used for starting the logger and configuring the logging delay time (more on this later). The LED will act as a confirmation of our button presses and can blink a few times to show what we have done is confirmed. The LED will be a small 3mm red LED with a diffused lens type to allow for a higher viewing angle.
Power the project with batteries
Do we use AA, AAA or a 9V battery? This is a long question but once you take your time you have an answer, for me it’s AA and I’ll explain why.
Lets start off with a 9v battery, firstly to power the ATtiny85V (note the V), it requires 1.8V to 5.5V. To convert the 9V to 5V we’ll need a voltage regulator, the one I chose is the LM7805.
From the datasheet we see the LM7805 can convert 7V to 25V to 5V, excellent that covers our 9V battery. Now lets check the power dissipation.
We see it’s 65C per watt, we’ll assume our circuit takes 20mA (which I’m sure it won’t) and do the calculations: (9V-5V) * 0.02mA = 0.08W of dissipation, so we’ll definitely be fine with no heatsink. Now lets check how we wire it up.
So we connect our 9v battery positive to pin 1 and battery negative to pin 2, then we get out 5v output positive from pin 3 and pin 2 is ground. If you noticed in the Electrical Characteristics it actually gives you a test circuit as: -40C < Tj < 125C, Io = 500mA, Vi = 10V, Ci = 0.1uF. The thing we don’t yet have is the Ci which is the capacitor for the input, they recommend a 0.1uF capacitor and you connect that to pin 1 and pin2.
Lets now test the 5V voltage with our multimeter.
Close enough for me, now time to test a LED.
It works! But what we haven’t looked at is how much current does this voltage regulator take up when nothing is connected to it? One would think close to 0mA however it’s not the case, for me it’s 3mA when no load is connected; the datasheet says it’s typically 5mA. This is what’s called the Quiescent Current, the amount of mA the voltage regulator takes when no load is connected.
There are voltage regulators around that do only take close to 0mA however they are expensive and for this project we are going for minimal parts and to keep things cheap. So that’s strike 1 for the 9v battery.
Next thing is how long will the battery last? Ideally I would like it to last a few days and would like to use a rechargeable battery, for 9V it’s typically 175-300mA. I happened to find this battery life calculator website, plugged in the details as 3mA (Voltage Regulator) + 3mA (ATTiny85V + LED [estimate]) current use with a 250mAh battery and got back 1.48 days, not nearly enough, strike 2 and we’re done with the 9v battery.
Let’s move to AA/AAA now, the ATtiny85 supports 1.8V as the minimum working voltage, 1.2v x 2 = 2.4v which is good enough. Lets do the calculations based on 3mA now for our ATtiny85 with the LED rarely on.
AA: 2500mAh @ 3mA = 29.51 days
AAA: 900mAh @ 3mA = 9.44 days
So it’s clear that AA wins this as expected however they are a little larger in size however the days it’ll last is I think worth the extra size.
Specify the logging delay time
I’d like to be able to specify the logging delay time, i.e. time between each temperature reading, without having to re-program the ATtiny, the easiest solution is to use a single button and LED in a different number of ways.
Perhaps when turning on the ATtiny, you can hold down the button for 2 seconds, then the LED turns on to say you’re changing the delay time, something like this? Then you can hold the button down for 2 seconds again and the LED can blink 3 times to confirm your selection?
1 button press = 1 minute delay, 2 = 5mins, 3 = 10mins, 4 = 15mins, 5 = 30mins, 6 = 1hr, 7 = 2hr, 8 = 4hr, 9 = 8 hr, 10 = 12hr, 11 = 24hr
This would mean that when turning on the ATtiny, maybe it’s actually better not to start logging until the user presses the button once or holds it down? I guess that would be good so your previous results don’t get accidentally erased.
Write temperature to EEPROM on-board
So our ATtiny85 has 512bytes of EEPROM on-board, we actually need to reserve the first address to store the logging delay time above, so we have 511 places to log our temperature data. However remember that the range of the 10K thermistor is from -40C to 125C, how do we store -40C to our EEPROM when you can only store the values 0 to 255?
Easy, what I did is take 255 as the upper value, subtract 125 from it and I got 130. So the value 130 is our new 0C temperature, -40C is 90 and 125C is 255, simple. If out thermistor read 30C, it would encode it as 160 (30C + 130).
Now how can we know the last data value, for example, we disconnect the battery or the battery runs out? I originally thought of keeping the a 2 byte address of the last EEPROM address we wrote to however an easier way is just to write 0 to the next EEPROM address. We can do this because we know that none of our temperature values will ever be 0; so we write our temperature value in say EEPROM address 5 and then in address 6 we write 0. The next iteration, we write the temperature value in address 6 and in address 7 we write 0.
How to extract data from EEPROM
For this we could actually use the 2Wire interface. Upon investigation of the ATtiny45/85 implementation on the Arduino that the hlt.media.mit.edu website did, it doesn’t have this functionality enabled. I could go around and start trying to get it working however why not just make my own simpler version of it using 2 wires as well?
My idea is to use 1 wire as the clock and another one as the data out line from the ATtiny. The Arduino would send a CLK of high for say 1 second and then send CLKs of highs/lows each lasting 1 ms. In each of those 1ms CLK highs, the ATtiny would send a high or low according to the EEPROM byte/bit it was reading. 1 byte/8 bits would take 16 ms, so gives us 62.5 bytes/sec which isn’t too bad.
Once the ATtiny reads the 0 in the EEPROM to indicate it’s the end of the logging (as above), it would send 8 bits of lows which indicates 0 and the Arduino would know to stop sending the CLK signal. I’ll have to look into this all a bit more closely.
That’s all for Part 1 and how I believe this project might work, Part 2 will be testing my code on the Arduino which will have all functionality except for the extracting data from the EEPROM, stay tuned!