DIY Temperature Logger With STM32F103, MicroSD Card and DS18B20 Using Atmega

DIY Temperature Logger

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.

DIY Temperature Logger










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.

Step 1: Gathering Parts

Gathering Parts (1)

  • 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.

Step 2: (Optional) Parts for End Product

Parts for End Product












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.

Step 3: Prototype













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.

Step 4: (Optional) Make a Finished Version of Your Device.

Finished Version of Your Device.












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.

Leave a Comment

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