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.