Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- #include <NewPing.h>
- #include <Servo.h>
- #define TRIGGER_PIN 8
- #define ECHO_PIN 9
- #define MAX_DISTANCE 200
- Servo s;
- const int PINb = 7;
- const int pinSERVO = 10;
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
- void setup() {
- pinMode(INPUT,PINb);
- pinMode(pinSERVO,INPUT);
- s.attach(pinSERVO);
- lcd.begin(16, 2);
- Serial.begin(9600);
- s.write(90);
- }
- void loop() {
- boolean button = digitalRead(PINb);
- lcd.clear();
- unsigned int uS = sonar.ping();
- Serial.print("Ping: ");
- Serial.print(uS / US_ROUNDTRIP_CM);
- Serial.println("cm");
- if(uS / US_ROUNDTRIP_CM<8){
- if(button){
- lcd.print("Filling");
- s.write(50);
- }
- else{
- lcd.print("Ready to fill");
- s.write(90);
- }
- }
- else{
- lcd.print("Too far away");
- s.write(90);
- }
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment