daniel_lawson9999

Waterbottle refilling machine v1

Feb 17th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. #include <NewPing.h>
  3. #include <Servo.h>
  4. #define TRIGGER_PIN  8
  5. #define ECHO_PIN     9  
  6. #define MAX_DISTANCE 200
  7. Servo s;
  8. const int PINb = 7;
  9. const int pinSERVO = 10;
  10.  
  11. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  12. NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
  13.  
  14. void setup() {
  15.   pinMode(INPUT,PINb);
  16.   pinMode(pinSERVO,INPUT);
  17.   s.attach(pinSERVO);
  18.   lcd.begin(16, 2);
  19.   Serial.begin(9600);
  20.   s.write(90);
  21. }
  22.  
  23. void loop() {
  24.   boolean button = digitalRead(PINb);
  25.   lcd.clear();
  26.   unsigned int uS = sonar.ping();
  27.   Serial.print("Ping: ");
  28.   Serial.print(uS / US_ROUNDTRIP_CM);
  29.   Serial.println("cm");
  30.  
  31.   if(uS / US_ROUNDTRIP_CM<8){
  32.     if(button){
  33.       lcd.print("Filling");
  34.       s.write(50);
  35.     }
  36.     else{
  37.       lcd.print("Ready to fill");
  38.        s.write(90);
  39.     }
  40.    
  41.   }
  42.   else{
  43.     lcd.print("Too far away");
  44.     s.write(90);
  45.   }
  46.  
  47.   delay(500);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment