ATTiny85 Mono Temperature Monitor
by stannickel in Circuits > Arduino
14655 Views, 100 Favorites, 0 Comments
ATTiny85 Mono Temperature Monitor
![2015-09-26 13.47.47.jpg](/proxy/?url=https://content.instructables.com/FM5/6I56/IF0XW92E/FM56I56IF0XW92E.jpg&filename=2015-09-26 13.47.47.jpg)
![2015-09-26 13.53.35.jpg](/proxy/?url=https://content.instructables.com/FF0/THFA/IF0XW92D/FF0THFAIF0XW92D.jpg&filename=2015-09-26 13.53.35.jpg)
I like to do electronics as a hobby and have a nice workspace that I made from a discarded PC. It contains a soldering holder and soldering iron (upper right corner of the workspace picture). It happens that I don't have a handy way to turn it on and off, so I plug it into a power strip behind my workspace. I'm never really sure if it is on or not. I thought if I could just measure the temperature near the soldering iron and have some kind of alert, I would know if it is on or not. (Yes, yes, I could spend my time figuring out a failsafe switching system, but I don't have the ingenuity for that.)
So, I came up with this project. OK, I know. There are hundreds, if not thousands of electronic temperature measuring devices made with Arduino and with 555 Timers. The problem is that I could not find one to do my specific job. I just wanted something that would tell me that my soldering iron is on and hot. Something that warns me to turn it off, if I go somewhere else. Really, just something to tell me if it is on. This project is for a device that measures only one thing is the temperature above (or below, if you wish) a certain point. It's a "mono" temperature monitor. It only measures ONE thing.
I thought it might be interesting to see if there are other applications, maybe measuring the baby bottle temperature, or anything that is not ambient temperature. Let us sally forth.
Materials and Equipment
![billofmaterials.png](/proxy/?url=https://content.instructables.com/FCG/2IGR/IF0XW9JF/FCG2IGRIF0XW9JF.png&filename=billofmaterials.png)
Arduino UNO or nano set up to program ATTiny85 microcontroller
ATTiny85 microcontroller (eBay sells them for about $1.25 each)
Solderless breadboards, one should have a power supply; this one looks like a good deal: http://www.banggood.com/MB-102-MB102-Solderless-Breadboard-Power-Supply-Jumper-Cable-Kits-p-933600.html
Arduino programming environment for the PC (current version is 1.6.5 https://www.arduino.cc/en/Main/Software)
LEDs - green and red
Thermistor - 10K ohm, these are something like 5 for $1.00; mine are green, I also have black ones. You have to calibrate them anyway, so it doesn't make much difference which one.
Resistors - 10 K ohm, and two 270 ohm
Programming ATTiny85 With Arduino UNO
![UNOProgrammer.jpg](/proxy/?url=https://content.instructables.com/FEJ/2VOX/IF0XWCVK/FEJ2VOXIF0XWCVK.jpg&filename=UNOProgrammer.jpg)
![attiny45_85pinout.png](/proxy/?url=https://content.instructables.com/F89/LP57/IF0XWCPO/F89LP57IF0XWCPO.png&filename=attiny45_85pinout.png)
You need to be able to program the ATTiny85 chip. That may be done with an Arduino UNO or nano microcontroller. I happen to have both of them. I find the Arduino UNO the easiest to use. The first photo shows the setup and a reasonably complete wiring setup. You could use a solderless breadboard instead of the soldered prototype board that I have depicted. Wiring is simple.
The best way to learn to program the ATTiny85 is to go to this website: http://highlowtech.org/?p=1229 It is very complete and does explain things quite well. I'll summarize for you. Notice first of all, the pinouts. In my photo, I am using the straight up 8-pin DIP layout. Starting at the notched end at the lower left, you see pin 1 and go counter-clockwise to pin 8. Hint: On receiving a shipment of these chips, I always use a little white-out correction fluid to mark pin #1. That way, I don't need my glasses to see which is pin 1. I also mark the receiving IC socket in the same way.
OK, programming in simple steps. 1) Connect the wiring to the Arduino UNO. 2) Get software for the ATTiny series: http://highlowtech.org/wp-content/uploads/2011/06/attiny45_85.zip 3) Unzip the contents into a hardware folder in your Arduino folder, you may need to create the hardware folder. 4) Connect the UNO to the PC. 5) Open the Arduino programming environment. 6) Go to Examples and select Arduino ISP from this menu. 7) Upload it to your UNO. 8) Try your setup with the Blink sketch. To do this, you need to edit Blink and change pin 13 to pin 0 (zero). 9) In Tools menu, select your Board (ATTiny85) AND Arduino as ISP. The port should be that of the UNO. 10) Upload the Blink sketch to the ATTiny85. 11) Connect an LED to a 220 ohm resistor and connect the positive lead to Pin 0 of the ATTiny85 and negative to GND. The LED should blink.
Wire the Breadboard
![2015-09-26 13.48.49.jpg](/proxy/?url=https://content.instructables.com/FFL/4KVY/IF0XW92G/FFL4KVYIF0XW92G.jpg&filename=2015-09-26 13.48.49.jpg)
![ATTiny85placement.png](/proxy/?url=https://content.instructables.com/F6A/JMC4/IF0XWESS/F6AJMC4IF0XWESS.png&filename=ATTiny85placement.png)
I've provided a photo and a schematic of the wiring layout. My suggestion is to use a solderless breadboard with its own 5V power supply. If you bought the kit alluded to the the materials list, you can use a USB cable or a 9-volt battery with a barrel connector. This provides a clean 5V current. You can run the chip directly from a 9-volt battery, but you are taking chances with blowing the chip.
Connect the 10K resistor to the 5 Volt power supply and connect the other end to the thermistor (no polarity, use either side). Attach a wire between the resistor and thermistor to pin #7 on ATTiny85. This is also known as A1 and is one of three analog pins used for input to the chip. Your sketch will refer to the pin as A1. Connect the open end of the thermistor to GND. Then, connect a 220 Ohm resistor to pin #5 and the other end to the positive (long) lead of the red LED. Pin #5 corresponds to a digital output port known to your sketch as pin 0 (zero), one of two PWM pins. The short lead of the red LED goes to GND.
For calibration purposes, you need to add one more LED. I used a green one. It goes the same way as the red LED. Connect a 220 Ohm resistor to pin #6 (corresponding to pin 1 PWM and pin 1 in your sketch). Connect the open end of the resistor to the long lead of the green LED and the short lead to GND.
And, finally, connect pin #4, the GND pin, to GND of your power source.
Check your wiring once more, and get ready to program the chip.
Programming the Chip - Calibration Intro
Be prepared to move the chip between the programmer and the mono thermometer breadboards. Maybe a lot!
The first thing we have to do is calibrate the thermistor. We need to know what ambient temperature means to the chip. To find this out, we are going to use the green LED as the counter and the red LED as the monitor. We'll be changing the base value of START_TEMP several times, to figure out what the chip thinks is the base ambient temperature.
Insert the ATTiny85 into the programmer, if it is not already there. Open the Arduino environment on your PC. Take the sketch called, ATTiny85monoCalibration.ino and upload it into the ATTiny85 chip. Everything hinges on the #define START_TEMP 60 statement. Note that I am starting with 60 as the starting temperature for calibration. You may start with a different number. You will encounter this variable near the bottom of the sketch. (NOTE: For all practical purposes you do not have to understand anything else in the sketch except the bottom part of the sketch where we will be making changes to find out what ATTiny85 thinks ambient temperature is.) I'll cut-and-paste the crucial part on the next page. That is the part you may need to edit.
Downloads
Programming the Chip - Calibration Setup
OK, here is the sketch you need to be concerned with:
if (calcnumF > START_TEMP - i) // count down until it is not hot
{ // Red LED
analogWrite(outPin0, 255);
delay(100);
// analogWrite(outPin0, 0);
delay(10); } // end if calcnumF
analogWrite(outPin1, 0);
// turn off green pin
delay(100);
} // end for
exit(0); // just quit; red LED is probably on at this point green LED should be off
} // end loop
The main thing you can do is change the START_TEMP at the top of the sketch. You would change the number 60 to something else. What we are getting at here is to find out what the chip thinks the ambient (room) temperature is.
Make sure the ATTiny85 chip is in the programmer and upload the sketch to the chip. Now, the chip is programmed for calibration.
Programming the Chip - Calibration for Too Hot (continued)
Now, move the chip from the programmer to the prototype bread board. Turn on the power supply. You should have a blinking green LED. You want to manually count the number of times that the green LED blinks from the time you power it on. When the red LED turns on, take the count at the time the red LED turned on and write it down. Take that number and, assuming you want to monitor "too hot", like I do, you subtract the count from START_TEMP. So, if you got a count of 7 green LED blinks, you would subtract that from START_TEMP which is 60. That gives you a number 53. Bear in mind that we are not actually measuring Celsius or Fahrenheit, we are just getting a number that the ATTiny85 understands as room temperature. If you have to, change the START_TEMP to another number higher or lower as needed and do the process again. Remember, if you forgot to count the green LED blinks or lost track, you can just unplug the power from the prototype bread board setup, and plug it back in again. Or press the little switch on the power supply that came with the board. Start your count again and write it down. If for any reason, the red LED never comes on, then try different START_TEMP numbers until it it does come on. To change START_TEMP, you will always need to move the chip from the prototype bread board environment to the programmer and back again as many times as you need. Also, if the red LED never comes on, you may want to check your wiring and make sure your power supply works.
Once you have figured out what ATTiny85 thinks is the ambient temperature, write it down. You will need it in the next sketch. It will be named CALIBRATION_TEMP, and you will need to edit the new sketch.
Programming ATTiny85 for Real Work
![ItWorksDark.png](/proxy/?url=https://content.instructables.com/F6L/37XG/IF4NA51H/F6L37XGIF4NA51H.png&filename=ItWorksDark.png)
![ItWorksYes.png](/proxy/?url=https://content.instructables.com/F2V/GXE4/IF4NA51A/F2VGXE4IF4NA51A.png&filename=ItWorksYes.png)
Now, download then ATTiny85monothermometer.ino sketch and enter it into the Arduino environment as a new sketch. Move the chip to the programmer, if you haven't done so already.
Edit the new sketch and change the value of #define CALIBRATED_TEMP 53 to match what you found out from calibration. This means you will probably change the number 53 to some other number. If you live in a very warm house, it will be higher, if you live environmentally sensibly--unlike me, unfortunately; you will have a lower value.
Upload that sketch and see what happens if you change the value in this section:
if (calcnumF > CALIBRATED_TEMP + 3)
{ // red LED blinks
analogWrite(outPin0, 255);
delay(25);
analogWrite(outPin0, 0);
delay(50);
}
} // end of loop()
There really is only one number you want to change and that is the number "3". If you want to monitor a temperature about 5 degrees warmer, you replace the 3 with a 5. If you want to monitor a temperature lower than ambient, you need to change the greater than ( > ) sign to the lower than ( < ) sign and change the plus to a minus.
Downloads
Beyond the Scope - a Few Comments
This instructable is very rudimentary and doesn't begin to show you want can be done with the ATTiny85 chip. I hope that the instructions are clear enough to get you started. I named it the way I did because this temperature monitor has only one function--to measure if something is too hot or too cold. It provides no numbers and only blinks if there is a problem.
Some things you could do with this project include:
- Make a permanent soldered board and an on-off switch for the power supply.
- Add a solenoid to the output port of ATTiny85 to do work like turn off a power supply or run a motor or turn on a ceiling fan.
- Add a buzzer.
- Connect it to the internet.
I'd like to mention that the reason I did the calibration like I did was due to the fact that the ATTiny85, as opposed to the Arduino family, does not have any way to do serial output. If it worked like the nano or the UNO or other Arduino boards, we could just read the output on the PC screen and find out with very little trouble what the ATTiny85 thinks ambient temperature is. Another way to calibrate it would be to simply measure the resistance across the thermistor and the 10K resistor, and enter those values into the sketch itself. The calibration should be fairly close, and may even be better related to the actual Fahrenheit or Celsius readings. Since I didn't really care what scale I was using, I didn't bother to do this.
There are probably a bunch of ways to calibrate this setup. I'd be interested to hear other ideas on this.I
I should also mention that you can remove the green LED after calibration. For this project, it is no longer needed. However, you may want to repurpose it and use it for an indicator for a different temperature range, for example, you may want to use that port to indicate that all is well. I'll leave it to you to write the code!
Power Supply for ATTiny85
![7805v_reg.png](/proxy/?url=https://content.instructables.com/FXO/GGD8/IF4NA3BF/FXOGGD8IF4NA3BF.png&filename=7805v_reg.png)
I didn't mention earlier that the ATTiny85 does not have a Vcc port to which you can attach a wide variety of batteries and do no harm. Most if not all Arduino products do have a Vcc port, so you can get by with a wide variety of power sources on those. Not so with the ATTiny85. The ATTiny85 works best at exactly 5 volts. So, if you make the project and attempt to run it with a 9 volt battery, it won't work. You need an inexpensive LM7805 voltage regulator to deliver exactly 5 volts to the chip. A couple of caveats:
- the cheapest LM7805 voltage regulator tends to run hot, even if nothing is happening. There is a heat sink on it, which should tell you right away that something is happening that you may not like. Heat means it is drawing current and the regulator itself shorten the battery life considerably.
- the LM7805 requires at least 7.5 volts input to get any output. Hence, a six volt battery will not work. Two in series would work. A 9 volt battery works fine as well. You may want to check out the LM2940 to see what its requirements are.
I've provided a rough shematic of a LM7805 circuit that would be suitable for this project. I, myself, did not use any capacitors, but maybe should.
Kids in Hot Car Challenge
![KidsInHotCar.png](/proxy/?url=https://content.instructables.com/F75/OM64/IF4NA40P/F75OM64IF4NA40P.png&filename=KidsInHotCar.png)
Just today I was reading a magazine in which an article mentioned the problem of kids (or animals) in hot cars. I thought right away,that this project could serve as a challenge to someone who would like to make a life-saving gadget. Bear in mind that about 40 children die in hot cars annually. Not a big number, but huge if you are the parent. The idea is to make a very simple expansion on input and output. You add a motion detector to one of the inputs (A2 or A3) and you add an alarm like a very loud buzzer or horn via solenoid to the one output that is left (pin #6 or #1 in the sketch). It's a simple matter of reading the input from the two sensors (motion sensor and temperature sensor). If the temperature is "too hot" and the motion sensor notes movement in the car, then the alarm should sound.
If your project saved one life, it would be worth the effort.
I would prefer that this idea not be commercialized. Keeping our kids alive should not be a money-making endeavor, even though society says it should. I don't agree.