DIY

Contact digital thermometer based on DS18B20 sensor

Contact digital thermometer based on DS18B20 sensor  Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor Recently, as homemade products, we see many examples of making non-contact thermometers. But such thermometers are less accurate and not universally applicable.
In this article, we will look at the manufacture of a contact thermometer. It can be used to measure the temperature of air, water, and other media and materials.
This is a very low power digital thermometer that runs on a single CR2032 battery for almost 140 days.
The thermometer has a funny function, to reset the readings you need to shake it like mercury.
Contact digital thermometer on DS18B20 sensor base Tools and materials: -ATTINY 85 microcontroller; -Programmer for ATTINY; -Piezo disks; -Arduino Nano; -PETG filament; -3D-printer; -Temperature sensor module; -OLED-display; -Battery 2032; -Battery holder CR2032; – Set of resistors; Step one: temperature sensor DS18B20
Let's start with the main part of the project – the temperature sensor.
There are different sensors depending on the accuracy, type and method of transferring data to the microcontroller. The DS18B20 was chosen by the master because, it is very well designed to measure temperature from an object, and only one wire is required to read data from this sensor. The probe itself at the sensor is enclosed in a metal case. On the plus side, it is supported by many Arduino libraries and consumes only 5 μA in sleep mode.
Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269264_1-6.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Step two: connecting DS18B20
Any microcontroller can be used to connect the sensor, because the sensor uses a protocol that is completely software dependent, not hardware dependent. All it takes is one GPIO pin of the microcontroller.
For the sake of example, the wizard uses Nodemcu. Connecting the circuit is very simple. Connect the power supply, i.e. red wire to + 3.3V, black wire to ground, and yellow data wire to D2 on the NodeMCU. A 4.7k resistor must be installed between 3.3V and the data pin. Otherwise, the microcontroller will not read data from the sensor.
Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269313_1-8.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor  Contact digital thermometer based on DS18B20 sensor Step three: testing DS18B20
The Nodemcu can now be programmed. Open Arduino IDE and load Dallas temperature sensors library and one wire library. Moving on to an example, we open a simple example of a temperature sensor. In the code, we change the connection contact to our own. In this case, this is pin D2, which is GPIO 4.
Compile and load the code.
After loading the code, open the serial port monitor. It takes some time to measure the temperature. The wizard set 15 seconds in the code. For more accurate readings, you need to increase this time.
Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269288_1-13.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269289_1-15.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269262_1-17.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Step four: OLED display
An OLED display is required to display the temperature.
Master used 0.91 inch OLED display with 4 pins. Connecting the following
SCL display to D1
SDA display to D2
to power the display, connect VCC and GND of the module to 3.3 V and GND NodeMCU.
 Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269347_1-20.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269297_1-22.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Step five: OLED testing
