/* 4 Line LCD - List Selection Example
*
* Code Behavior: As you press up and down buttons, LCD Scrolls through a predefined list.
* Selecting a menu item with the play button activates the pump and a set of valves, delivering
* liquid from one or multiple sources, then clearing the line with air.
*
* DIO-2 - Pump Relay
* DIO-4 - Air Line Solenoid Relay
* DIO-23 - Neopixel Ring
* DIO-7 - Left Solenoid Relay 1
* DIO-8 - Left Solenoid Relay 2
* DIO-9 - Right Solenoid Relay 1
* DIO-10 - Right Solenoid Relay 2
* DIO-11 - Right Solenoid Relay 3
* DIO-12 - Left Solenoid Relay 3
* I2C - RobotGeek 2 line LCD
* DIO-14 (AIO-0) - Up Button
* DIO-15 (AIO-1) - Down Button
* DIO-16 (AIO-2) - Enter Button
* DIO-17 (AIO-3) - Back Button
*
* NOTES: You can power the pump and solenoids off of the same 12V10A Power Supply. Run the Geekduino
* on a SEPARATE power supply (USB or 6V2A). Running the Geekduino on the same power supply as the
* Pump and Relays will cause your board to reset.
*/
// Libraries
#include <Bounce2.h> //Load the Debouncing Library
#include <Wire.h> //Load for I2C
#include <LiquidCrystal_I2C.h> //Load the LiquidCrystal I2C Library for the 4 Line LCD Display
#include <Adafruit_NeoPixel.h> //Load the Neopixel Library
#include <Servo.h>
#include <AccelStepper.h>
#define RELE_BLOCCO 49 // pino para nema 17 enable
#define EN_PIN A2 // pino para rele positivo fonte para nema
#define su 0
#define giu 450
#define dis 10
AccelStepper ascensore(1, 45, 47); // 3 pino de direção-4 pino de passos
Servo rubinetto;
// Buttons
const int BUTTON_PIN[4] = {10, 11, 12,};
int value[4] = {10, 11, 12,};
//hc-sr04 sensor
int trigPin = 37;
int echoPin = 39;
int duration, distance; //Define two intregers duration and distance to be used to save data
//long durasi;
//int kejauhanCm;
//int kejauhanInch;
// Relays
//const int PUMP_RELAY_PIN = 2;
//const int CLEAN_RELAY_PIN = 4;
const int SELECTED_RELAY_PIN[9] = {9, 8, 7, 6, 5, 4, 3, 2};
//Neopixels
const int NEOPIXEL_PIN = 23;
// LCD Screen
long previousMillis = 0; // will store last time LED was updated
long interval = 100; // interval at which to blink (milliseconds)
// Prompts
String promptLine[4] = {
"Oh, hi there! ",
"Selec. a Bebida: ",
"OK! ",
"CLEANING "
};
// Selections
String selectionLine[24] = {
" ", //buffer line. Leave here or experience terror.
"1. Vodka ",
"2. Cointreau ",
"3. CranberryJuice ",
"4. Sprite ",
"5. LemonJuice ",
"6. SugarWater ",
"7. BlueCur ",
"8. Gin ",
"9. Vodka sprite ",
"10. Blue Lagoon ",
"11. cosmopolitan ",
"12. Lemon drop ",
"13. Blue Moon ",
"14. Blue Gin Moon ",
"15. Double Strike ",
"16. Tom Collins ",
"17. Flying Dutchman",
"18. London Cosmo ",
"19. Vodka Cranberry",
"20. Cranberry Gin ",
" ", //buffer line. Leave here or experience terror.
" ",
"End of List " //buffer line. Leave here or experience terror.
};
// Create objects
Bounce debounce[4] = Bounce(); //Debouncing Library
//NOTE: The screen address can be 0x27 or 0x3F. If your screen only shows black lines instead of your display, change the object call here.
LiquidCrystal_I2C lcd(0x27, 20, 4); //I2C 4 Row 20 Col LCD Screen at 0x27
//LiquidCrystal_I2C lcd(0x3F, 20, 4); //I2C 4 Row 20 Col LCD Screen at 0x3F
Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800); //Neopixel strip. (Number of LEDs, Pin, Pixels are wired for GRB bitstream and 800 KHz bitstream )
int delayval = 500; // delay for half a second
int promptSelect = 1; // Initialize prompt at 1
int drinkSelectCounter = 1; // Initialize Drink Selection at 1
int PUMP_TIME = 1200; //Time for pumping station to run in milliseconds
int PUMP_TIME1 = 1000;
int PUMP_TIME15 = 1500;
int PUMP_TIME18 = 1800;
int PUMP_TIME2 = 2000;
int PUMP_TIME22 = 2200;
int PUMP_TIME25 = 2500;
int PUMP_TIME3 = 3000;
int PUMP_TIME38 = 3800;
int PUMP_TIME4 = 4000;
int PUMP_TIME5 = 5000;
//setup() runs once
void setup()
{
// Setup the pump and air relay pins as Output :
//pinMode(PUMP_RELAY_PIN, OUTPUT);
//pinMode(CLEAN_RELAY_PIN, OUTPUT);
// Setup the liquid relay pins as Output :
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(RELE_BLOCCO, OUTPUT);
pinMode(EN_PIN, OUTPUT);
ascensore.setMaxSpeed(1400);
ascensore.setAcceleration(500);
ascensore.setCurrentPosition(0);
rubinetto.attach(A1);
rubinetto.write(100); //posizione iniziale föra di ball
for (int i = 0; i < 8; i = i + 1)
{
pinMode(SELECTED_RELAY_PIN[i], OUTPUT);
}
// Setup the button with an internal pull-up :
for (int i = 0; i < 4; i = i + 1)
{
pinMode(BUTTON_PIN[i],INPUT_PULLUP);
debounce[i].attach(BUTTON_PIN[i]);
debounce[i].interval(5);
}
// Neopixel:
strip.begin(); // This initializes the NeoPixel library.
strip.show(); // Initialize all pixels to 'off'
// initlaize the lcd object - this sets up all the variables and IIC setup for the LCD object to work
lcd.init(); // initialize the lcd
lcd.init();;
lcd.backlight();
lcd.setCursor(0,0);
// Print a message to the LCD.
//lcd.print("Fattore");
delay(delayval);
}
//loop() runs indefinitely
void loop()
{
// Update the Bounce instance:
for (int i = 0; i < 4; i = i + 1)
{
debounce[i].update();
value[i] = debounce[i].read();
}
colorWipe(strip.Color(0, 0, 0), 0); // Reset the Neopixel Strip
// LCD
unsigned long currentMillis = millis(); // Update currentMillis
if(currentMillis - previousMillis > interval)
{
// save the last time you refreshed the LCD
previousMillis = currentMillis;
lcd.setCursor(0, 0);
lcd.print(promptLine[promptSelect]);
lcd.setCursor(0, 1);
lcd.print('>');
lcd.setCursor(1, 1);
lcd.print(selectionLine[(drinkSelectCounter)]);
lcd.setCursor(1, 2);
lcd.print(selectionLine[(drinkSelectCounter + 1)]);
lcd.setCursor(1, 3);
lcd.print(selectionLine[(drinkSelectCounter + 2)]);
}
drinkSelectCounter = constrain(drinkSelectCounter, 1, 20); //constrain the possible selection numbers for the drink counter
//Buttons
if ( debounce[0].fell() )
{
drinkSelectCounter = (drinkSelectCounter - 1);
}
if ( debounce[1].fell() )
{
drinkSelectCounter = (drinkSelectCounter + 1);
}
if ( debounce[2].fell() )
{
switch (drinkSelectCounter)
{
case 1: // Vodka
lcd.setCursor(0, 0);
lcd.print(promptLine[2]);
colorWipe(strip.Color(255, 0, 0), 50); // Red
spostaAscensore(giu);
checkObject1();
break;
case 2: // Cointreau
lcd.setCursor(0, 0);
lcd.print(promptLine[2]);
colorWipe(strip.Color(0, 255, 0), 50); // Green
spostaAscensore(giu);
checkObject2();
break;
case 3: // CranberryJuice
lcd.setCursor(0, 0);
lcd.print(promptLine[2]);
colorWipe(strip.Color(0, 0, 255), 50); // Blue
spostaAscensore(giu);
checkObject3();
break;
case 4: // Sprite
lcd.setCursor(0, 0);
lcd.print(promptLine[2]);
colorWipe(strip.Color(255, 255, 0), 50); // Yellow
spostaAscensore(giu);
checkObject4();
break;
case 5: // LemonJuice
lcd.setCursor(0, 0);
lcd.print(promptLine[2]);
colorWipe(strip.Color(255, 255, 255), 50); // White
spostaAscensore(giu);
checkObject5();
break;
case 6: // SugarWater
lcd.setCursor(0, 0);
lcd.print(promptLine[2]);
colorWipe(strip.Color(230, 0, 126), 50); // Pink
spostaAscensore(giu);
checkObject6();
break;
case 7: // BlueCur
lcd.setCursor(0, 0);
lcd.print(promptLine[2]);
colorWipe(strip.Color(254, 161, 25), 50); // Black
spostaAscensore(giu);
checkObject7();
break;
case 8: // Gin
lcd.setCursor(0, 0);
lcd.print(promptLine[2]);
colorWipe(strip.Color(192, 5, 248), 50); // Purple
spostaAscensore(giu);
checkObject8();
break;
case 9: // Vodka sprite
lcd.setCursor(0, 0);
lcd.print(promptLine[2]);
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(255, 255, 0), 50); // Yellow
spostaAscensore(giu);
checkObject9();
break;
case 10: // Blue Lagoon
lcd.setCursor(0, 0);
lcd.print(promptLine[2]);
colorWipe(strip.Color(255, 0, 0), 50); // Red
spostaAscensore(giu);
checkObject10();
break;
case 11: // Cosmo
lcd.setCursor(0, 0);
lcd.print(promptLine[2]);
colorWipe(strip.Color(0, 255, 0), 50); // Green
spostaAscensore(giu);
checkObject11();
break;
case 12: // Lemon drop
lcd.setCursor(0, 0);
lcd.print(promptLine[2]);
colorWipe(strip.Color(255, 255, 255), 50); // White
spostaAscensore(giu);
checkObject12();
break;
case 13: // Blue Moon
lcd.setCursor(0, 0);
lcd.print(promptLine[2]);
colorWipe(strip.Color(5, 5, 5), 50); // Black
spostaAscensore(giu);
checkObject13();
break;
case 14: // Blue Gin Moon
lcd.setCursor(0, 0);
lcd.print(promptLine[2]);
colorWipe(strip.Color(5, 5, 5), 50); // Black
spostaAscensore(giu);
checkObject14();
break;
case 15: // Double Strike
lcd.setCursor(0, 0);
lcd.print(promptLine[2]);
colorWipe(strip.Color(5, 5, 5), 50); // Black
spostaAscensore(giu);
checkObject15();
break;
case 16: // Tom Collins
lcd.setCursor(0, 0);
lcd.print(promptLine[2]);
colorWipe(strip.Color(5, 5, 5), 50); // Black
spostaAscensore(giu);
checkObject16();
break;
case 17: // Flying Dutchman
lcd.setCursor(0, 0);
lcd.print(promptLine[2]);
colorWipe(strip.Color(5, 5, 5), 50); // Black
spostaAscensore(giu);
checkObject17();
break;
case 18: // London Cosmo
lcd.setCursor(0, 0);
lcd.print(promptLine[2]);
colorWipe(strip.Color(5, 5, 5), 50); // Black
spostaAscensore(giu);
checkObject18();
break;
case 19: // Vodka Cranberry
lcd.setCursor(0, 0);
lcd.print(promptLine[2]);
colorWipe(strip.Color(5, 5, 5), 50); // Black
spostaAscensore(giu);
checkObject19();
break;
case 20: // Cranberry Gin
lcd.setCursor(0, 0);
lcd.print(promptLine[2]);
colorWipe(strip.Color(5, 5, 5), 50); // Black
spostaAscensore(giu);
checkObject20();
break;
}
}
if ( debounce[3].fell() )
{
lcd.setCursor(0, 0);
lcd.print(promptLine[3]);
}
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait)
{
for(uint16_t i=0; i<strip.numPixels(); i++)
{
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
//movimento motor nema com driver a4988
void spostaAscensore(int dove)
{
bloccaAscensore(0);
ascensore.moveTo(dove);
ascensore.runToPosition();
bloccaAscensore(1);
}
//desabilita enable driver motor a4988
void bloccaAscensore(bool stato)
{
if(stato) // solo perché serve farli in ordine diverso a seconda se sto bloccando o sbloccando
{
digitalWrite(EN_PIN, HIGH);
digitalWrite(RELE_BLOCCO, LOW);
} else {
digitalWrite(RELE_BLOCCO, HIGH);
digitalWrite(EN_PIN, LOW);
}
}
//inicia sensor ultrasonico hc-sr04
void checkObject1() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.034) / 2;
Serial.print("Distância: ");
Serial.println(distance);
if (distance < dis) {
activateRelay1();
} else {
spostaAscensore(su);
}
}
//rele 01 da bebida 01
void activateRelay1() {
rubinetto.write(36);
delay(500);
digitalWrite(SELECTED_RELAY_PIN[0], HIGH); // Open Solenoid valve 1
delay(PUMP_TIME); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[0], LOW); // Close Solenoid valve 1
delay(1000);
rubinetto.write(100);
spostaAscensore(su);
}
//inicia sensor ultrasonico hc-sr04
void checkObject2() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.034) / 2;
Serial.print("Distância: ");
Serial.println(distance);
if (distance < dis) {
activateRelay2();
} else {
spostaAscensore(su);
}
}
//rele 02 da bebida 02
void activateRelay2() {
delay(500);
rubinetto.write(36);
digitalWrite(SELECTED_RELAY_PIN[1], HIGH); // Open Solenoid valve 2
delay(PUMP_TIME); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[1], LOW); // Close Solenoid valve 2
delay(500);
rubinetto.write(100);
spostaAscensore(su);
}
//inicia sensor ultrasonico hc-sr04
void checkObject3() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.034) / 2;
Serial.print("Distância: ");
Serial.println(distance);
if (distance < dis) {
activateRelay3();
} else {
spostaAscensore(su);
}
}
//rele 03 da bebida 03
void activateRelay3() {
delay(500);
rubinetto.write(36);
digitalWrite(SELECTED_RELAY_PIN[2], HIGH); // Open Solenoid valve 3
delay(PUMP_TIME); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[2], LOW); // Close Solenoid valve 3
delay(500);
rubinetto.write(100);
spostaAscensore(su);
}
//inicia sensor ultrasonico hc-sr04
void checkObject4() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.034) / 2;
Serial.print("Distância: ");
Serial.println(distance);
if (distance < dis) {
activateRelay4();
} else {
spostaAscensore(su);
}
}
void activateRelay4() {
delay(500);
rubinetto.write(36);
digitalWrite(SELECTED_RELAY_PIN[3], HIGH); // Open Solenoid valve 4
delay(PUMP_TIME); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[3], LOW); // Close Solenoid valve 4
rubinetto.write(100);
spostaAscensore(su);
}
void checkObject5() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.034) / 2;
Serial.print("Distância: ");
Serial.println(distance);
if (distance < dis) {
activateRelay5();
} else {
spostaAscensore(su);
}
}
void activateRelay5() {
delay(500);
rubinetto.write(36);
digitalWrite(SELECTED_RELAY_PIN[4], HIGH); // Open Solenoid valve 5
delay(PUMP_TIME); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[4], LOW); // Close Solenoid valve 5
rubinetto.write(100);
spostaAscensore(su);
}
void checkObject6() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.034) / 2;
Serial.print("Distância: ");
Serial.println(distance);
if (distance < dis) {
activateRelay6();
} else {
spostaAscensore(su);
}
}
void activateRelay6() {
delay(500);
rubinetto.write(36);
digitalWrite(SELECTED_RELAY_PIN[5], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[5], LOW); // Close Solenoid valve 6
rubinetto.write(100);
spostaAscensore(su);
}
void checkObject7() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.034) / 2;
Serial.print("Distância: ");
Serial.println(distance);
if (distance < dis) {
activateRelay7();
} else {
spostaAscensore(su);
}
}
void activateRelay7() {
delay(500);
rubinetto.write(36);
digitalWrite(SELECTED_RELAY_PIN[6], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[6], LOW); // Close Solenoid valve 6
rubinetto.write(100);
spostaAscensore(su);
}
void checkObject8() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.034) / 2;
Serial.print("Distância: ");
Serial.println(distance);
if (distance < dis) {
activateRelay8();
} else {
spostaAscensore(su);
}
}
void activateRelay8() {
delay(500);
rubinetto.write(36);
digitalWrite(SELECTED_RELAY_PIN[7], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[7], LOW); // Close Solenoid valve 6
rubinetto.write(100);
spostaAscensore(su);
}
void checkObject9() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.034) / 2;
Serial.print("Distância: ");
Serial.println(distance);
if (distance < dis) {
activateRelay9();
} else {
spostaAscensore(su);
}
}
void activateRelay9() {
delay(500);
rubinetto.write(36);
digitalWrite(SELECTED_RELAY_PIN[0], HIGH); // Open Solenoid valve 1
delay(PUMP_TIME3); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[0], LOW); // Open Solenoid valve 1
digitalWrite(SELECTED_RELAY_PIN[3], HIGH); // Open Solenoid valve 4
delay(PUMP_TIME5); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[3], LOW); // Open Solenoid valve 4
rubinetto.write(100);
spostaAscensore(su);
}
void checkObject10() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.034) / 2;
Serial.print("Distância: ");
Serial.println(distance);
if (distance < dis) {
activateRelay10();
} else {
spostaAscensore(su);
}
}
void activateRelay10() {
delay(500);
rubinetto.write(36);
digitalWrite(SELECTED_RELAY_PIN[0], HIGH); // Open Solenoid valve 1
delay(PUMP_TIME2); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[0], LOW); // Open Solenoid valve 1
digitalWrite(SELECTED_RELAY_PIN[3], HIGH); // Open Solenoid valve 4
delay(PUMP_TIME5); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[3], LOW); // Open Solenoid valve 4
digitalWrite(SELECTED_RELAY_PIN[4], HIGH); // Open Solenoid valve 4
delay(PUMP_TIME18); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[4], LOW); // Open Solenoid valve 4
digitalWrite(SELECTED_RELAY_PIN[5], HIGH); // Open Solenoid valve 4
delay(PUMP_TIME1); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[5], LOW); // Open Solenoid valve 4
digitalWrite(SELECTED_RELAY_PIN[6], HIGH); // Open Solenoid valve 4
delay(PUMP_TIME18); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[6], LOW); // Open Solenoid valve 4
rubinetto.write(100);
spostaAscensore(su);
}
void checkObject11() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.034) / 2;
Serial.print("Distância: ");
Serial.println(distance);
if (distance < dis) {
activateRelay11();
} else {
spostaAscensore(su);
}
}
void activateRelay11() {
delay(500);
rubinetto.write(36);
digitalWrite(SELECTED_RELAY_PIN[0], HIGH); // Open Solenoid valve 2
delay(PUMP_TIME25); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[0], LOW); // Open Solenoid valve 2
digitalWrite(SELECTED_RELAY_PIN[1], HIGH); // Open Solenoid valve 3
delay(PUMP_TIME15); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[1], LOW); // Open Solenoid valve 3
digitalWrite(SELECTED_RELAY_PIN[2], HIGH); // Open Solenoid valve 3
delay(PUMP_TIME38); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[2], LOW); // Open Solenoid valve 3
digitalWrite(SELECTED_RELAY_PIN[4], HIGH); // Open Solenoid valve 3
delay(PUMP_TIME); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[4], LOW); // Open Solenoid valve 3
digitalWrite(SELECTED_RELAY_PIN[5], HIGH); // Open Solenoid valve 3
delay(PUMP_TIME); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[5], LOW); // Open Solenoid valve 3
rubinetto.write(100);
spostaAscensore(su);
}
void checkObject12() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.034) / 2;
Serial.print("Distância: ");
Serial.println(distance);
if (distance < dis) {
activateRelay12();
} else {
spostaAscensore(su);
}
}
void activateRelay12() {
delay(500);
rubinetto.write(36);
digitalWrite(SELECTED_RELAY_PIN[0], HIGH); // Open Solenoid valve 5
delay(PUMP_TIME15); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[0], LOW); // Open Solenoid valve 5
digitalWrite(SELECTED_RELAY_PIN[1], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME15); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[1], LOW); // Open Solenoid valve 6
digitalWrite(SELECTED_RELAY_PIN[4], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME18); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[4], LOW); // Open Solenoid valve 6
digitalWrite(SELECTED_RELAY_PIN[5], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[5], LOW); // Open Solenoid valve 6
rubinetto.write(100);
spostaAscensore(su);
}
void checkObject13() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.034) / 2;
Serial.print("Distância: ");
Serial.println(distance);
if (distance < dis) {
activateRelay13();
} else {
spostaAscensore(su);
}
}
void activateRelay13() {
delay(500);
rubinetto.write(36);
digitalWrite(SELECTED_RELAY_PIN[0], HIGH); // Open Solenoid valve 4
delay(PUMP_TIME2); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[0], LOW); // Open Solenoid valve 4
digitalWrite(SELECTED_RELAY_PIN[2], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME3); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[2], LOW); // Open Solenoid valve 6
digitalWrite(SELECTED_RELAY_PIN[4], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME18); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[4], LOW); // Open Solenoid valve 6
digitalWrite(SELECTED_RELAY_PIN[5], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[5], LOW); // Open Solenoid valve 6
digitalWrite(SELECTED_RELAY_PIN[6], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[6], LOW); // Open Solenoid valve 6
rubinetto.write(100);
spostaAscensore(su);
}
void checkObject14() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.034) / 2;
Serial.print("Distância: ");
Serial.println(distance);
if (distance < dis) {
activateRelay14();
} else {
spostaAscensore(su);
}
}
void activateRelay14() {
delay(500);
rubinetto.write(36);
digitalWrite(SELECTED_RELAY_PIN[2], HIGH); // Open Solenoid valve 4
delay(PUMP_TIME2); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[2], LOW); // Open Solenoid valve 4
digitalWrite(SELECTED_RELAY_PIN[4], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME18); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[4], LOW); // Open Solenoid valve 6
digitalWrite(SELECTED_RELAY_PIN[5], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[5], LOW); // Open Solenoid valve 6
digitalWrite(SELECTED_RELAY_PIN[6], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[6], LOW); // Open Solenoid valve 6
digitalWrite(SELECTED_RELAY_PIN[7], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME2); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[7], LOW); // Open Solenoid valve 6
rubinetto.write(100);
spostaAscensore(su);
}
void checkObject15() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.034) / 2;
Serial.print("Distância: ");
Serial.println(distance);
if (distance < dis) {
activateRelay15();
} else {
spostaAscensore(su);
}
}
void activateRelay15() {
delay(500);
rubinetto.write(36);
digitalWrite(SELECTED_RELAY_PIN[0], HIGH); // Open Solenoid valve 4
delay(PUMP_TIME2); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[0], LOW); // Open Solenoid valve 4
digitalWrite(SELECTED_RELAY_PIN[2], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME3); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[2], LOW); // Open Solenoid valve 6
digitalWrite(SELECTED_RELAY_PIN[4], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME18); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[4], LOW); // Open Solenoid valve 6
digitalWrite(SELECTED_RELAY_PIN[6], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[6], LOW); // Open Solenoid valve 6
rubinetto.write(100);
spostaAscensore(su);
}
void checkObject16() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.034) / 2;
Serial.print("Distância: ");
Serial.println(distance);
if (distance < dis) {
activateRelay16();
} else {
spostaAscensore(su);
}
}
void activateRelay16() {
delay(500);
rubinetto.write(36);
digitalWrite(SELECTED_RELAY_PIN[3], HIGH); // Open Solenoid valve 4
delay(PUMP_TIME4); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[3], LOW); // Open Solenoid valve 4
digitalWrite(SELECTED_RELAY_PIN[4], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME18); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[4], LOW); // Open Solenoid valve 6
digitalWrite(SELECTED_RELAY_PIN[5], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME18); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[5], LOW); // Open Solenoid valve 6
digitalWrite(SELECTED_RELAY_PIN[7], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME22); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[7], LOW); // Open Solenoid valve 6
rubinetto.write(100);
spostaAscensore(su);
}
void checkObject17() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.034) / 2;
Serial.print("Distância: ");
Serial.println(distance);
if (distance < dis) {
activateRelay17();
} else {
spostaAscensore(su);
}
}
void activateRelay17() {
delay(500);
rubinetto.write(36);
digitalWrite(SELECTED_RELAY_PIN[1], HIGH); // Open Solenoid valve 4
delay(PUMP_TIME2); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[1], LOW); // Open Solenoid valve 4
digitalWrite(SELECTED_RELAY_PIN[4], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[4], LOW); // Open Solenoid valve 6
digitalWrite(SELECTED_RELAY_PIN[5], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME1); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[5], LOW); // Open Solenoid valve 6
digitalWrite(SELECTED_RELAY_PIN[7], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME2); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[7], LOW); // Open Solenoid valve 6
rubinetto.write(100);
spostaAscensore(su);
}
void checkObject18() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.034) / 2;
Serial.print("Distância: ");
Serial.println(distance);
if (distance < dis) {
activateRelay18();
} else {
spostaAscensore(su);
}
}
void activateRelay18() {
delay(500);
rubinetto.write(36);
digitalWrite(SELECTED_RELAY_PIN[1], HIGH); // Open Solenoid valve 4
delay(PUMP_TIME2); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[1], LOW); // Open Solenoid valve 4
digitalWrite(SELECTED_RELAY_PIN[2], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME5); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[2], LOW); // Open Solenoid valve 6
digitalWrite(SELECTED_RELAY_PIN[3], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME18); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[3], LOW); // Open Solenoid valve 6
digitalWrite(SELECTED_RELAY_PIN[7], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME2); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[7], LOW); // Open Solenoid valve 6
rubinetto.write(100);
spostaAscensore(su);
}
void checkObject19() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.034) / 2;
Serial.print("Distância: ");
Serial.println(distance);
if (distance < dis) {
activateRelay19();
} else {
spostaAscensore(su);
}
}
void activateRelay19() {
rubinetto.write(36);
digitalWrite(SELECTED_RELAY_PIN[0], HIGH); // Open Solenoid valve 4
delay(PUMP_TIME2); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[0], LOW); // Open Solenoid valve 4
digitalWrite(SELECTED_RELAY_PIN[2], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME5); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[2], LOW); // Open Solenoid valve 6
digitalWrite(SELECTED_RELAY_PIN[5], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME22); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[5], LOW); // Open Solenoid valve 6
rubinetto.write(100);
spostaAscensore(su);
}
void checkObject20() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration * 0.034) / 2;
Serial.print("Distância: ");
Serial.println(distance);
if (distance < dis) {
activateRelay20();
} else {
spostaAscensore(su);
}
}
void activateRelay20() {
delay(500);
rubinetto.write(36);
digitalWrite(SELECTED_RELAY_PIN[2], HIGH); // Open Solenoid valve 4
delay(PUMP_TIME5); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[2], LOW); // Open Solenoid valve 4
digitalWrite(SELECTED_RELAY_PIN[4], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME2); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[4], LOW); // Open Solenoid valve 6
digitalWrite(SELECTED_RELAY_PIN[7], HIGH); // Open Solenoid valve 6
delay(PUMP_TIME22); // Run for the set amount of time
digitalWrite(SELECTED_RELAY_PIN[7], LOW); // Open Solenoid valve 6
rubinetto.write(100);
spostaAscensore(su);
}up
down
enter
12