I thought it might be useful to those new to analog circuits and Micro A/D converters to provide some comments on the design of the DC Remote. I've included the PDF of the schematic here for your reference.
The current sensor used in the DC Remote is a very common one, the Allegro ACS712. You can find a TON of these on breakout boards without too much trouble. This design uses the chip mounted directly on the PCB but also includes a 3 pin header that just so happens to match the pinout of some of the breakout boards. This allows me to add a second current sensor to a remote - this is used when the remote needs to support two zones.
The ACS712 is a 5V only part. The Moteino (with its radio and flash chip) is a 3.3V only part. There are lots of ways to get these two to safely 'talk' to each other (level shifting with an operational amplifier, relying on the fact that the quiescent output of the ACS712 is 2.5V, mid range on the power supply, and simply clamp the output if it goes above 3.3V, or, as I have done, use a simple resistor divider). The first two methods would keep the amount of voltage/Amp the same as the ACS712 output (nominally 100mV/A) while the resistor divider will scale this down (approximately 67mV/A). But, another factor to keep in mind, is that '0' Amps is set to the midpoint of the power supply and measured current swings the voltage above or below this midpoint.
This is important as all calculations for current, must be based on deviation from this '0' or midpoint value, not an absolute voltage. If I had used the operational amplifier, then I'd had to precisely set the offset so that the midpoint was known by the micro. There are techniques to do this, especially if you have the wealth of analog inputs that the Moteino has (you bring your offset voltage into a spare analog input and measure it!), but, for me, given that the Moteino only has 10bits of A/D resolution AND has its AREF pin available on the board makes me less concerned about losing voltage resolution with the divider.
What does the AREF pin have to do with it? Quite simply, the Moteino A/D converter measures an analog signal proportional to the AREF - ALWAYS. By default AREF is tied internally to VDD so it's common to think in terms of the voltage being measured with respect to VDD, but, technically that is not the case - the VDD is switched to the AREF and the AREF controls the 'gain' of the ADC. This is why you need to be careful when you supply a voltage to AREF, if ANY internal source is selected on the ADC, the AREF will try to drive this voltage on its pin.
With AREF literally as the voltage reference to the ADC, then if you sample a voltage on A0, for example, that is equal to AREF, you'll get an ADC value of 1023. If you read a voltage that is exactly half of AREF, you'll get 511 (+/- 1/2bit) and so on. So, given this, if I divide the ACS712 output by 2/3 AND supply an AREF signal that is 2/3 of 5V, then the midpoint of the ACS712 will supply EXACTLY the midpoint of the ADC. Cute huh?
Now, if you look at the schematic, you'll notice two things:
1. the divider isn't exactly 2/3. It is 2.2/(2.2+4.3) or 2.2/6.5. So will this introduce an error in the calculations? No. Why? Because the AREF is driven by exactly the same ratio. 4.3K is a more common resistor than a 4.4K is (unless I used 2 2.2Ks in series) and, as I've shown, it doesn't matter as long as the two ratios are the same.
2. while the ACS712 output is divided by 2.2K & 4.3K ohm divider, the AREF pin has 220 & 430 ohm resistors. The ratio is the same, why the different values? The specs on the two ICs dictate what resistance is proper. The ACS712 doesn't want a load greater than 4.7K so this is why those values are chosen (total is 6.5K). The ATMega328P AREF pin, on the other hand, has an input resistance of approximately 35-36K ohms. This would introduce an error in the ratio of the divider as it would put 35K in parallel with the 4.3K ohm divider. That's a pretty big error. I could adjust the value of the resistor so that the equivalent resistance is 4.3K or, as I have done, I simply dropped the resistor values by a factor of ten, which, in turn reduces the error within acceptable quality limits. Note that this is a lot of current by Moteino standards but is ok in this case BECAUSE the DC Remote is AC powered. That solution is NOT a good one if the Mote was battery powered. I have another Mote where I'll show how to deal with this...
So, given this circuit, I get an accurate rendering of the ACS712 output, centered on 512, and covering the full range of current measured by the device. If you look at the code I provided you'll see how I calculate a noise filtered and 'quasi'RMS current from the input. The code provided, with the radioCheck() code included in the loop, provides about 8800 samples with a one second sample window.
I hope you've found this useful...
Tom