Skip to content

Instantly share code, notes, and snippets.

@penpencool
Last active June 22, 2018 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save penpencool/bfb1bf9b10f21556d1e4e9b9752fbf3a to your computer and use it in GitHub Desktop.
Save penpencool/bfb1bf9b10f21556d1e4e9b9752fbf3a to your computer and use it in GitHub Desktop.
/*
Example By ArduinoAll.com
ต่อขากับ Arduino Uno
Analog - A0
VCC - 5V
GND - GND
*/
int sensorPin = A0;
int sensorValue = 0;
float Vout = 0;
float P = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
int i = 0;
int sum = 0;
int offset = 0;
Serial.println("init...");
for (i = 0; i < 10; i++)
{
sensorValue = analogRead(sensorPin) - 512;
sum += sensorValue;
}
offset = sum / 10.0;
Serial.println("Ok");
while (1)
{
sensorValue = analogRead(sensorPin) - offset;
Vout = (5 * sensorValue) / 1024.0;
P = Vout - 2.5;
Serial.print("Presure = " );
Serial.print(P * 1000);
Serial.println("Pa");
delay(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment