Grain hopper limit switch

I am trying to design a system that has a hopper that is filled by a auger. I want it to have a high and low limit switch. When the level in the hopper reaches the bottom limit switch I would like it to run my auger ( controlled by a relay) until it is full and trips the high limit. Then it needs to wait till it trips the low limit again. Also i need to have a second auger hopper system running but it needs to switch on the relay when it trips the high limit and off when it trips the low. There will also be a third relay that is simply on or off. How do I run all this in the same sketch? Thanks for any help! I am a novice at this and anything helps.

What is the problem? The project look higly feasable.

The problem is I am not sure how to write the code. I know the basics but I’m struggling to figure this one out.

Get started trying! Write some code that reads an input and when that works some more code that handles an output like a relay. Watch the electrical needs for any relay. They often need more current then the 20 mA that an Arduino can give. Use INPUT_PULLUP and buttons connected between GND and input.

I know how to do both of those. Other than the pull up. I have a simple code wrote at the moment to turn on a LED which is in place of my relay for simplicity.t I have to engage two switches for it to turn on. In practice two switches will actually be off but to test the system it was set to turn on the LED. I can’t figure out how to make the relay turn back on when the lower switch sends the low signal.

Attach Your entire code. Use the code tags("</>").

void setup() {
pinMode(13,INPUT);
pinMode(12, OUTPUT);
pinMode (11,INPUT);

}

void loop() {
  // put your main code here, to run repeatedly:

if(digitalRead(13) ==LOW && digitalRead(11)==LOW){
  digitalWrite(12, LOW);
}else{
  digitalWrite(12, LOW);
}


}

I guess, not knowing Your wiring diagram, that declaring inputs as "INPUT_PULLUP" and buttons connected between GND and input would be good.
Your code looks not good

if(digitalRead(13) ==LOW && digitalRead(11)==LOW){
  digitalWrite(12, LOW);
}else{
  digitalWrite(12, LOW);
}

Try

if(digitalRead(13) ==LOW && digitalRead(11)==LOW){
  digitalWrite(12, LOW);
}else{
  digitalWrite(12, HIGH);
}

or the opposite, first HIGH and then LOW.

dwyerl2:
Thanks for any help! I am a novice at this and anything helps.

Understanding the workings of the first five sketches in the IDE file/examples/digital will give you a good base to progress on.

I missed that when I copied it in. I did have it that way at once but I changed it as I was playing around. So this little tidbit of code works.

if(digitalRead(13) ==LOW && digitalRead(11)==LOW){
  digitalWrite(12, LOW);
}else{
  digitalWrite(12, HIGH);
}

But as the hopper empties The upper limit (pin, 13) will become high but I do not want pin 12 to become HIGH until the lower limit (pin,11) goes into a HIGH state. When both upper and lower switches are in a LOW state pin 12 is to go back to a LOW state. I may have my high and low designations wrong on my limit switches. I do not know how to continue the code so it preforms as I need it to. I will check those examples out. Thank you.

You could also do a site search on 'tank fill'. This problem comes up regularly in various forms so there are lots of threads addressing it.

As programs get longer and more complex it can become difficult to remember what digitalRead(13) is reading. Giving it a descriptive name like digitalRead(upperLimitSW) will make the program what the program is doing a lot more understandable - which you may find quite useful six months from now.

Might help to create two booleans. Emptying_the Tank and Filling_the Tank. Mutually exclusive, meaning both cannot be true of false at the same time.

Only check the bottom switch if Emptying_the_Tank is true. Only check the upper switch if Filling_the_Tank is true. When either switch becomes true, set the associated Boolean to False.

If your system can empty the tank continuously while filling is happening, then the logic is different.

Paul

This is what I have so far. The lower limit infeed switch seems to work correctly and the upper limit infeed switch shuts off the infeed auger. The problem is the infeed auger starts up again when the upper limit infeed switch is LOW again. Ill try to figure out the booleans.

int ulimitinfeed = 13;
int llimitinfeed = 11;
int infeedauger = 12;
void setup() {
pinMode( ulimitinfeed,INPUT);
pinMode(infeedauger, OUTPUT);
pinMode (llimitinfeed,INPUT);

}

void loop() {
  // put your main code here, to run repeatedly:

  
if(digitalRead(llimitinfeed) ==LOW)
   digitalWrite(infeedauger,HIGH);
  
if(digitalRead(ulimitinfeed) ==LOW)
   digitalWrite(infeedauger, LOW);
else
  digitalWrite(infeedauger, HIGH);
  
}

Planning and Implementing an Arduino Program

Good to see you've already named your pins.

Hi,

