Hi, I will try to not have much pain in the butt. So what I'm trying to do is simple except I can not figure out the best way to do it. Im working on an art project and i need to turn a relay on
I need help. I took a project that has me just a little confused on how to combine all the different functions I need to happen. I can make them all happen separately but combining them has thrown me for a loop. I want the push button to activate the relay and the relay will turn itself off when the water is full.
Thank you for reading and helping.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
#define echopin 9 // PIN HC
#define trigpin 8 // PIN HC
const int button = 2;
const int relay = 13;
int buttonState = 0;
int maximumRange = 150;
long duration, distance;
void setup()
{
lcd.init();
lcd.init();
lcd.backlight();
lcd.begin(20,4);
Serial.begin (9600);
pinMode (trigpin, OUTPUT);
pinMode (echopin, INPUT );
pinMode (4, OUTPUT);
pinMode (13,OUTPUT);pinMode(relay, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(button, INPUT_PULLUP);
}void loop ()
{
{digitalWrite(trigpin,LOW);
delayMicroseconds(2);digitalWrite(trigpin,HIGH);
delayMicroseconds(10);duration=pulseIn (echopin,HIGH);
distance= duration/58.2;
delay (50);
Serial.println(distance);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("AUTO PROCESS SYSTEMS");
lcd.setCursor(0,1);
lcd.print("--------------------");
lcd.setCursor(1,2);
lcd.print("Current Level: ");
lcd.print(distance);
delay(100);}
if (distance >= 25 ){
digitalWrite (7,LOW);// connect to relay(motor)
digitalWrite (13,LOW);
lcd.setCursor(2,3);
lcd.print("Motor Started!!!");
delay(100);
}else if (distance <=5) {
digitalWrite (7,HIGH); // connect to relay(motor)
digitalWrite (13,HIGH);
lcd.setCursor(3,3);
lcd.print("Tank is FULL!!");
delay(100);}
buttonState = digitalRead(button);
// check if the pushbutton is pressed.
// if it is, the buttonState is LOW:
if (buttonState == LOW) {
digitalWrite(relay, LOW);
delay (1000);
} else {
digitalWrite(relay, HIGH);
}
}