Skip to content

Instantly share code, notes, and snippets.

@boulama
Last active October 17, 2023 17:10
Show Gist options
  • Save boulama/72b8ec1064be5087ed81e1a32d99be01 to your computer and use it in GitHub Desktop.
Save boulama/72b8ec1064be5087ed81e1a32d99be01 to your computer and use it in GitHub Desktop.
pressure transducer code
#include "Wire.h" //allows communication over i2c devices
const int sensorPin = A0;
float sensorVal = 0;
float p_max = 5000;
float p_min = 0;
float v_max = 5;
float v_min = 0;
float voltage;
float psiVal;
const int baudRate = 9600; //constant integer to set the baud rate for serial monitor
const int sensorreadDelay = 250; //constant integer to set the sensor read delay in milliseconds
void setup() //setup routine, runs once when system turned on or reset
{
Serial.begin(baudRate); //initializes serial communication at set baud rate bits per second
Serial.print('ok...');
}
void loop() //loop routine runs over and over again forever
{
sensorVal = analogRead(sensorPin); // Read pressure sensor val (A0)
voltage = sensorVal; // calculate voltage
psiVal = ((voltage - 5.15E-16) / 0.1)/2.036;
Serial.print(psiVal, 4); //prints value from previous line to serial
Serial.print(" PSI -- "); //prints label to serial
Serial.print(voltage, 4);
Serial.println(" V"); //prints label to serial
delay(sensorreadDelay); //delay in milliseconds between read values
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment