Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // analog input which is conneted to the sensor "output" pin
- int sensorInput = A0;
- // 150 psi = 10 bar, you can change it according to you sensor/ prefered unit
- float maxPressure = 150;
- void setup() {
- // put your setup code here, to run once:
- // depending on the sensor, INPUT_PULLUP instead of INPUT might be useful
- pinMode(sensorInput, INPUT);
- }
- void loop() {
- float sensor_value = analogRead(sensorInput);
- // TODO: implement a routine to calibrate
- // max pressure = 4.5V. Arduino has 8 bit accuracy -> 1024 different voltages it can detect (0-1023).
- // if we assume a 5V reference, max value would be at (1023 / 5) * 4.5 ~ 920 so 920 equals max pressure
- // min pressure = 0.5V. (1023 / 5) * 0.5 ~ 102
- // eff range is 920 - 102 = 818
- float pressure = ((sensor_value - 102.0) / 818.0) * maxPressure;
- // incorrect reading
- if (pressure < 0) {
- pressure = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement