Arduino readout for a cold cathode vacuum gauge
I’m building an ultra high vacuum system, and have been accruing parts over time. I just recently wrote my first arduino program, a program that takes the voltage from the gauge, and converts it to a pressure reading in torr via a logarithmic scale equation.
The code is quite simple, thanks to the help of PaulRB and the fantastic arduino community forums!
#include <LiquidCrystal.h>
#include <math.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(A0, INPUT); //A0 is set as input
#define PRESSURE_SENSOR A0;
lcd.begin(16, 2);
lcd.print("MKS Instruments");
lcd.setCursor(0, 1);
lcd.print("IMT Cold Cathode");
delay(6500);
lcd.clear();
lcd.print("Gauge Pressure:");
}
// the loop routine runs over and over again forever:
void loop() {
float v = analogRead(A0); //v is input voltage set as floating point unit on analogRead
v = v * 10.0 / 1024; //v is 0-5v divider voltage measured from 0 to 1024 calculated to 0v to 10v scale
float p = pow(10, v - 11.000); //p is pressure in torr, which is represented by k in the equation [P=10^(v-k)] which is-
// -11.000 (K = 11.000 for Torr, 10.875 for mbar, 8.000 for microns, 8.875 for Pascal)
Serial.print(v);
char pressureE[8];
dtostre(p, pressureE, 1, 0); // scientific format with 1 decimal places
lcd.setCursor(0, 1);
lcd.print(pressureE);
lcd.print(" Torr");
}
The code simply sets A0 as a floating point unit for voltage, which is 0-5v from the voltage divider. Then it is calculated back up to a 10v scale and interpolated using an equation based on the voltage/pressure table provided by the manufacturer.
The equation is P=10^(v-k) where p is pressure, v is voltage on a 10v scale and k is the unit, in this case torr, represented by 11.000. It calculates that in floating point, then displays it on an LCD screen in scientific notation using dtostre.
This code was the first program I have written from the ground up, and it was pretty daunting at first, but it was made easy and super rewarding by the community! :3