TringaliLuca

vacuum box with Arduino

Nov 29th, 2019
143
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2. #include <Adafruit_BMP085.h>
  3.  
  4. Adafruit_BMP085 bmp;
  5. // VCC -> 3.3V
  6. // GND -> GND
  7. // SCL -> Analog 5
  8. // SDA -> Analog 4
  9.  
  10. int pushButton = 8;
  11. int valve = 7;
  12. int pump = 6;
  13.  
  14. double vacuum = 960.0; //at this pressure we got vacuum
  15. double safety = 20.0;  //safety range for pressure
  16.  
  17.  
  18. void setup() {
  19.  
  20.   pinMode(pushButton, INPUT);
  21.   pinMode(valve, OUTPUT);
  22.   pinMode(pump, OUTPUT);
  23.   Serial.begin(9600);
  24.   if (!bmp.begin()) {
  25.     Serial.println("Could not find a valid BMP085 sensor, check wiring!");
  26.     while (1) {}
  27.   }
  28. }
  29.  
  30. void loop() {
  31.     Serial.print("Temperature = ");
  32.     Serial.print(bmp.readTemperature());
  33.     Serial.println(" *C");
  34.  
  35.     double pressure = (bmp.readPressure()/100); //hPa
  36.     Serial.print("Pressure = ");
  37.     Serial.print(pressure);
  38.     Serial.println(" Pa");
  39.  
  40.     if (digitalRead(pushButton) == HIGH) {
  41.       digitalWrite(valve, HIGH);
  42.       digitalWrite(pump, HIGH);
  43.       while (pressure > vacuum && digitalRead(pushButton) == HIGH) {
  44.         pressure = (bmp.readPressure()/100)+safety; //we will actually get to (960-20)=940 hPa before stopping
  45.         Serial.print("Pressure = ");
  46.         Serial.print(pressure);
  47.         Serial.println(" Pa");
  48.         delay(1000);
  49.       }
  50.       Serial.println("Stop");
  51.       digitalWrite(valve, LOW);
  52.       digitalWrite(pump, LOW);
  53.     } else {
  54.       digitalWrite(pump, LOW);
  55.       digitalWrite(valve, HIGH);
  56.     }
  57.    
  58.     delay(5000);
  59. }
RAW Paste Data