One led voltmeter (Part 1)

Part 1, 2, 3, 4

This is a minimal voltmeter which reads the signal from one of the analog ports and converts its value in to a sequence of led flashes. Long flashes for volts, short flashes for tenths of volts.

One led voltmeter or 'the voltmeter of the poor'
Reads analog port 0 from a bare Arduino board
Count long lasting flashes for volts and short lasting flashes for tenths of volts
The routine will also print value on serial comm port

No warranty, no claims, just fun
Didier Longueville invenit et fecit May 2010
int inputVoltagePin = 0;               

void setup(){
  DDRB  |=  (1 << PINB5); // Led pin
  PORTB &= ~(1 << PINB5); // Turn led off
  // blink status led
  toggleLed(5, 100, 100);

void toggleLed(int cycles,int onTime, int offTime) {
  for(int i=0; i < cycles; i++){
    PORTB |=  (1 << PINB5); // turn led on
    PORTB &= ~(1 << PINB5); // turn led off

void loop(){
  // read voltage value
  int DACValue = analogRead(inputVoltagePin);
  int tenthsVolts = (DACValue*50L) >> 10;
  int integerPart = (tenthsVolts/10);
  int fracPart = (tenthsVolts%10);
  // send formated value to serial comm port
  Serial.print(integerPart, DEC);
  Serial.print(fracPart, DEC);
  Serial.println(" V");
  // flash volts
  toggleLed(integerPart, 500, 500);
  // pause
  // flash hundreths of millivolts
  toggleLed(fracPart, 100, 500);
  // pause between readings

Starting from there, we will try to improve it while keeping the same principle…

Next post on same subject

Leave a Reply

You must be logged in to post a comment.