mBuino hardware mod: resistor to measure VCC

Hello all,

For my battery powered mBuino project, I wanted to be able to measure the voltage status. Lacking an internal reference voltage I followed @ AndyA’s suggestion to use an external reference voltage. Not having a proper zener diode laying around, I found another component that worked for me: a resistor.

Although it may not look nice, it works for me. (I’m not a soldering star and didn’t have any SMD components laying around). Probably a simple wire would work as well, but I thought using a 100R resistor would be safer. I selected this value since the LED pins use this value too and hoped this hack would allow me to use PWM on LED6 too. Unfortunately I ran into a PWM issue there.

See the mbed homepage of this example program and the comments in the code for more information.

In attempt to get more or less accurate readings under various conditions, the code contains some goofy trial on error compensation. Most times the reading is still off by up to 0.1V, which I like to improve. If you have any suggestions to improve accuracy in software, I’d appreciate them.

A resistor should not work! It will cause the reference voltage to drop when the source drops and then you will get the same reading at any voltage.

Hi Gus, it’s not just a resistor! It’s actually a simple connection from P0_14 to LED6, for safety reasons I used a resistor instead of plain wire :wink:
Tried, tested and it works for me! (You can test yourself using my mBuino PowerMeter sample program)

The circuit is actually a (light emitting) diode connected to ground on one side and via a resistor to VCC on the other side. The voltage on the junction of the resistor and the diode is (more or less) constant. By measuring the relative value on that junction, the absolute VCC can be derived. For more information see this page, which includes circuit diagrams and a nice picture.

In a stroke of (mad) genius under the shower it occurred to me that that these components didn’t need to be external. mBuino already features plenty of LED’s and resistors! All that was missing to read the (constant) voltage was a connection. Note that in my example I only blink the LED for a short time. The reading gets more accurate when the LED is on for a longer time.
BTW: I noticed that in the mBuino schematics, the resistor values for LEDs 5 and 6 are incorrect. The resistors are all 100 Ohm, not 33 or 1 as noted in the schematics.

Below is a picture showing a CR2032 powered mBuino (with added resistor) as a RF24 sensor node. (Still on a mini breadboard with messy wires but already pretty small). The node is part of my sensor network project in which I use battery powered mBuino’s and nRF24L01+ modules. The voltage reported by the nodes is accurate to about 0.1V (checked 3v3 pin with multimeter), but it’s using some goofy software hack to compensate for inaccurate readings in low power conditions. Nevertheless it works for me and will serve its purpose to warn for low battery conditions. Next step is to include @ AndyA’s excellent mBuino sleep library.

I see, you are using the diode’s constant voltage drop as a reference voltage. I never thought of this before, not as accurate but still good idea.

@ Gus - Yes. since mBuino already has the diode, all needed extra is the connection. (I intentionally mentioned the resistor in the topic title to trigger readers with some knowledge of electronics :wink:

BTW: The idea of using a (zener) diode as external reference was suggested by AndyA. The alternatives I found online. I only thought it would be interesting if one could use the LEDs already on mBuino.

Nice trick.

As Gus said, not as accurate as a true reference diode and it’s going to have a slight supply voltage dependency but good enough for what you want.

The resistor is probably a good idea, it shouldn’t have any impact on the results but stops things going pop if that pin accidentally gets configured as an output.