To check if the OLED display is working, go to the Arduino development environment and load the Adafruit SSD1306 library from the Library Manager [Sketch – & gt; include library – & gt; Manage Library – & gt; Adafruit SSD1306]].
Open the Hardware_test.ino sketch, Compile and upload the code to Nodemcu. Everything is ready, now you can read the temperature and display it on the OLED display.
Hardware_test.ino
Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269306_1-24.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Step six: piezo sensor
By default, the thermometer reads the temperature continuously. The master wanted the value to be reset. You can do this with a simple button, but by design it should be shaken like a mercury thermometer.
For this purpose, he decided to install a piezoelectric element. This is a pretty interesting sensor. It contains a small crystal between two metal plates. When pressure is applied to this crystal, the sensor emits a small electrical current. So, you can build a very simple circuit to measure this current and perform a task based on the readings.
Contact digital thermometer based on DS18B20 sensor  Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor The scheme is very simple. You need to make a voltage divider using a 5.6 kΩ resistor with a piezo sensor. Then connect to pin A0 of NodeMCU. For the code you need to do an analog read and display it on a serial monitor.
Changes in values ​​can be seen as different pressures are applied to the sensor. You need to calculate the threshold value and add it to the code. When the value matches the specified value, the value is reset and the temperature reading starts again.
This works in test mode (see the code in the previous steps), but this is not the logic that will be used with the sensors in the final assembly.
< a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269333_1-28.jpg" rel = "prettyPhoto">Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269297_1-29.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269302_1-31.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269325_1-33.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Step seven: finding an alternative to the microcontroller
The task is to make the whole circuit work with only one CR2032 battery. But one battery (3.3 V/210 mAh) will not even be powerful enough to run an Arduino UNO/Nano or NodeMCU (ESP8266), and you also need to power the entire circuit with a temperature sensor, a piezodisk and a display.
So, you need an alternative a microcontroller that does not require a lot of power and can also control the display, temperature sensor and piezoelectric element with this single cell. And there is such a microcontroller. This is ATTINY 85.
Contact digital thermometer based on DS18B20 sensor  Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor This is an 8-bit microcontroller with 8 pins and has all the functions that are exactly needed in this assembly: I2C for driving an OLED display, an input contact for reading temperature readings, and an analog input for reading piezoelectric elements. Most importantly, all of this can be done with a single 3.3V cell.
But it also has its drawbacks. It's more difficult to program, the memory is limited to 8KB and the RAM is only 512 bytes. He also has only 5 useful contacts. In any case, there is no other alternative yet.
Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269318_1-38.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor Step eighth: programming ATTINY 85
How to program this attiny 85? This requires an arduino that supports ISP, both arduino nano and uno can be used. The wizard will use nano as an example to show how to program this microcontroller.
The first step is to prepare the arduino. Just connect the board to your computer and open the arduino IDE. Now go to the examples and open the Arduino ISP example. Just compile and upload this code to arduino nano. Now we need to connect arduino nano and attiny 85. Connect VCC power to 3.3V and ground. Then we connect D13 to 7, D12 to 6, D11 to 5 and finally D10 to 1. Install an electrolytic capacitor between the arduino nano reset and ground.
Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269352_1-41.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269331_1-43.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269302_1-45.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Step nine: testing ATTINY 85
Once the connection is established, open the Arduino IDE, go to settings and paste this link. [https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json] This will allow the Arduino IDE to load the attiny core.
Next, go to the board manager. Next, you need to find attiny and install. Board – attiny 85, frequency – 8 MHz and finally, install the port to which the Arduino Nano is connected. Once this setup is complete, go to tools and click on the recording loader.
This completes the programming setup for the ATTINY 85. You can test it by running a simple sketch of the LED blinking. We connect the LED to pin 3 of the ATTINY 85, then write a sketch of the blinking. To control this pin you need to change the input, in this case the master connected the LED to GPIO D4, which is pin 3.
Then make sure the ATTINTY 85 settings are selected in the tools and upload the code.
Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269334_1-46.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor  Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor  Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor Step ten: checking the power consumption of the circuit
Before using other components, check if there is enough current supplied by this single 3V cell to drive all components.
The CR2032 cell has a capacity of 210 mAh and a maximum current consumption of 30 mA. The Attiny 85 needs less than 4mA for power, the DS18B20 temperature sensor draws 1.5mA when active, and finally, the display needs 20mA when displaying all pixels on the screen. Collectively, this is still less than 30 mA peak current consumption.
Contact digital thermometer based on DS18B20 sensor Step eleventh: breadboard
To test the operation of the device, the wizard assembles a circuit on a breadboard. The complete schematic diagram and code are available on Github.
 Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor  Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor While coding, he added some splash screens.

 OzOled.clearDisplay (); OzOled.printString (& # 34; ATTINY 85 & # 34;, 0,0); OzOled.printString (& # 34; Thermometer! & # 34;, 0.2); delay (5000); OzOled.clearDisplay (); OzOled.printString (& # 34; Measuring in & # 34;, 0,0); OzOled.printString (& # 34; 3 second & # 34;, 0.2); delay (3000); OzOled.clearDisplay (); OzOled.printString (& # 34; Measuring ... & # 34;, 0,2); lastMeausreTime = millis ();  

After switching on the device started working normally. After testing the circuit with a multimeter, it was found that the device consumes an average of 6.5 mA before and during temperature measurement and peaks up to 11 mA within a few seconds when displaying temperature data. In this mode, the circuit consumes 60 μA.
At its current setting, it can be turned on for almost 134 days, 100 times a day. The device needs 25 seconds from the screen saver to the end of the temperature measurement. If you remove unnecessary delays and reduce the frequency to 1 MHz, you can increase the period for another 4-5 days with one battery.
 Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor  Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor Step twelfth: assembling the circuit on the board
Next, the master cuts out the perforated board as in the photo below. Assembles a circuit on the board. Instead of using a DIP chip, it mounts the SMD version. This will reduce the size of the device with the same parameters.
All other parts are the same as on the breadboard.
Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269276_1-63.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269355_1-65.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269359_1-67.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor To download the code, you need to temporarily solder the jumpers to the [1,4,5,6,7,8] pins of the ATTINY 85 (SMD) and connect these pins to the Arduino Nano in the same way as in step 10. Then you need to change the clock frequency to 1Mhz in the Arduino IDE and download the code.
Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269357_1-70.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor After lowering the frequency to 1 MHz, in contrast to 8 MHz when testing with a breadboard circuit, power consumption was halved. On average, the circuit consumes less than 3 mA during operation and 58 μA during sleep.
It is true that lowering the speed to 1 MHz leads to slower screen refresh, but this is not a big problem.
Contact digital thermometer based on DS18B20 sensor  Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor  Contact digital thermometer based on DS18B20 sensor Step Thirteen: 3D Printing
Wizard designed the model in fusion 360.
You can download the files from the Github repository. When printing, the wizard uses the following settings: PETG filament with a layer height of 0.2 mm, nozzle temperature 245 ° C, heated bed temperature 70 ° C and speed 40 mm/s.
Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269286_1-82.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269283_1-84.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Step fourteen: assembly
Assembly is very simple and intuitive. Before assembly, you need to apply a little varnish to the soldering points. This is necessary so that the piezodisk does not close the circuit.
Then we install everything in the case, connect the two halves and fix it with a ring.
< img class = "aligncenter" alt = "Contact digital thermometer based on DS18B20 sensor" src = "https://usamodelkina.ru/uploads/posts/2021-05/1622269329_1-85.jpg"/> Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269302_1-87.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor < a href = "https://usamodelkina.ru/uploads/posts/2021-05/1622269316_1-89.jpg" rel = "prettyPhoto"> Contact digital thermometer based on DS18B20 sensor Everything is ready. According to the results, the master has several comments.
It should be understood that this is by no means a suitable replacement for a commercial thermometer. This is just a fun little project that will teach you a little about electronics.
There are a few extras that can be made to improve the design.
First, the case design is not bad, but not very durable.
– Second, longer measurement time. I cut the time just for the sake of the video to get a more accurate result. Try changing the settings to 45 seconds + in the code.
Finally, you can make a custom PCB with all the well-placed components.
Contact digital thermometer based on DS18B20 sensor  Contact digital thermometer based on DS18B20 sensor Contact digital thermometer based on DS18B20 sensor The whole assembly process and testing the device can be viewed in the video.

Source:

usamodelkina.ru

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button