Hello I am very new to the wonderful world of Arduino.
I have made a basic setup to fill up a grain hopper. What i want to end up with is two levels MIN and MAX, where a relay is triggered for 15 seconds every minute, whenever the MIN level is reached and continue that loop until MAX.
I dont want the loop to start as soon as the level is below MAX. Hope this makes sense.
Attached is a picture of my simle setup. The LED is a substitute for the relay.
Here is my code:
const int trigPin = 9; //Define the HC-SE04 triger on pin 9 on the arduino
const int echoPin = 10; //Define the HC-SE04 echo on pin 10 on the arduino
const int bulb = 4; //Define the relay signal on pin 4 on the arduino
const int MIN = 150; //Minimum level in tank, sensor is meassuring vertically down so above 150 is below min
const int MAX = 50; //Max level in tank
const int MOTOR = 15000; // Fill motor run time in millisec
const int BREAK = 60000; // Cycle time in millisec
void setup()
{
Serial.begin (9600); //Start the serial monitor
pinMode(trigPin, OUTPUT); //set the trigpin to output
pinMode(echoPin, INPUT); //set the echopin to input
pinMode (bulb, OUTPUT); //set the bulb on pin 4 to output (this will be a relay in the finished project)
}
void loop()
{
int duration, distance; //Define two intregers duration and distance to be used to save data
digitalWrite(trigPin, HIGH); //write a digital high to the trigpin to send out the pulse
delayMicroseconds(500); //wait half a millisecond
digitalWrite(trigPin, LOW); //turn off the trigpin
duration = pulseIn(echoPin, HIGH); //measure the time using pulsein when the echo receives a signal set it to high
distance = (duration/2) / 29.1; //distance is the duration devided by 2 becasue the signal traveled from the trigpin then back to the echo pin, then divide by 29.1 to convert to centimeters
if (distance < MIN && distance > MAX) //run fill loop if distance is between MIN and MAX
{
digitalWrite(bulb,HIGH);
delay(MOTOR);
digitalWrite(bulb,LOW);
delay(BREAK);
}
else
{
delay(BREAK);
}
Serial.print(distance); //Dispaly the distance on the serial monitor
Serial.println(" CM"); //in centimeters
delay(500); //delay half a second
}
I have tried to read up on bool and boolean but cannot get it to make sense in my brain.
Any assistance is greatly appreciated.

