DIY Temperature Logger With STM32F103, MicroSD Card and DS18B20
by headcra6 in Circuits > Microcontrollers
14378 Views, 23 Favorites, 0 Comments
DIY Temperature Logger With STM32F103, MicroSD Card and DS18B20
![K-log: DIY Temperature logger with STM32F103, microSD card and DS18B20](/proxy/?url=https://content.instructables.com/F3H/ZG8U/JC2YBA43/F3HZG8UJC2YBA43.jpg&filename=K-log: DIY Temperature logger with STM32F103, microSD card and DS18B20)
![IMG_6894.JPG](/proxy/?url=https://content.instructables.com/FHJ/V6NS/JC2YBLWM/FHJV6NSJC2YBLWM.jpg&filename=IMG_6894.JPG)
Hi everyone!
I'm currently building a temperature logger for some guys doing a research in biology. Tried to make it as small as possible, with temperature sensor that can be crammed in small space.
Since the first revision slash prototype of the device was incredibly simple to make and featured easily procured parts, I decided to write up every step of making the device.
The detailed guide with sources and schematics can be found on my blog, I'll be publishing slightly abridged version here.
Gathering Parts
![DS18B20.jpg](/proxy/?url=https://content.instructables.com/FCC/VICV/JC2YB9WF/FCCVICVJC2YB9WF.jpg&filename=DS18B20.jpg)
![ds18b20-waterproof.jpg](/proxy/?url=https://content.instructables.com/FTZ/NWR3/JC2YB9X1/FTZNWR3JC2YB9X1.jpg&filename=ds18b20-waterproof.jpg)
![STM32_Blue_Pill_perspective.jpg](/proxy/?url=https://content.instructables.com/FVN/PWIC/JC2YB9ZL/FVNPWICJC2YB9ZL.jpg&filename=STM32_Blue_Pill_perspective.jpg)
![st-link-v2-800x800.jpg](/proxy/?url=https://content.instructables.com/FEA/2YJQ/JC2YB9ZI/FEA2YJQJC2YB9ZI.jpg&filename=st-link-v2-800x800.jpg)
![1.jpg](/proxy/?url=https://content.instructables.com/FIQ/5CK9/JC2YB9UM/FIQ5CK9JC2YB9UM.jpg&filename=1.jpg)
![SKU122168a.JPG](/proxy/?url=https://content.instructables.com/FDH/OKRR/JC2YB9YX/FDHOKRRJC2YB9YX.jpg&filename=SKU122168a.JPG)
![1200px-A_few_Jumper_Wires.jpg](/proxy/?url=https://content.instructables.com/F15/7XVP/JC2YB9V7/F157XVPJC2YB9V7.jpg&filename=1200px-A_few_Jumper_Wires.jpg)
![45040-dscn0624.jpg](/proxy/?url=https://content.instructables.com/FKZ/VG9A/JC2YB9VT/FKZVG9AJC2YB9VT.jpg&filename=45040-dscn0624.jpg)
- DS18B20 temperature sensor. You can get one in metal package, or a bare IC. I used the latter, because I hope to come up with something smaller than this steel cylinder encasing it.
- Blue pill. Inexpensive and versatile board with STM32F103C8T6 as its core.
- STLink v2 programmer. You'll need it to upload your code to STM32 and debug it.
- microSD memory card + adapter for it. We'll convert microSD to SD adapter into microSD to microcontroller one. You can omit this part and just opt for an adapter board for microcontrollers (especially if you don't want to go further than a prototype) - less soldering, but maybe less fun.
- Pushbutton, some jumper wires (these or these), one 4.7k resistor.
(Optional) Parts for End Product
![swithcces.jpg](/proxy/?url=https://content.instructables.com/FI1/QPHF/JC2YBA03/FI1QPHFJC2YBA03.jpg&filename=swithcces.jpg)
![connector_for_temp.jpg](/proxy/?url=https://content.instructables.com/FZA/0CO3/JC2YB9WE/FZA0CO3JC2YB9WE.jpg&filename=connector_for_temp.jpg)
![sizes_button_cells.jpg](/proxy/?url=https://content.instructables.com/F3E/Z6OO/JC2YB9YW/F3EZ6OOJC2YB9YW.jpg&filename=sizes_button_cells.jpg)
![3pin.jpeg](/proxy/?url=https://content.instructables.com/FED/RNUS/JC2YB9UX/FEDRNUSJC2YB9UX.jpg&filename=3pin.jpeg)
![IMG_6808.JPG](/proxy/?url=https://content.instructables.com/FDQ/3PKH/JC2YB9YF/FDQ3PKHJC2YB9YF.jpg&filename=IMG_6808.JPG)
![IMG_6800.JPG](/proxy/?url=https://content.instructables.com/FXQ/AOKT/JC2YB9X3/FXQAOKTJC2YB9X3.jpg&filename=IMG_6800.JPG)
The list of parts in the previous step is only good for a prototype. If you want to build something you can give to other people without being scared for the life of your... device, then you'll additionally need:
- Two toggle or rocker switches (both SPST - one to switch operating mode and another as a power switch)
- Enclosure-mount connector for temperature sensor. I used XS9K4P: a circular polarized 4-pin connector. Just make sure it can't be plugged any other than the right way (make it polarized, in other words). This connector is pure awesomeness. It looks like the plug is locked into place after being screwed into receptacle, but it is actually self-locking. You have to pull the outer 'collar' part of a plug to unlock it, otherwise it won't budge.
- Coin cell battery. How big depends on what kind of autonomous time you expect to get from this logger, I'm using the beefy-looking CR2477 (25mm diameter, 7mm height, 1Ah on average) to get as much as years. The standard CR2032 (20mm diameter, 3mm height, 220mAh on average) won't last as long, but it's encountered more frequently in daily life.
- Polarized 3-pin connector to configure temperature logger via UART. I'm going to be using old familiar Molex KK series pin header that everyone knows simply as 'motherboard fan connector'.
- Load switch IC with at least one channel. You're going to need it to switch off your memory card to conserve power. DS18B20 consumes so little current it can be switched from IO pin. Load switch is not a part that every tinkerer has in their part bin, but luckily I had one that I ordered a long time ago as a sample from Texas Instruments (TSP22960). Well, your time to shine's finally come, little buddy, after years of laying in a dusty box! You can order one from distributor like Mouser, Farnell, etc..Miscellania like standoffs and tiny screws and 3d-printed enclosure.
I'll just leave the picture of all the parts I had (excluding the lid of the enclosure with indicator LED and mode switch associated with it) prior to assembling first revision of this device.
Prototype
![IMG_6712.JPG](/proxy/?url=https://content.instructables.com/FDP/QB0Z/JC2YBA04/FDPQB0ZJC2YBA04.jpg&filename=IMG_6712.JPG)
![temp_logger_poc_schematic.png](/proxy/?url=https://content.instructables.com/FFO/N362/JC2YBKCU/FFON362JC2YBKCU.png&filename=temp_logger_poc_schematic.png)
With a device as (relatively) complex as this one, you gotta prototype to make sure all this technology can integrate. Temperature logger will involve FAT filesystem access via SPI, temperature sensor access via OneWire, usage of real-time clock with battery backup.
Got to admit, I never even as much as dabbled in any of those before, at least on STM microcontrollers.
Let's cobble up something that can read temperature and write it to memory card upon a click of a pushbutton - using only jumper wires! Why solder something as impermanent as this?
Prototype code can be found on my blog here.
(Optional) Make a Finished Version of Your Device.
![IMG_6894.JPG](/proxy/?url=https://content.instructables.com/FJN/UYS2/JC2YBA05/FJNUYS2JC2YBA05.jpg&filename=IMG_6894.JPG)
![temp_logger_schematic.png](/proxy/?url=https://content.instructables.com/FEH/LEH6/JC2YBLJE/FEHLEH6JC2YBLJE.png&filename=temp_logger_schematic.png)
Whoo, this prototype building was really educational. Hopefully it taught you something about these little inexpensive Bluepill boards with STM32 microcontrollers, their power saving features and so on. You can stop it here, or you can build a more finished version of this device. To do that, you'll have to print out the enclosure and solder your device together. For the schematics and finished device's code, as well as STL models for the enclosure, check out my blog.
Next revision will feature a PCB, serial flash memory instead of microSD and USB configuration instead of Serial.
Thank you for reading this far, and leave your comments and suggestions on this build! Also make sure to post your builds of this simple temperature logger here!