Lock Yourself Inside for the Winter with an Arduino and Sensirion Temper
2017-02-27 | By All About Circuits
License: See Original Project Arduino
No more waiting around for the groundhog. This device will keep you inside until springtime arrives with the help of your favorite songs, especially if you like Foreigner!
Why?
With springtime approaching, the weather outside can be all over place, and the temperature for your city given by your smartphone isn’t always accurate for your home. Why not have an accurate readout that can turn against you and lock you inside for eternity, like in "2001: A Space Odyssey?" Ryan didn’t have enough time to make a space station, so instead he used a solenoid to lock the door. He also only added two songs to the sound card, hence the Foreigner.
The STS3x Temperature Sensor provided a standard I2C communication protocol and gave Ryan an excuse to try some DFN soldering while he was at it. By mounting the solenoid on the outside of the door, he his creation could literally lock him inside all Winter. Luckily, he included a threshold value that can be lowered to a desired temperature, so you don't have to hibernate with the bears until springtime unless you really want to.
Bill of Materials:
- Sensirion’s STS3x High Accuracy Temperature Sensor
- Its associated breakout board for easy connection
- Solder paste
- Heatgun
- Arduino Uno
- A lock-type solenoid
- A beefy transistor (TIP120)
- 220R resistor
- Two 10K resistors
- 0.1uF capacitor
- 1N4001 diode
- 12V supply
- And a Wav trigger if you want to rock out to the sounds of the season!
Attempting to mount the enclosure to the "door"
The DFN Soldering
The Sensirion STS3x temperature sensor is a very small component, with a footprint of 2.5mm x 2.5mm, so it needs to be placed on a breakout board to use it. To do so, I ordered a standard SMD breakout adapter that provides accurate pin spacing for breadboard use. With no reflow oven and just one component to mount, he decided to use some solder paste and a standard heat gun to surface mount the sensor.
This was Ryan’s first time DFN soldering and he was successful after only a few attempts, so if you’re on the fence about trying it, don’t be afraid!
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 it 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 component 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 component 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 proper number of pins 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
There are a few different ways to hook up the STS3X sensor, you can view the datasheet for your specific use. Ryan used "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 the ADDR pin to ground, the address becomes "0x4A." If he were to connect the pin to a logic high signal, the address would then become "0x4B."
His circuit design was modeled 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 I2C to the sensor. To do so, you will need to include the Arduino Wire library in your 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’ve wired it successfully!
The temperature sensor circuit
The solenoid circuit is pretty straight forward, and if you have been keeping up with this series, you can do this with your eyes closed. But you should probably keep your eyes open anyway, safety first!
This circuit is controlled by a logic high signal sent from digital pin 2 whenever the sensor's temperature value breaks our threshold. For music, he 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 tutorial.
Getting the Temperature
Specific details for I2C communication can be found within the datasheet, and vary for different uses. Ryan used Single Shot mode and was able to accomplish simple communication using the sketch below, see "void gettemp(){" for specific protocol. We first 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.
To do so, we use the “Wire.requestFrom" and request three bytes from the sensor. The first two bytes indicate temperature and the third is a checksum that is used to verify the validity of the numbers. To convert these numbers into a standard temperature you must use the equation included in the datasheet. S(t) denotes the raw sensor output for temperature, (datasheet).
Now, open your Serial Monitor and you should see accurate temperature readings! In the first part of the loop, he 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 not 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 killswitch so you don't get locked inside for good!
/*
To be used with the Sensirion STS3x in Single Shot mode
Special thanks to the All About Circuits contributors that
helped compile this code!
*/
#include
int address1 = 0x4A; // hex address of sensor 1 with ADDR to GND
unsigned short tC;
byte byte1, byte2, byte3;
float temperatureF;
int lockPin = 2; //solenoid/transistor circuit
int wavTrig1 = 3; //used to control song 1
int wavTrig2 = 4; //song 2
void setup() {
Serial.begin(9600);
Wire.begin();
pinMode(lockPin, OUTPUT);
digitalWrite(lockPin, LOW);
pinMode(wavTrig1, OUTPUT);
pinMode(wavTrig2, OUTPUT);
}
void loop() {
gettemp (); //look at void gettemp(){
if (temperatureF > 80) { //if temperature over threshold
digitalWrite(lockPin, HIGH); //open door
digitalWrite(wavTrig1, HIGH); //play summer song
} else { //if not
digitalWrite(lockPin, LOW); //LOCK DOOR
digitalWrite(wavTrig1, LOW); //play winter song
}
}
void gettemp() {
Serial.println(" wait..");
delay(1000);
// set up for single shot mode / clock stretching /.5/sec max frequency
Wire.beginTransmission(address1);
//start the communication with IC with the address xx
Wire.write(byte(0x2C));
Wire.write(byte(0x06));
Wire.endTransmission();
// request the 3 bytes of measurement data 16 bit temp value plus checksum
Wire.requestFrom(address1, 3);
byte1 = Wire.read(); // msb of temp
byte2 = Wire.read(); // lsb of temp
byte3 = Wire.read(); // chksum
Serial.print("Checksum = ");
Serial.println(byte3);
tC = (byte1 << 8) byte2;
temperatureF = -49 (315 * (float)tC / 65535); //temperature conversion
Serial.print("Temperature (F) = ");
Serial.println(temperatureF);
}
Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.
Visit TechForum