Maker Pro

Make a Temperature-Based Arduino Automatic Door Lock

June 23, 2017 by Ryan Jones

This device will cause a solenoid to either lock or unlock a door based on the temperature outside.


In this project, you'll learn about DFN soldering, using a temperature sensor, and using a solenoid. This device takes the temperature and will cause a solenoid to either lock or unlock a door based on the temperature outside. It also plays thematic music for the weather outside. This project was originally made in the winter, but with some changes in the code, it can work for the summertime. Check it out in the video below and read along to see how it works!


Groundhog Day was approaching so I thought it would be fun to make a thematic project for the season. The Punxsutawney 5000 will lock you in the house if it's too cold outside so you don't emerge until it is warm enough. With some Tupperware, some components, and an Arduino, I got started on my smart door.

I wanted to give DFN soldering a try, so I used a surface mount STS3x temperature sensor, which provides I2C communication protocol. The solenoid was mounted on the outside of the door, so it can really trap you inside. It does, however, have a threshold value that can be lowered so you don't get trapped forever.

Attempting to mount the enclosure to the "door"

The DFN Soldering

The Sensirion STS3x temperature sensor is a pretty small component, with a footprint of 2.5mm x 2.5mm, so needless to say it needed to be placed on a breakout board for use. I ordered a standard SMD breakout adapter that provides accurate pin spacing for breadboard use to make my breakout board. With no reflow oven and just a single component to mount, I decided to use some solder paste and a standard heat gun to surface mount the device. This was actually my first time DFN soldering and it only took me a few tries to get it right. It was easier than I thought it would be.

The solder paste should be spread on each of the land terminals of the breakout board, as well the thermal pad in the center. The pads are very small and the process will probably get a little sloppy, but there's not much else you can do with the tools at hand. Fortunately enough, as you apply heat, the solder naturally becomes smooth and neat and should take to each of the individual terminals. Place the sensor chip in the center of the breakout board. Apply heat until you see the solder become molten.

Solder paste, tweezers, breakout board, sensor, finger

When you are finished, grab a multimeter and run a continuity test to ensure that none of the terminals are shorted together. If some are, try heating up the sensor chip again and resetting it with a pair of tweezers. When the component is set, wait for it to cool and then flip it over to begin placing the breakout pins on the board.

The bottom of the PCB has large terminal pads. The kit includes 90º breakout pins as well as a PCB spacer that is used to properly space the pins across from one another. Break off the number of pins needed for each side and place the legs through the PCB spacer. Then align the 90º knee against the terminal pads and solder on using a traditional soldering iron and rosin solder. Then, boom, you have yourself a breakout board! Let's get to testing!

The bottom of the pins and the terminal pads

The bottom of the breakout PCB

Getting It Going

The STS3X sensor can be hooked up a few different ways—you can view the datasheet for more information. With my configuration, I decided to use "Single Shot Mode" for sake of simplicity. It should be noted that "through appropriate wiring of the ADDR pin, the I2C address can be selected" (datasheet). By connecting my ADDR pin to ground, the address becomes "0x4A". If I had instead decided to connect the pin to a logic high signal, the address would then become "0x4B".

With that in mind, I modeled my circuit after the example found in the datasheet. You will notice that ALERT and nRESET were left floating. SDA and SCL are plugged into the Arduino Uno's A4 and A5 pins, which can be used to communicate over I
2C to the sensor. To do so, we will need to include the Arduino Wire library in our sketch, which can be found below. 

When you are confident that everything is wired properly, try running a simple "I2C Scanner" sketch, which will detect any connected I2C devices and display their address. If the address the serial monitor reads matches your sensor's, you have wired it successfully!

Temperature Sensor Circuit

The solenoid circuit is pretty straightforward and, if you have been keeping up with this series, you can do this with your eyes closed (please don't!). Previously, we have used a relay circuit to control high-current loads—but, with the right transistor, we can do away with the relay. My solenoid here draws an average 500mA current. By using the TIP120 transistor, which can handle a load greater than 500mA, we can safely use the transistor as a switch to connect power to the solenoid.

My circuit is controlled by a logic high signal sent from digital pin 2 whenever the sensor's temperature value breaks our threshold. As far as the music, I included additional Digital Write statements which send a 5V logic signal to control the Wav Trigger. If you'd like more information on it, check out this great tutorial!

Solenoid Circuit

Getting the Temperature

Specific details for I2C communication can be found within the datasheet and vary for different uses. As stated, I used Single Shot mode and was able to accomplish simple communication using the sketch below (see  "void gettemp(){" for specific protocol).

First, we begin transmission with the sensor and send two bytes to it. When the sensor receives these bytes, it spits out a value that can be read and then converted by the Arduino.

We use the 'Wire.requestFrom" and request three bytes from the sensor to do this. The first two bytes indicate temperature and the third is a checksum that is used to verify the validity of the numbers. We can use the equation included in the datasheet to convert these numbers into a standard temperature. S(t) denotes the raw sensor output for temperature (datasheet).

The equation

Now, open your Serial Monitor and you should see accurate temperature readings! In the first part of the loop, I included a simple If/Else statement to control the solenoid from the sensor's readings. If you would like to change the temperature threshold, simply adjust the number within that statement!

You should now have the components ready to make your own smart door! Find the nearest door in sight and attach it all! Don't forget to include a kill switch so you don't get locked inside for good!


Ryan Jones

Start my career as an Audio Engineer, now turned professional maker!

Related Content


You May Also Like