I think you need to consider BOTH limits together to get your outputs right.

Some pseudo code.

uplimitState = digitalRead(ulimitinfeed);

lowlimitState = digitalRead(llimitinfeed);
//

read both limits at the start of the loop, then use the Status to do your control. ie, you take a snapshot of you project inputs.

if (uplimitState == HIGH and lowlimitState == HIGH) // hopper is full.
{
auger = OFF;
faultSignal = OFF;
HopperFullState = ON;
}
If (uplimitState == LOW and lowlimitState == LOW) //Hopper is empty.
{
auger = ON;
faultSignal = OFF;
HopperFullState =OFF;
}
if (uplimitState == LOW and lowlimitState == HIGH and HopperFullState == OFF) //Hopper is filling
{
auger = ON;
faultSignal = OFF;
}
and for a fault state
if (uplimitState == HIGH and lowlimitState == LOW) // not a possible combination when operating correctly.
{
auger = OFF;
faultSignal = ON;
}

I haven't put it in code tags as it is not true code, just a way we use sometimes to layout any logic decisions .

HopperFullState can only be turned ON when the hopper is FULL and OFF when the hopper is EMPTY, so the auger cannot come back on when the auger has been filled and is in the middle of emptying.

I have added a faultSignal, as this would be standard in a situation like this if you had some form of sensor fault.

I hope it makes sense, just about to go and get a coffee.

Tom... :slight_smile:

Curious how does the limit switches in the hopper actually work / look like.

Simple state variable control.
If Lower and Upper sensors are “Low” set state variable to TRUE
If Upper is “Low” and state variable is TRUE, turn on fill auger.
If Upper is “High” set state variable to FALSE, turn off fill auger.
Loop.

Thanks Tom I will try to sort this out! Naming pins has defiantly made it easier to sort out what I am trying to do.

TomGeorge:
Hi,

I think you need to consider BOTH limits together to get your outputs right.

Some pseudo code.

I haven't put it in code tags as it is not true code, just a way we use sometimes to layout any logic decisions .

HopperFullState can only be turned ON when the hopper is FULL and OFF when the hopper is EMPTY, so the auger cannot come back on when the auger has been filled and is in the middle of emptying.

I have added a faultSignal, as this would be standard in a situation like this if you had some form of sensor fault.

I hope it makes sense, just about to go and get a coffee.

Tom... :slight_smile:

I know I have some issues with this code but I am working on it yet. 3 of the 4 actions are covered. Full, Empty, Filling but not Emptying or Dumping. In this state the ulimitinfeed will be high and the llimitinfeed will be low. Which is the same as the filling state and the auger will run. I dont want the auger to switch on until it sees a llimitinfeed low signal.

int ulimitinfeed = 13;
int llimitinfeed = 11;
int infeedauger = 12;
int uplimitState = digitalRead(ulimitinfeed);
int lowlimitState = digitalRead(llimitinfeed);
int infeedaugerstate = digitalWrite(infeedauger);
void setup() {
pinMode( ulimitinfeed,INPUT);
pinMode(infeedauger, OUTPUT);
pinMode (llimitinfeed,INPUT);

}

void loop() {
  // put your main code here, to run repeatedly:

  
if (uplimitState == LOW and lowlimitState == LOW) //  hopper is full.
{
infeedaugerstate = HIGH;
HopperFullState = ON;
}
If (uplimitState == HIGH and lowlimitState == High) //Hopper is empty.
{
infeedaugerstate = HIGH;
HopperFullState =OFF;
}
if (uplimitState == HIGH and lowlimitState == LOW and HopperFullState == OFF) //Hopper is filling
{
infeedaugerstate = HIGH;
}

Slumpert:
Curious how does the limit switches in the hopper actually work / look like.

Simple state variable control.
If Lower and Upper sensors are “Low” set state variable to TRUE
If Upper is “Low” and state variable is TRUE, turn on fill auger.
If Upper is “High” set state variable to FALSE, turn off fill auger.
Loop.

I am also curious about this! Having run a grass seed cleaning mill many decades ago, I am quite familiar with hoppers and augurs, etc. Also that fact that grain will fill a hopper in the form of a cone. Emptying the same hopper will produce an inversion of the same cone shape.

Moreover, dust in a hopper is a tremendous problem, so light sensors won't work.

Paul

I am using an off the shelf micro switch. I will have a square of rubber or steel that will be over the switch and as the grain covers the square of rubber or steel it will press the micro switch. I will be cleaning sunflower seeds to bag for bird seed. The reason for all the switches and such is so I dont have augers running with little or no seed in them. I want the augers to run full at all times to minimize seed damage.