Advertisement
Guest User

M7100 Sensor SV Seeker

a guest
Feb 21st, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1.  
  2. // analog input which is conneted to the sensor "output" pin
  3. int sensorInput = A0;
  4.  
  5. // 150 psi = 10 bar, you can change it according to you sensor/ prefered unit
  6. float maxPressure = 150;
  7.  
  8. void setup() {
  9.   // put your setup code here, to run once:
  10.   // depending on the sensor, INPUT_PULLUP instead of INPUT might be useful
  11.   pinMode(sensorInput, INPUT);
  12.  
  13. }
  14.  
  15. void loop() {
  16.   float sensor_value = analogRead(sensorInput);
  17.   // TODO: implement a routine to calibrate
  18.  
  19.   // max pressure = 4.5V. Arduino has 8 bit accuracy -> 1024 different voltages it can detect (0-1023).
  20.   // if we assume a 5V reference, max value would be at (1023 / 5) * 4.5 ~ 920 so 920 equals max pressure
  21.   // min pressure = 0.5V. (1023 / 5) * 0.5 ~ 102
  22.   // eff range is 920 - 102 = 818
  23.  
  24.  
  25.   float pressure = ((sensor_value - 102.0) / 818.0) * maxPressure;
  26.  
  27.   // incorrect reading
  28.   if (pressure < 0) {
  29.     pressure = 0;
  30.   }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement