I have a 4 wire pressure transducer (Power, ground, output pos, output neg) that I am using to read hydraulic cylinder pressure. But I'm having problems understanding how to read that off the analog voltage on an Arduino Mega 2560. How would I code that and how could I wire that if analog only reads off one pin, no ground?
Here is the code I have so far, I have it reading out on a LCD display and eventually it will be reading weight from that pressure and be able to zero the weight (like a scale)
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int pin5 = A5;
int pin0 = A0
int Tare = pin0
void setup() { //This function gets called when the Arduino starts
Serial.begin(9600); //This code sets up the Serial port at 115200 baud rate
lcd.begin(16, 2);
lcd.clear();
pinMode(pin5, INPUT);
}
void loop() { //This function loops while the arduino is powered
int val; //Create an integer variable
int weight;
float Tare = 0;
weight = analogRead(pin5)*(5/1023);
val = (analogRead(pin5)*(5/1023))*10; //the value to the serial port
Serial.println(weight);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Pressure=");
lcd.print(val);
lcd.print(" psi");
lcd.setCursor(0,1);
// lcd.print("Weight ="); //Code for changing pressure to weight
// lcd.print(weight); //Commented out for now till I figure out the math
// lcd.print(" lb");
float voltage = analogRead(pin5)*(5/1023);
Serial.println(voltage);
lcd.print("volts =");
lcd.print(voltage-Tare);
if(tare == HIGH) Tare = voltage;
delay(750); //Wait one second before we do it again
}