July 27, 2014

Wireless HVAC Sensors - Part 2

Previously I introduced the idea of a battery operated wireless sensor board for sensing temperature and humidity. The intent is to get information to my Raspberry Pi (or Arduino, or any other microcontroller) so that it can intelligently control the HVAC system in my house. Today I give you an update on the project.

To recap, what I wanted was a battery powered wireless sensor to communicate with my Raspberry Pi. In addition to all the regular good stuff (cheap, re-programable, etc.), I wanted the thing to be discrete and not just a bulk of electronics and wires sitting on a shelf or hung on the wall. So I designed it to fit in a standard electrical box behind a light switch face plate. And now we have V2.

There were three main motivations behind this new version:
  • Fix the numerous flaws in V1.
  • Increased battery life by going to two AAA batteries rather than a single button cell.
  • Better aesthetics in the face plate opening.

I won't beat around the bush. V1 was chock full of issues. There were traces in the wrong places connecting the wrong things, the analog output of the humidity sensor was unbuffered so reading the line changed the value, the battery life was not at all what I was hoping it would be (though I don't think I have sleep functions working properly yet), and if you studied what was visible through the light switch opening it was kind of messy.

So I fixed the routing in eagle... or so I thought. Turns out I had the SPI reset node hooked up to the wrong pin in the schematic. So I had to cut another trace and add another jumper wire to continue testing. I also made to board too wide where it mates with the electrical box. Such is life.

But I did make and validate some improvements, so it wasn't a total loss. I added an additional sensor option. Now the user can choose between the accurate but pricey DS18B20 digital temperature sensor or the much cheaper analog TMP36. I also added a 2 channel op-amp to buffer the two analog sensors. 

Why go through the trouble of an op-amp, you ask? Though it's not often thought about in the hobby world, it is important to guard the output of an analog sensor from the effects of reading it. The ADC (Analog to Digital Converter) pins on an Arduino, when activated, act like a ~50k pull-down resistor to ground. Many analog sensors have such a weak output that this pull-down can significantly change their reading. That means you probably have an inaccurate or maybe even bogus number if you didn't properly buffer the signal. Op-amps are great at buffering. When connected as a voltage follower they appear as an open circuit to the sensor (nothing pulling on it one direction or the other) while the op-amp can draw from its own power supply to hold the output at the level of what's on the input. I hooked the outputs of the HIH-5030 humidity sensor and the TMP36 temperature sensor to the two channels of the op-amp and came out with properly buffered signals that the micro can read with no worries. 

I also put in a few solder jumpers to close when either of the analog sensors are left off the board. This is done to prevent the input to the op-amp from floating, which would most likely result in wild oscillations of the op-amp output, drawing more power than it would otherwise (bad for a battery operated design). From the datasheet I also read that the op-amp uses the least power when it's output is halfway between the power lines, so I connected the opposite side of the jumpers to some areas that remain more or less at one half of 3.3v.

As for battery life, the button cell battery of V1 only lasted a few days. I'm pretty sure that I didn't have the sleep modes on the attiny working properly and that's the number one cause of the battery life fail. But I also learned something about the MCP1640 boost converter. Its job is to take the input voltage (from the battery, 1.5v per cell for alkaline batteries) and boost it up to a higher voltage (3.3v in this design). It does so with the help of an inductor and capacitor and switching the inductor on and off at a resonant frequency. While the MCP1640 is perfectly capable of stepping the voltage up from 1.5v to 3.3v (it's can start with as low as 0.65v on the input), efficiency degrades with lower input voltages. Going with two batteries in series means a nominal 3v on the input. That's a lot less of a step up to 3.3v allowing the MCP1640 to operate in a more efficient region, improving battery life. Also, AAA batteries have such a large capacity compared to the button cell I was using on V1. I'm talking 8x more capacity. That, combined with (hopefully) figuring out sleep mode and the improved efficiency of the MCP1640 should mean a good while between battery changes.

Of course there were good features from V1 that are unchanged on V2 and are worth mentioning again:
  • Each of the sensors (and now the op-amp) are powered from a digital output of the attiny. That means that the sensors can be powered down when not in use. 
  • The battery (pre boost converter) is connected to an analog input so the attiny can monitor battery level and send a warning when they are getting close to dying.
For those interested, see below for the schematic of the design (V2 errors corrected). I'm working on cleaning up the board design as I have time. Hopefully I'll be ordering V3 boards soon, and hopefully they will be the final version.


  1. I'm glad to see an update on this project. When are you planning to spin the v3 board? I'm very interested in getting some when you do. Are you using the MCP1640C and putting the boost circuit in "input bypass" mode for uC sleeping?

    1. You're in luck. I just placed the order for V3 boards today. They will take about 4 weeks to get here from Asia. Once they arrive I will build one up to make sure it works and then begin selling them.

    2. And yes, the plan is to use the input bypass while sleeping. I connected the enable pin of the MCP1640C to the uC to turn it on and off. I'm also reading the battery voltage on one of the analog inputs so that if the battery gets too low it won't try to turn off the MCP and put the uC in a brown-out condition or worse.

  2. This is phenomenal, and exactly what I'm looking for in my smart thermostat project!

    A few questions:

    Would the board need to be redesigned to handle an I2C sensor such as the MCP9808? I love the increased accuracy of that part.

    Is it feasible for the sensor to be raised off the board, perhaps onto a tiny breakout board on pins, to allow the sensor to get into the ambient room air better? We could cover the switch opening with a tiny plastic guard of some kind, perhaps a 3D printed part.

    Fantastic job so far, I'm keeping a close eye on all of these projects!

    1. At first glance the MCP9808 is the same resolution and accuracy as the DS18B20, though the latter is a lot more expensive. The MCP does offer more features (various alerts) than the DS, but pin count it already maxed out on this uC. Even without the alerts it requires one more pin than the DS, so you'd have to give up something somewhere else. But the board could be redesigned with a bigger uC in surface mount form factor and you could get a win there.

      As for getting the sensor out into ambient, I think you have a decent idea. you could even make the breakout board the same size as the opening in the light switch cover so it becomes the guard you mentioned. How you would get the standoffs to work would be the challenging part.

      Other thoughts I've had are to use a closed, dedicated electrical box (to help isolate it from the air within walls) and put louvers at the top and bottom of the face plate to help facilitate air flow. Louvers could be added with a dremel or hobby knife or a new face plate could be 3D printed.

    2. I know it's designed for surface mount, but would it be possible to somehow finagle a TO-92 bodied DS18B20 in there? That would give the height necessary to get the sensor into ambient air.

      Maybe for V4?

    3. There's enough room on the surface mount pads that it wouldn't be too hard to get a TO-92 on there. Modifying the board for a through hole device would be a little trickier since there's other stuff directly behind it on the other side.

      Of course, you're always welcome to modify the design files after they're posted. I'm hoping to get them up in the next week or so.

  3. Nich, any updates on this board?

    1. Wondering the same, I might be in for as many as 8!