Software apps and online services
Hand tools and fabrication machines
This might seem totally useless, considering how advance current technology can be and you might even be like "Tsk! a Thermometer?"
But there is a lot of experiment based on temperature (water temperature, room temperature, etc) so digital thermometer becomes a key instrument for temperature measurement considering the other alternatives and cost/performance ratio. It is used from measuring temperature of human body to measuring temperature of chemical substances. So, In this tutorial we'll build a digital thermometer which runs on a single CR2032 cell for almost 140days! (In makers term that is amazing!) and also run through optimizing the code and circuit for running in low power. Just to add some nostalgic moment, I used the piezo sensor to reset the thermometer that people usual do with a Mercury-in-glass thermometer.
So, enough with the story grab your supplies and let's get started.Supplies
These are the list of products which can help you do this project with ease
- ATTINY 85 : https://amzn.to/3bB8t8p
- ATTINY dev board : https://amzn.to/3bC1cp3
- Piezo : https://amzn.to/2S6yo0V
- Arduino Nano : https://amzn.to/3tY8I3E
- PETG filament : https://amzn.to/3w6bB46
- DS18B20 : https://amzn.to/3ylGRy0
- OLED display : https://amzn.to/2VcEATc
- CR2032 : https://amzn.to/3ysFiOX
- CR2032 battery holder : https://amzn.to/3fsFhl8
- Resistor Kit : https://amzn.to/3frj4nx
- 3d Printer : https://amzn.to/3trVWKw
- Printer Upgrades : https://amzn.to/3hbK3Ga
Let's start with the core part of the project, the temperature sensor.
There are different sensors to choose from, based on accuracy, type and how they transfer the data to the microcontroller. but I chose the DS18B20, because it’s very well designed to read temperature from an external object, and it requires only one wire to read the data from this sensor. Also this is better for this project because of the metal probe, or it would be difficult to make a custom metal probe to make the contact point and the other major reasons are, the sensor is supported by a variety of libraries with Arduino and consumes only 5uA when it’s on sleep mode.Step 2: Interfacing DS18B20 With a Microcontroller
To interface this. You can use any microcontroller because the sensor uses a protocol called one wire which is totally dependent on the software rather than the hardware, all you need is a single GPIO pin of the microcontroller.
Just for the sake of this example I will use the Nodemcu. The circuit connection is easy as it gets. Connect the power supply i.e red wire to +3.3V, black wire to ground and the yellow data wire to D2 of the NodeMCU, that’s it. finally Don't forget this important step, add a 4.7k pull resistor between the 3.3v and the data pin. If not, the microcontroller won’t read the data from the sensor.Step 3: Testing DS18B20
Now we can program the Nodemcu, Just go to your Arduino IDE and download the Dallas temperature sensor library and one wire library. Once that’s been installed. Go to example and open the simple temperature sensor example and change the pin wherever the sensor is connected too, in my case it’s pin D2 which is GPIO 4.
Compile and upload the code.
Once, the code is uploaded you can open the serial monitor. You see the sensor data is shown here, but this DS18B20 sensor doesn’t instantly show accurate temperature readings same as commercial thermometers, it takes a while to settle down at the correct value, you can also see how this affects in the final build. So, for the sake of this experiment, I have reduced it to the measurement time to 15 seconds. But in case you need a better accuracy you can always increase the measurement time in the code.Step 4: Interfacing 128X32 OLED Display
As we can now read the temperature, let’s try to display this on an OLED display. In most of my previous tutorials I have used this, if you like to learn more check out this links:
I used a 0.91 inch OLED display with 4 pins, connect the SCL of the display to D1, and the SDA of the display to D2, because D1 and D2 are the default I2C pins of the NodeMCU and to power the display connect the VCC and ground of the module to 3.3v and ground of the NodeMCU.Step 5: Testing the OLED
To test if the OLED display is working or not, go to your Arduino IDE and download the Adafruit SSD1306 library from the library manager.
[Go to Sketch -> include library -> Manage Library -> Adafruit SSD1306]
Now open the sketch Hardware_test.ino, compile and upload the code to your Nodemcu. Now with that we can read the temperature and show it on the OLED display. Everything working pretty great!Step 6: Peizo Sensor
But the current setup reads the sensor value continuously. I would rather want this to stop reading the temperature after a while and restart when we give some input. For this you can use a button but in the intro you would have seen the thermometer is triggered by slamming. This was simpler to implement than you expect. I neither used complicated sensors nor complex coding. Instead I used a very simple piezo sensor.
This is quite a little interesting sensor. This contains a small crystal between 2 metallic plates, when pressure is applied to this crystal, the sensor outputs a small electric current. So, we can build a very simple circuit to measure this current and do some task based on the reading.Step 7: Interfacing and Testing Peizo Sensor
Again the circuit is very simple, just build a voltage divider using the 5.6kresistor with the piezo sensor. Then connect the junction to the pin A0 of the NodeMCU. For the code just do an analog read and display it on the serial monitor.
You can see the value changes as we apply varying pressure to the sensor. Now we add this to our existing circuit and add a threshold to the sensor value inside the code, So wherever the piezo hits this value the code will reset and the temperature reading will start again. (Upload the Hardware_test.ino file from previous step)
You can see this works exactly as we expected! But this is not the same logic we will use with sensors in the final build, but a little different, which we’ll discuss more on that later.Step 8: Finding a Microcontroller Alternative
Let’s say we want the whole circuit to work with just this single CR2032 cell. It would be close to impossible because this single cell (3.3V / 210mah) won’t even be powerful enough to run Arduino UNO/Nano nor the NodeMCU(ESP8266) so there is no way it will run the entire circuit with temperature sensor, piezo and the display.
We need an alternative microcontroller which doesn’t need much power as well as can run the display, temperature sensor and the piezo with this single cell. This might be too much to ask, but lucky there is a microcontroller which can do all this! Meet the ATTINY 85.Step 9: ATTINY 85
This is an 8 bit microcontroller with 8 pins and has all the features that we exactly need, a I2C to drive the OLED display, an input pin to read the temperature reading and also analog input to read the piezo reading. Mostly importantly this can do all this while being powered by just a single 3.3v cell.
But it comes with it’s own disadvantages. It's slightly complicated to program, the storage is limited to 8kb and ram is just 512 bytes and also it has just 5 usable pins. We can use the reset pin as GPIO but it just makes things way more complicated than it was initially. So, deciding the microcontroller was purely based on a few simple questions: Is that enough? Can we fit everything in ? Do I have it? Can I program it? In my case, it’s a big YES!Step 10: Interfacing ATTINY 85
So, let me show you how to program this attiny 85, for this we need an arduino which supports ISP, both arduino nano or uno can be used. I will be using the nano as an example to show how to program this microcontroller.
First step is to prepare the arduino. Just connect the board to your computer and open the arduino IDE. Now, go to examples and open the Arduino ISP example. Just compile and upload this code to your arduino nano. That’s all the setup we need, next start with the connection between the arduino nano and the attiny 85, connect the power VCC to 3.3v and ground to ground. Then connect pin D13 to pin7, pinD12 to pin6, pinD11 to pin5 and finally pinD10 to pin1. And add an electrolytic capacitor between arduino nano reset and ground. If you like to follow along you can check the link in the description for the circuit diagram for the connection.Step 11: Testing ATTINY 85
Once the connection is done, open the Arduino IDE, go to preference and paste this link. [https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json] This will let the Arduino IDE to download attiny core.
Go to the board manager and search for attiny, and install the board. Now change the board, processor to attiny 85, clock to 8Mhz and finally the port to where Arduino Nano is connected. Once this setup is done go to tools and click on burn bootloader.
This completes the programming setup for the ATTINY 85. We can test this by running a simple blink sketch. Connect a led on pin 3 of the 85 then write and modify the blink sketch to drive that pin in our case I have connected the LED to GPIO D4 which is pin 3.
Then make sure the ATTINTY 85 settings are selected under tools and upload the code.
And there you go, successfully programmed the ATTINY85!Step 12: Verify Power Consumption of the Circuit
Before diving into using other components with this let’s just verify if the current supplied by this single 3V cell is enough to drive all the components.
So the cell I’m using is CR2032. This cell has a capacity of 210mAh, and a peak current draw of 30 mA. So we have to keep everything under atleast 20mA to work perfectly.
ATTINY 85 needs little less than 4mA [datasheet] running at 3.3V at 8Mhz and the temperature sensor DS18B20 needs 1.5mA [datasheet] while it’s reading the temperature and the oled display needs 20mA [datasheet] when displaying all the pixels on the screen. Combined all this together we are still less than the peak current draw 30mA.Step 13: Putting Everything Together
we are kind of sure that everything will work with the cell, I built the entire circuit in the breadboard. The complete circuit diagram and the code will be available on my Github.
While coding this, I made sure I added a few delays in the code, just to add a few splash screens, if you don’t like you can totally ignore it by commenting the below lines in the code.
Step 14: Testing the Circuit
OzOled.printString(" ATTINY 85 ",0,0);
OzOled.printString(" Measuring in",0,0);
OzOled.printString(" 3 second ",0,2);
lastMeausreTime = millis();
Once I power this, you can see the device starts running. I have also attached my multimeter to see how much current is consumed by the circuit. It averagely consumes 6.5mA before and while measuring the temperature, and it peaks to 11mA for a few seconds while displaying the temperature data. I have also implemented deep sleep, to reduce the battery consumption significantly. You can see the screen turns off and the circuit goes to deep sleep. Here the circuit consumes less than 60uA. Which sounds great!
With the current setup we can run this for almost 134days, 100 times a day! The device takes 25 seconds from the splash screen to the end of temperature measurement. If I remove the unnecessary delays and decrease the clock to 1Mhz we can squeeze in 4-5 more days with a single cell. Which we’ll try after building the circuit on the PCB.Step 15: Building a Perfboard Circuit
So, enough with theory and math, let's build the circuit in a perfboard!
Start off with a perfboard, the shape might look a little odd but this is totally needed design, because later when we start designing the case we need to reduce the size as much as possible. Instead of using the DIP IC i’m going for the SMD version, This shouldn’t affect the performance greatly and at the same time it should give us a very minimal footprint! Other than this, the rest of the circuit is the same as what we did in the breadboard.Step 16: Programming Attiny 85 on Perfboard
To upload the code, solder jumper wires temporarily to pins[1, 4, 5, 6, 7, 8] of ATTINY 85 (SMD) and connect these pins to Arduino Nano same as in the Step 10. Then change the clock speed to 1Mhz in the Arduino IDE and upload the code just like we did in Step 11.Step 17: Testing the Perfboard Circuit
This kind of looks weird now, but once we design the case it should look pretty good! But before that let's see how much current does this circuit consume, because I have reduced the clock speed to 1Mhz unlike the 8Mhz when tested with the breadboard circuit.
This seems pretty good! We have cut the circuit power consumption by half! It just averagely takes less than 3mA during operation and takes 58uA during sleep. So, with this setup theoretically we can use this for approximately 140days! But in practice it would be quite less. Still this great considering everything was off the shelf parts and no major modification done to the circuit.
Reducing the speed 1Mhz might cause a slower screen update, which you could see in the video but I’m really happy how this turned out to be and I don't think slower screen update is a big issue. So, let’s finish this project now!Step 18: Printing PCBs With PCBWay
You can use the final build circuit diagram to make a polished version of this device, but due to the simplicity I'm not going to print a PCB for this project now, But if you do want me to design one and make a video on that I would be happy to do that!
I thank PCB way for sponsoring my projects, If you need custom PCBs for your project, they offer 10 custom PCBs for as low as 5$ and a variety of customization that you can choose for your PCB, like the colour of the solder mask, silk layer and surface finish and on your first order you get a coupon of 5$!
Link : https://www.pcbway.com/
[The blue PCB are for the new upcoming projects, so stayed tuned for more XD]Step 19: 3D Model - 3D Printing
I have designed the model in fusion 360, it is not complicated as it looks.
if you like the design you can check out Github repo or download the STL files at the end of this step. I have the STL files along with the circuit diagram and the code. Okay, so the model is ready, Let’s print it! I’m using PETG with 0.2mm layer height, 245C nozzle temperature, 70C heat bed temperature and 40mm/s speed. Even with slower speed it was harder for me to work with PETG and caused a lot of stringing in the model. If you guys have any tips/tricks drop them below!Step 20: Assembly
Assembly can't be simpler than this. Just use a little bit of the glue or insulation on the solder joint so the piezo doesn’t short the circuit. Then place the circuit on the bottom case and close the top case. Now use the ring to close the other side.
That’s it we are done!Step 21: Final Thoughts!
You need to understand this is no way a suitable replacement for a commercial thermometer. This is just a fun little project where you learn about electronics and other DIY stuff.
And there are plenty of upgrades you can do to improve the project. First, I like the case design but it’s not very sturdy so a better design approach would be great! Secondly a longer measure time, as I said I reduced the time just for the sake of the video to get a more accurate result. Try changing it 45seconds+ in the code. And finally a proper PCB with all the components are efficiently arranged!
So, if you like the video so far don’t forget to hit the like button and make sure you are subscribed to the channel so you don’t miss any upcoming videos, Until then see you in the next video!