The program start when the start button is get low value and sol on when level get value low the loop start for 10 loop the problem in the num 8 or 9 in loop arduino reset or stop working and cannot complete the program
the Code
#include <EEPROM.h>
const int start = 0;
const int level2 = 10;
const int level = 2;
const int s1 = 3;
const int s2 = 4;
const int h = 5;
const int p = 6;
const int kR = 7;
const int kL = 8;
const int kF = 9;
// Variables will change:
int address = 0 ;
int counter;
int numWach = 0 ;
int numRis = 0 ;
unsigned long previousMillis = 0; // will store last time was updated
// constants won't change:
const long interval = 1000; // interval at which to blink (milliseconds)
int levelPushCounter = 0; // counter for the number of button presses
int levelState = 0; // current state of the button
int lastlevelState = 1; // previous state of the button
int level2State = 0 ; // current state of the button
int lastlevel2State = 1; // previous state of the button
int startState = 0; // current state of the button
int lastStartState = 1; // previous state of the button
/*
*** Functions
/
void motorRight() {
/*
*** Motor ON For 15 Sec And Delay Off 5 Sec
**/
digitalWrite(kR, HIGH);
Serial.println(" kR is ON For 12 Sec... ");
delay(12000);
digitalWrite(kR, LOW);
Serial.println(" kR is OFF 3 Sec... ");
delay(3000);
}
void motorLeft() {
/**
*** Motor ON For 15 Sec And Delay Off 5 Sec And Pump On For 20 Sec
/
digitalWrite(kL, HIGH);
Serial.println(" kL is ON For 12 Sec... ");
delay(12000);
/
*** Motor Left
**/
digitalWrite(kL, LOW);
Serial.println(" kL is OFF 3 Sec... ");
delay(3000);
}
void solON() {
digitalWrite(s1, HIGH);
digitalWrite(s2, HIGH);
Serial.println("S1,S2 is ON ....");
}
void solOff() {
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
Serial.println(" S1 & S2 is OFF ....");
}
void heaterON()
{
digitalWrite(h, HIGH);
Serial.println(" Heater On ");
}
void heateroff()
{
digitalWrite(h, LOW);
Serial.println(" Heater off ");
}
void pumpON() {
solOff();
heateroff();
delay(2000);
digitalWrite(p, HIGH);
Serial.println(" pump is ON ");
}
void pumpOff() {
digitalWrite(p, LOW);
Serial.println(" pump is off... ");
}
void kFastON() {
digitalWrite(kF, HIGH);
Serial.println(" kF is on ....");
}
void kFastOFF() {
digitalWrite(kF, LOW);
Serial.println(" kF is OFF ....");
}
void WachLoop()
{
for (int i = 0; i < 10 ; i++) {
heaterON();
Serial.println(" Loop No. ");
Serial.println(i);
motorRight();
motorLeft();
motorRight();
motorLeft();
motorRight();
motorLeft();
motorRight();
motorLeft();
}// end while loop
}
void wach()
{
// function Wach
Serial.println(" ----------------------- ");
Serial.println(" Clean Program Is Start For 20 min");
Serial.println(" ----------------------- ");
solOff();
WachLoop();
pumpON();
delay(55000);
pumpOff();
Serial.println(" ----------------------- ");
Serial.println(" End Of Clean Program");
Serial.println(" ----------------------- ");
}
void secound()
{
Serial.println(" ----------------------- ");
Serial.println(" Washing Program Is Start For 10 min ");
Serial.println(" ----------------------- ");
for (int i = 0; i < 12; i++) {
solON();
Serial.println(" Loop No. ");
Serial.println(i);
heaterON();
motorRight();
motorLeft();
motorRight();
motorLeft();
pumpON();
delay(8000);
pumpOff();
}// end while loop
Serial.println(" ----------------------- ");
Serial.println(" End Of Washing Program");
Serial.println(" ----------------------- ");
}
void last()
{
Serial.println(" ----------------------- ");
Serial.println(" Last Program Is Start For 10 min ");
Serial.println(" ----------------------- ");
pumpON();
delay(50000);
kFastON();
delay(120000);
kFastOFF();
pumpOff();
Serial.println(" ----------------------- ");
Serial.println(" End Of Program ");
Serial.println(" ----------------------- ");
}
void check()
{
counter ++;
EEPROM.write(address, counter);
Serial.println(" ======== ");
Serial.println(" Demo version Will End after ");
Serial.println(" ======== ");
Serial.println(200 - counter);
Serial.println(" Program ");
}
/*************************/
void setup() {
// put your setup code here, to run once:
Serial.begin( 115200 );
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(h, OUTPUT);
pinMode(p, OUTPUT);
pinMode(kR, OUTPUT);
pinMode(kL, OUTPUT);
pinMode(kF, OUTPUT);
pinMode(start, INPUT_PULLUP);
pinMode(level, INPUT_PULLUP);
pinMode(level2, INPUT_PULLUP);
Serial.println(" Welcome Smart Control Team ..");
//attachInterrupt(digitalPinToInterrupt(level), heaterOFF , HIGH);
//assign counter the value of address 0
counter = EEPROM.read(0);
// write a 0 to address 0
//EEPROM.write(address, 0);
}
void loop() {
// read the pushbutton input pin:
startState = digitalRead(start);
//levelState = digitalRead(level);
/*unsigned long currentMillis = millis();
if (currentMillis - previousMillis > interval) {
previousMillis = currentMillis;}*/
// compare the buttonState to its previous state
if (startState != lastStartState) {
if (startState == LOW) {
if (counter < 200) {
check();
wachStart:
solON();
numWach ++ ;
delay(30000);
levelState = digitalRead(level);
Serial.println(" levelState = " );
Serial.println(levelState);
if (levelState != lastlevelState) {
// if the state has changed, increment the counter
if (levelState == LOW) {
// start program wach
wach();
} else {
heateroff();
}
// Delay a little bit to avoid bouncing
delay(50);
// start sol on
} else {
if (numWach < 10)
{
goto wachStart;
} else {
Serial.println("-- Oops Noo Water ---");
goto end;
}
}// end if levelState
lastlevelState = levelState;
rising:
numRis ++;
solON();
delay(30000);
level2State = digitalRead(level);
Serial.println(" level2State = " );
Serial.println(level2State);
// lastlevel2State = level2State;
if (level2State != lastlevel2State) {
// if the state has changed, increment the counter
if (level2State == LOW) {
// start program wach
secound();
} else {
heateroff();
}
// Delay a little bit to avoid bouncing
delay(50);
} else {
if (numRis < 10)
{
goto rising;
} else {
Serial.println("-- Oops Noo Water ---");
goto end;
}
}// end else if lastlevelState High
lastlevel2State = level2State;
delay(5000);
last();
} else {
Serial.println(" ************************************ ");
Serial.println(" ** ERROR PLease Call Smart Control Team **");
Serial.println(" ************************************ ");
}// end else if counter
} else {
// Serial.println(" Push Start To Start The Machine Program ");
}// end startState
}// end lastStartState
end:
lastStartState = startState;
}