The issue
To create better insight in the isolation and air quality at home, a network of sensors is necessary to collect data. The values of interest are temperature and humidity. The module has to operate wireless to allow placement on locations where external power is unavailable.
The solution
The created solution consists out of a sensor module, a microcontroller, and a wireless transmitter. The whole system is battery powered. The different parts will be highlighted in more detail later. All electronics are attached to a piece of protoboard. In an attempt to keep everything small, a 5x7cm protoboard was split in 4 pieces. Unfortunately this led to using more space because of the inconvenient orientation of the antenna. The pieces came out uneven, so some creativity was required to fit all components on the different boards.
The sensor
To take measurements I used a SHT40 combined temperature and humidity sensor. This sensor should be able to take measurements accurate to 0.1 C and 1% RH. The sensor was supplied on a breakout board that also contains a voltage regulator and level shifter. This will come in handy as we will see later. Communication to the sensor us done using I2C.
Wireless communication
I decided to use the same protocol as Oregon Scientific sensors. Support for this protocol is already available in our home automation system. This protocol works by transmitting messages at a frequency of 433.92MHz. The used modulation is on-off-keying. Because this is a commonly used frequency, ready-made modules both transmit and receive are available for this frequency. Because no data needs to be received wireless, we only need to use the transmit module.
The microcontroller has to generate the baseband signal. This only uses a single data pin as output on the microcontroller. I used the V2.1 version of the protocol, as documented here. This protocol works by periodically broadcasting the current sensor readings. This data is received and stored in our home automation system for analysis. Readings are not stored on the module itself.
Microcontroller
An ATTiny85 microcontroller forms the brain of the module. It has the following tasks:
- Take readings from the sensor
- Confirm if the sensor reading has valid CRC
- Measure battery level
- Create and send correctly formatted messages
- Delay until next reading
All tasks should be done while consuming minimal power. As we will see later, the delay phase is the most important to conserve energy.
The datasheet labels pins PB0 and PB2 as SDA and SCL, so these pins where connected to the sensor. In the final code, I ended up bit banging the I2C bus, so in theory any set of data pins could be used. After connecting the sensor and the radio-transmitter two IO pins remained available. I decided to connect a LED and a pushbutton to the module.
The battery level can be monitored without using additional pins on the microcontroller. This can be done by configuring the ADC to measure the bandgap reference against the supply voltage. From this reading, the battery voltage can be derived. This path is not shown on the block-diagram in the datasheet, so I only found out this was possible after looking at some example code. When the battery drops below a pre-determined level, a flag is set in the transmissions to notify the user.
The EEPROM is used to store the sensor identification code. This value is send during the transmission to specify the sensor that send the data.
Battery
The first step for selecting a suitable battery is determining the required voltage. The sensor itself is made for the 1.08v to 3.6v range, but the LDO present on the breakout board accepts up to 6v. The microcontroller accepts 2.7v to 5.5v. The only available specifications on the transmitter module listed 3.5v to 12v. RF power is likely increased with higher supply voltage. I decided to use 3 AA batteries in series to generate a nominal supply of 4.5v. Alkaline batteries are recommended because these can operate at lower temperature. One of the sensors was deployed outside when it was freezing, so this temperature range was important.
Battery life estimation
Because some of the sensors will be positioned in hard to reach locations, the interval between maintenance should be as long as possible. The obvious limitation is the battery capacity. Most of the time the module will be idle waiting for the next measurement. To conserve power during this phase, the microcontroller is put into sleep mode with only the watchdog time running to generate periodic interrupts. This consumes the least current at the cost of reduced accuracy in the delay time. The target time was set to be 2 minutes. The sensor itself goes down to the nanoamp range when not active, but the LDO continuously consumes about 1uA. The combined consumption during sleep was measured to be about 12uA.
The active phase can be split in two parts. The first part is the acquisition phase. During this phase the microcontroller wakes up and requests a reading from the sensor, polls the sensor until the reading is available, and retrieves and processes the reading. Overall this process takes about 40ms. Energy consumption is dominated by the microcontroller, and is estimated to be 1mA.
The data transmission phase lasts for about 400ms and has the highest power consumption. The transmitter consumes about 10mA when active. We will use this number for our battery life estimation.
By adding the power during the different phases, we find that during one cycle approximately 5.5ma*s is consumed. Assuming a battery capacity of 2000mh*h, we find that the battery should last for 1.3 million cycles. This converts to a period of almost 5 years, long enough for our purpose. Note that this number will be affected if we use the build in heater to clear moisture from the sensor.
Enclosure
To protect the electronics from damage, everything had to be placed in an enclosure. The basis for this enclosure was formed from a scrap piece of large PVC pipe. Two 3D printed pieces where used to cover the ends while allowing air to flow over the sensor. The openings are designed at an angle to prevent rain from reaching the sensor. The inspiration for this design came from the Stevenson screen. All electronics are hold in place by the end pieces. Long screws could be inserted to lock the parts together is necessary.
Testing
After construction and programing, a logic analyzer was connected to both the I2C lines and the baseband data output. The captured data shows the I2C communication with the sensor and the Oregon Scientific RF message. Note that the protocol requires the full message to be send two times.
Despite the attempt to allow for airflow in the enclosure, the response to change is still slow. The datasheet specified testing condition was an airflow of 1m/s over the sensor. With the sensor in the enclosure located in an area with little airflow, it can take one hour for the sensor settle on the final value.
Conclusion
the goal to measure temperature and humidity was achieved using this module. The predicted battery life is great. Future version can be made more compact. A smaller overall size and more neutral colors would help the module blend into living areas. For indoor use, the requirement for water protection can be released.
- schema.svg
- waveform.png
- board.jpg
- parts.jpg
- enclosure.jpg