Friday, June 7, 2013

AC Voltmeter and Temperature Monitor

I was asked to build a test jig for testing Honeywell Aquastats, and the two parameters that needed monitoring were voltage (12-16 vac), and temperature. I usually work with DC monitoring and DS18B20 digital temperature sensors, but this project called for monitoring AC, and I was given a TMP36 analog temperature sensor.

Before connecting the output of the voltage divider to the Arduino, I plugged my DMM into the output of the voltage divider, connected the AC source, and adjusted the two pots till I got exactly 5v. The 5.1v Zener prevents you from doing something foolish with the pots.

I then connected my DMM to the AC source, took the AC reading, and put it into my map command in the code as the value for 1023 on the ADC. After all the wiring was finished and the code uploaded to the Arduino, I connected the input of my AC transformer to a variac so I could run the transformer primary from 0-125vac. With my DMM on the secondary of my 29vac transformer, the Arduino LCD display mirrored the DMM almost perfectly throughout the complete range.

Without further delay, here's the schematic and code:




#include "LiquidCrystal.h"
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); //Arduino Digital Ports for RS, EN, D4, D5, D6 & D7


int voltPin = 0;     // voltage divider (middle terminal) connected to analog pin 0
                       // outside leads to 0-29vac
int tempPin = 2;     // TMP36 data pin
int val = 0;           // variable to store the value read
int volt = 0;           // variable to store the voltage calculated

void setup()
{
  Serial.begin(9600);          //  setup serial
  lcd.begin(20, 4);            // setup LCD
}

void loop()
{
  val = analogRead(voltPin);    // read the input pin
  Serial.println(val);             // debug value
  volt = map(val, 0, 1023, 0, 29); // map 29v range
  Serial.println(volt);             // voltage
  lcd.setCursor(0, 1);
  lcd.print(volt);
  lcd.print(" VAC  ");
  delay(50);

  int reading = analogRead(tempPin);    // read the input pin
  float voltage = reading * 5.0;
  voltage /= 1024.0;

  Serial.print(voltage);
  Serial.println(" volts");
  float temperatureC = (voltage - 0.5) * 100;
  Serial.print(temperatureC);
  Serial.println(" degrees C");
  float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
  Serial.print(temperatureF);
  Serial.println(" degrees F");
  lcd.setCursor(0, 3);
  lcd.print(temperatureF);
  lcd.print(" degrees F  ");
  delay(500);
}


2 comments:

  1. Question: Do be sure I'm reading this properly, you're taking the DC- (Gnd) from the A/C bridge rectifier and connecting it to the ground bus on the Arduino? I'm afraid of toasting my Arduino, so I want to be sure!

    ReplyDelete
    Replies
    1. That is correct. We are measuring voltage that is higher than the arduino 5v, so + goes to the top of R1, gnd to the bottom of R2, and the arduino analog input connects to the bottom of R1 / top of R2 intersection. The Zener prevents an oops.

      Delete

Related Posts Plugin for WordPress, Blogger...