Automatic filling line Arduino

A small sketch for arduino. Automatic liquid filling line with menu control on the display 16 * 2

Automatic filling line Arduino
Automatic filling line Arduino

This example shows the code for programming Arduino. This results in a liquid filling line.


#include <EEPROM.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

//Это на ультрозуковой датчик, который измеряет уровень жидкости
#define echopin A4 // echo pin
#define trigpin A5 // Trigger pin

int cont = 0;

// кнопки меню 
int in1 = A0;
int in2 = A1;
int in3 = A2;
int in4 = A3;

int remotePins [] = { A0, A1, A2, A3};

int set = 0;
int stop = 0, stop1;
int mode = 0;

int buz = 13;// это походу пищалка
int timer = 0;
 
int pump = 8;// реле насоса воды
int motor = 9;// реле мотора

int ir_start = 10; //иф датчик 1
int ir_fill = 11; //иф датчик 2 вероятно это датчик налива
int ir_stop = 12; //иф датчик 3


int dist;
long duration;

int val1=0,val2=0,val3=0,val4=1;
long result=0;

void setup(){
 for (int i = 0; i < 5; i ++) {
  pinMode (remotePins [i], INPUT);
  digitalWrite(remotePins [i], HIGH);
}

pinMode(ir_fill, INPUT);
pinMode(ir_start, INPUT);
pinMode(ir_stop, INPUT);

pinMode (trigpin, OUTPUT);
pinMode (echopin, INPUT);

pinMode(motor, OUTPUT);
pinMode(pump, OUTPUT);
pinMode(buz, OUTPUT);
digitalWrite(buz,LOW);

lcd.init();
lcd.backlight();
lcd.setCursor(0,0);lcd.print("   WELCOME  To  ");
lcd.setCursor(0,1);lcd.print("Automatic  Water");
delay(500); 
Serial.begin(9600);
//Write();
Read();
//analogWrite(motor, 100);
 for (int i = 0; i < 5; i ++) {
dist = data1();
data2();
delay(100); 
}
lcd.clear(); 
}

void loop(){
digitalWrite(buz,LOW);
  
if(stop==0){
if(digitalRead (in1) == 0){ //читаем первую кнопку
lcd.clear();
mode = mode+1; 
if(mode>4){mode=0;
Write();
Read();
lcd.setCursor(0,0);
lcd.print("Ok Saved Data ");
delay(1000);
}
delay(300);}
  
if(digitalRead (in2) == 0){
if(mode==1){val1 = val1+1;}
if(mode==2){val2 = val2+1;}
if(mode==3){val3 = val3+1;}
if(mode==4){val4 = val4+1;}
if(val1>9){val1=0;}
if(val2>9){val2=0;}
if(val3>9){val3=0;}
if(val4>9){val4=0;}
delay(300);
}
}

if(mode==0){
if(digitalRead (in3) == 0){stop=0;}
if(digitalRead (in4) == 0){stop=1;}

//lcd.setCursor(0,0);lcd.print("   WELCOME  To  ");

lcd.setCursor(0,0);
lcd.print("Tank Level=");
lcd.print(dist);
lcd.print("%   ");

lcd.setCursor(0,1);
lcd.print("Fill Time =");
lcd.print(result);  
lcd.print("   ");

}else{

lcd.setCursor(0,0);
lcd.print("Set Time= ");
lcd.print(val4); 
lcd.print(val3);
lcd.print(val2);
lcd.print(val1);

if(mode==4) {lcd.setCursor(10,1);lcd.print("-");} 
if(mode==3) {lcd.setCursor(11,1);lcd.print("-");}
if(mode==2) {lcd.setCursor(12,1);lcd.print("-");} 
if(mode==1) {lcd.setCursor(13,1);lcd.print("-");} 
}

//манипуляции с моторами и датчиками
if(stop==1){   
if(digitalRead (ir_stop) == 1){digitalWrite(motor, HIGH);
if(digitalRead (ir_fill) == 0){
if(stop1==0){stop1=1;
digitalWrite(motor, LOW); 
delay(200);
digitalWrite(pump, HIGH);
delay(result);
digitalWrite(pump, LOW);
//for (int i = 0; i < 10; i ++) {
//dist = data1();
//data2();
delay(200); 
//}
digitalWrite(motor, HIGH);
}
}
if(digitalRead (ir_start) == 0){stop1=0;}
}else{
digitalWrite(motor, LOW);
delay(300);
digitalWrite(buz, HIGH);
delay(300);
digitalWrite(buz, LOW);
}
}else{digitalWrite(motor, LOW);}

}
void Read(){
val1 = EEPROM.read(11); val2 = EEPROM.read(12); val3 = EEPROM.read(13); val4 = EEPROM.read(14);  
result = val4*1000+val3*100+val2*10+val1;  
Serial.println(result);  
}

void Write(){  
EEPROM.write(11, val1);EEPROM.write(12, val2);EEPROM.write(13, val3);EEPROM.write(14, val4);
}


void data2(){
dist = map(dist, 2, 30, 100, 0);
if(dist>100){dist=100;}
if(dist<0){dist=0;}  
}

long data1(){
 digitalWrite(trigpin,LOW);
 delayMicroseconds(2);
 digitalWrite(trigpin,HIGH);
 delayMicroseconds(10);
 duration=pulseIn (echopin,HIGH);
 return duration / 29 / 2; 
}

 



on the site are taken from open sources. The site does not contain files for download. All links to files from open sources. Owners of copyrights to the material may request removal of the post from the site.