Hello to All,
I am working on one college project but fail to complete it due to some coding issue.
As im new to coding and trying this project from last 2months but still im stuck.
Everyone please suggest were im wrong in coding and how it can be made .
My project is concern about the pressure sensor and pump .
1-i want to set the pressure level with button1 and button2 which will display on LCD......Which i have done.
2-after that i will press button4 to set the ON and OFF time to run the motor.once time is set i will press button3 and process start. which i am not able to do.
i want to set the time duration in Minutes .
I am attaching my schematic of project......and code below.
Please please help,teach,suggest......
#include <LiquidCrystal.h>
LiquidCrystal lcd (12,11,5,4,3,2);
const byte button1= 7; //----------------Increment------------------------//
const byte button2= 8;
const byte button3= 9; //----------------Decrement------------------------//
const int button4= 6;
int pump= 50;
//int sensor=A1;
//--------------------------------------------------------------------------------------------------------------------//
unsigned long duration= 0; /////.......how long to run pump in minute.....
unsigned long starttime= 0; ////........how long to run pump in minute.....
int startime=0;
int stoptime=0; ///
int state=LOW;
//-------------------------------------------------------------------------------------------------------------------//
int buttonPushCounter =0; ////.........initial value..........
int buttonState1 =0; ////.........initial value..........
int buttonState2 =0; ////.........initial value..........
int buttonState3 =0;
int buttonState4 =0;
int lastButtonState =0 ; ////.........initial value..........
//volatile int sen =2;
void setPressure(); ////.........set pressure sensor function.........
//unsigned long runCycle(); ///..........set runcycle start and stop the motor..........
void welCome();
//void Liquid();
void Vaccum();
void Lcd();
void setup() {
// put your setup code here, to run once:
pinMode(button1, INPUT); ///.........Up arrow increment button.....
pinMode(button2, INPUT); ///.........down arrow decrement button....
pinMode(sensor,INPUT); ///...........Pressure sensor......
pinMode(button3, INPUT); ///............Enter buttton........
pinMode(pump,OUTPUT); ///........... pump.........
pinMode(8,OUTPUT);
pinMode(button4,INPUT);
// attachInterrupt(0,Liquid,CHANGE);
Serial.begin(9600);
lcd.begin(16,2);
lcd.display();
lcd.setCursor(3,0);
lcd.print("HELLO");
lcd.setCursor(2,1);
lcd.print("WELCOME YOU");
delay(5000);
if(buttonState3==LOW)
{
lcd.clear();
lcd.setCursor(2,0);
lcd.print("PRESS ENTER");
lcd.setCursor(3,1);
lcd.print("TO BEGIN");
delay(1000);
lcd.clear();
}
}
void loop() {
// put your main code here, to run repeatedly:
int buttonState1 = digitalRead(button1);
int buttonState2 = digitalRead(button2);
int buttonState3 = digitalRead(button3);
int buttonState4=digitalRead(button4);
int state=LOW;
setPressure();
if (buttonState1 != lastButtonState)
{
if (buttonState1 == HIGH)
{
buttonPushCounter+=10;
buttonPushCounter=constrain(buttonPushCounter,10,90);
lcd.setCursor(2,1);
lcd.print(buttonPushCounter);
lcd.setCursor(5,1);
lcd.print("mmgh");
delay(500);
}
}
lastButtonState = buttonState1;
if (buttonState2 != lastButtonState)
if(buttonState2==HIGH)
{
{
buttonPushCounter-=10;
buttonPushCounter=constrain(buttonPushCounter,10,100);
lcd.setCursor(2,1);
lcd.print(buttonPushCounter);
lcd.setCursor(5,1);
lcd.print("mmgh");
delay(500);
}
}
lastButtonState = buttonState2;
if(buttonState4==HIGH)
{
Vaccum();
}
}
//------------------------------------------------------Welcome dispaly function-------------------------------------------------//
void welCome()
{
if(buttonState3==LOW)
{
lcd.clear();
lcd.setCursor(2,0);
lcd.print("PRESS ENTER");
lcd.setCursor(3,1);
lcd.print("TO BEGIN");
delay(1000);
lcd.clear();
}
}
//------------------------------------------------------Set pressure value----------------------------------------------------//
void setPressure()
{
lcd.setCursor(0,0);
lcd.print("SET PRESSURE");
lcd.setCursor(0,1);
lcd.print("P=");
}
///---------------------- display Vaccum set time ----------------------------
void Vaccum()
{
lcd.clear();
buttonState4=digitalRead(button4);
while(buttonState4==HIGH )
{
lcd.setCursor(0,0);
lcd.print("Vaccum ON");
lcd.setCursor(0,1);
lcd.print("T=");
delay(1000);
if (buttonState1 != lastButtonState)
{
if (buttonState1 == HIGH)
{
buttonPushCounter++;
buttonPushCounter=constrain(buttonPushCounter,1,10);
lcd.setCursor(3,1);
lcd.print(buttonPushCounter);
lcd.setCursor(5,1);
lcd.print("Minutes");
delay(500);
}
}
lastButtonState = buttonState1;
if (buttonState2 != lastButtonState)
if(buttonState2==HIGH)
{
{
buttonPushCounter--;
buttonPushCounter=constrain(buttonPushCounter,1,10);
lcd.setCursor(3,1);
lcd.print(buttonPushCounter);
lcd.setCursor(5,1);
lcd.print("Minutes");
delay(500);
}
}
lastButtonState = buttonState2;
}
}