Reply to comment

user warning: Unknown column 'i18n.language' in 'where clause' query: SELECT DISTINCT b.* FROM blocks b LEFT JOIN blocks_roles r ON b.module = r.module AND b.delta = r.delta LEFT JOIN i18n_blocks i18n ON (b.module = i18n.module AND b.delta = i18n.delta) WHERE (i18n.language ='en' OR i18n.language ='' OR i18n.language IS NULL) AND ( b.theme = 'garland' AND b.status = 1 AND (r.rid IN (1) OR r.rid IS NULL) )ORDER BY b.region, b.weight, b.module in /var/alternc/html/o/orangeseeds/usr/drupal-6/modules/block/block.module on line 456.

Voltage metering circuit (with AVR)

No this is not a DIY multimeter... sorry fellows! :) But in a way it's much more useful for the electronic interventionist. This is a small circuit that allows you to measure any input voltage with an ATmega168 (although it can be adapted to any microcontroller that has analog inputs and a reference voltage).

It uses a simple resistor bridge to bring the input voltage between 0 and 1.1V (the reference voltage on the ATmega168).

The code of the VoltageMeter class is provided in attachment to this post.

Note: If you want to measure the voltage from the ATmega168 itself (ie. AVcc) you can use the following code instead (no need to build a circuit).

Circuit schematics

             R1             R2
   GND ----/\/\/\----*----/\/\/\---- Vin
                     |
                     | Vout
                     |
                ANALOG PIN
  • Vin : input voltage (the voltage we try to meter)
  • Vmax : the maximum value of the input voltage
  • Vout : the output voltage (the Vin remapped to 0 .. 1.1V)

Choose R1 and R2 CAREFULLY according to the following rule:

R1 = R2 x 1.1 / (Vmax - 1.1)
R2 = R1 x (Vmax - 1.1) / 1.1

A typical configuration is R1 = 1k and R2 = 4k. It assumes Vmax = 5.5V.

Important considerations

  1. It is recommended to test the circuit before, especially if Vmax > 6V, to make sure the voltage at the analog pin (Vout) does not get over 5V.
  2. '''You should not connect any external voltage source to the AREF pin''' since this system relies on the internal reference. Doing so might result in a short circuit.
  3. ATmega168 datasheet has the following notice "Note that VREF is a high impedance source, and only a capacitive load should be connected in a system." According to one of our readers (many thanks to Peter) "what it means is that when VREF is used as an output, you may not draw current from it. You may connect a capacitor to it to eliminate any ripple that might be caused by noise on adjacent circuits."

Example Arduino code

 #include "VoltageMeter.h"

 #define VOLTAGE_AIN 0

 VoltageMeter meter(VOLTAGE_AIN, 5.5);
 
 void setup() {
   Serial.begin(9600);
 }
 
 void loop() {
   float voltage = meter.voltage();
   Serial.print((int)(voltage*1000), DEC); Serial.println(" mV");
 }
AttachmentSize
analog_reference.h2.65 KB
prescaler.h3.34 KB
VoltageMeter.h3.02 KB

Reply

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.