Advertisement
safwan092

Untitled

May 10th, 2022
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #define relayPin 7
  2. #define pressureInput A0
  3.  
  4. int flag = 0;
  5. const int pressureZero = 102.4; //analog reading of pressure transducer at 0psi
  6. const int pressureMax = 921.6; //analog reading of pressure transducer at 100psi
  7. const int pressuretransducermaxPSI = 100; //psi value of transducer being used
  8. float bar = 0;
  9. float pressureValue = 0; //variable to store the value coming from the pressure transducer
  10.  
  11. void setup() {
  12. Serial.begin(9600);
  13. pinMode(relayPin, OUTPUT);
  14. pinMode(pressureInput, INPUT);
  15. digitalWrite(relayPin, LOW);
  16. delay(5000);
  17. }
  18.  
  19. void loop() {
  20. readSensor();
  21. if (pressureValue >= 6) {
  22. digitalWrite(relayPin, LOW);
  23. Serial.println("6 PSI****************************");
  24. }
  25. else if (pressureValue < 1) {
  26. digitalWrite(relayPin, HIGH);
  27. }
  28. }
  29.  
  30.  
  31. void readSensor() {
  32. pressureValue = analogRead(pressureInput);
  33. pressureValue = ((pressureValue - pressureZero) * pressuretransducermaxPSI) / (pressureMax - pressureZero);
  34. pressureValue = pressureValue + 0.6;
  35. if (pressureValue < 0.5) {
  36. pressureValue = 0;
  37. }
  38. Serial.print(pressureValue, 1);
  39. Serial.print("psi\t");
  40. bar = pressureValue / 14.5037738;
  41. Serial.print(bar, 1);
  42. Serial.println(" bar");
  43. delay(250);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement