Thursday 23 March 2017

BASIC Tech Group - MyNews 31 - LCD voltmeter

Here is a very simple LCD display voltmeter, for 0-5V inputs - do NOT exceed as will destroy the Arduino!!!

It was written to be used as a digital voltmeter for measuring the output of a simple RF Probes.

Screen Shot 2017 03 23 at 15 57 30

The output of such a probe is the peak-to-peak RF voltage, minus any loss due to the diode forward drop. So its not an accurate measurement.

On the other hand the sketch has been written such that for an input of 0.225V (1mW in to 50R) it displays 0dB, and will then show the relative log (dB) of your voltage measurement...

IMG 0874 Code

// LCD_V using LCD to display analog voltage
// V1 10-3-17
// LCD I2C bus (16x2)
// GND - GND
// VCC - 5V
// SDA - A4
// SCL - A5

#include 
#include 

// chose address of 0x27 or 0x3F for LCD
#define LCDADDR 0x27
//#define LCDADDR 0x3F
#define LCDCOLS 16
#define LCDROWS 2

// lcd object
LiquidCrystal_I2C lcd(LCDADDR, LCDCOLS, LCDROWS);

void setup() {

  lcd.begin();

  lcd.print("   VOLTMETER   ");
}

void loop() {
  int Ain;                          // 0-1023 input
  double Vin, calc, dB;

  Ain = analogRead(A0);
  Vin = Ain * (5.0 / 1023.0);       // convert to volts

  lcd.setCursor(0, 1);              // clear display line
  lcd.print("                ");
  
  lcd.setCursor(1, 1);              // volts
  lcd.print(Vin, 3);
  lcd.print("V     ");

  if (Vin > 0) {                    // if not zero dB
    dB = 10 * log10(Vin * Vin / 0.05);
    lcd.setCursor(9, 1);
    lcd.print(dB, 1);
    lcd.print("dB");
  }


  delay(500);
}

No comments: