Grain hopper limit switch

dwyerl2:
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.

Ok, Have you proven this before we spend any more time?

Paul

It will work. I have seen this type of setup work many times on commercial equipment.

Hi,
What do you want to hAve happen while the hopper is EMPTYING or DUMPING?

What are the outputs you want controlled?

My psuedocode covers EMPTYING with the upperlimit==low AND lowerlimit==high AND hopperfullstate == high.

Tom... :slight_smile:

TomGeorge:
Hi,
What do you want to hAve happen while the hopper is EMPTYING or DUMPING?

I dont want anything to happen. I just want it to sit and wait until it is empty then start over. How would I implement the hopperfull state? I was trying to figure that out earlier today but I was stumped and didn't find any good examples. I only need to turn on a fill auger and then emptying auger. Also a simple on off to run the cleaner.

dwyerl2:
I dont want anything to happen. I just want it to sit and wait until it is empty then start over. How would I implement the hopperfull state? I was trying to figure that out earlier today but I was stumped and didn't find any good examples. I only need to turn on a fill auger and then emptying auger. Also a simple on off to run the cleaner.

Well that is what my code does.
Can you post a copy of your test circuit so we can see how you have wired the I/O?
Thanks.. Tom... :slight_smile:

Hope this is what you wanted to see.

Hi,
Yup fine for the exercise.


I assume you are using a LED instead of the relay at the moment.

So when the level in the hopper is high enough the trip the sensors, they close, so LOW is lower and upper ON.

Tom... :slight_smile:

Hi,
So revised pseudocode;

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

Tom... :slight_smile:

Yes I am using an LED in place of the relay at the moment. Thanks Ill see if I can get that to work.

Tom I like your idea of how this code should work. I have been trying to get it to work and I am getting error messages. I also dont understand how to use the hopperfullstate, faultsignal, infeedaugerstate. I have included my code. Am I on the right track?

int ulimitinfeed = 13;
int llimitinfeed = 11;
int infeedauger = 12;
int HopperFullState=2;
int faultsignal=3;
//int OFF=LOW;
//int ON=HIGH;
int uplimitState = digitalRead(ulimitinfeed);
int lowlimitState = digitalRead(llimitinfeed);
int infeedaugerstate= digitalWrite(ON,OFF);
void setup() {
pinMode( ulimitinfeed,INPUT);
pinMode(infeedauger, OUTPUT);
pinMode (llimitinfeed,INPUT);

void loop () 

//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 == LOW and lowlimitState == LOW) //  hopper is full.
{
infeedaugerstate = HIGH;
 faultSignal = OFF;
  HopperFullState = ON;
}
If (uplimitState == HIGH and lowlimitState == HIGH) //Hopper is empty.
{
infeedaugerstate = ON;
 faultSignal = OFF;
  HopperFullState =OFF;
}
if (uplimitState == HIGH and lowlimitState == LOW and HopperFullState == OFF) //Hopper is filling
{
infeedaugerstste = ON;
faultSignal = OFF;
}
and for a fault state
if (uplimitState == LOW and lowlimitState == HIGH)  // not a possible combination when operating correctly.
{
auger = OFF;
faultSignal = ON;
}

Hi,

A good start. :slight_smile:

Try this, you had some easy mistakes that we all make from time to time, and some logic declarations.

I'm not sure how the code will work, I'm at work, but I'll make a test jig tonight if you have any problems.

int ulimitinfeed = 13;
int llimitinfeed = 11;
int infeedauger = 12;
int HopperFullState = 2;
int faultsignal = 3;
//int OFF=LOW;
//int ON=HIGH;
bool uplimitState ;
bool lowlimitState ;
int infeedaugerstate = LOW;
bool faultSignal = LOW;
void setup()
{
  pinMode( ulimitinfeed, INPUT);
  pinMode(infeedauger, OUTPUT);
  pinMode (llimitinfeed, INPUT);
}


void loop ()
{


  //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.
  uplimitState = digitalRead(ulimitinfeed);
  lowlimitState = digitalRead(llimitinfeed);


  if (uplimitState == LOW and lowlimitState == LOW) //  hopper is full.
  {
    infeedaugerstate = LOW;
    faultSignal = LOW;
    HopperFullState = HIGH;
  }
  if (uplimitState == HIGH and lowlimitState == HIGH) //Hopper is empty.
  {
    infeedaugerstate = HIGH;
    faultSignal = LOW;
    HopperFullState = LOW;
  }
  if (uplimitState == HIGH and lowlimitState == LOW and HopperFullState == LOW) //Hopper is filling
  {
    infeedaugerstate = HIGH;
    faultSignal = LOW;
  }
  if (uplimitState == LOW and lowlimitState == HIGH)  // not a possible combination when operating correctly.
  {
    infeedaugerstate = LOW;
    faultSignal = HIGH;
  }
}

Also a little trick that the IDE has, if you select TOOLS then AUTO-FORMAT the code is indented so you can see your { and } pairs.

Tom... :slight_smile:

It wouldn't work for some reason. I made some small tweaks and still nothing. For some reason the hopperfullstate LED was lit up very dim on pin 2 but I moved it to pin 4 and now id doesn't do that. I'm not sure why.

Hi,

pinMode (hopperfullstate ,OUTPUT);

In the setup might help.

Tom... :slight_smile:

I had added that already. This is what Im working with now.

int ulimitinfeed = 13;
int llimitinfeed = 11;
int infeedauger = 12;
int HopperFullState = 4;
int faultsignal = 3;
bool uplimitState ;
bool lowlimitState ;
int infeedaugerstate = HIGH;
bool faultSignal = LOW;
void setup()
{
  pinMode( ulimitinfeed, INPUT);
  pinMode(infeedauger, OUTPUT);
  pinMode (llimitinfeed, INPUT);
  pinMode (HopperFullState, OUTPUT);
  pinMode (faultsignal, OUTPUT);
}


void loop ()
{


  //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.
  uplimitState = digitalRead(ulimitinfeed);
  lowlimitState = digitalRead(llimitinfeed);


  if (uplimitState == LOW && lowlimitState == LOW) //hopper is full.
  {
    infeedauger = LOW;
    faultSignal = LOW;
    HopperFullState = HIGH;
  }
  if (uplimitState == HIGH && lowlimitState == HIGH) //Hopper is empty.
  {
    infeedauger = HIGH;
    faultSignal = LOW;
    HopperFullState = LOW;
  }
  if (uplimitState == HIGH && lowlimitState == LOW && HopperFullState == LOW) //Hopper is filling
  {
    infeedauger = HIGH;
    faultSignal = LOW;
  }
  if (uplimitState == LOW && lowlimitState == HIGH)  //not a possible combination when operating correctly.
  {
    infeedauger = LOW;
    faultSignal = HIGH;
  }
}
  pinMode (HopperFullState, OUTPUT);

...
    HopperFullState = HIGH;

This doesn't turn on the LED on pin 4.

To reduce this kind of error, it's useful to use distinct names for pins. Like hopperFullPin for the pin number and hopperFullState for the status.

Hi,
I have edited your code, hope you can follow it, I have setup a circuit here to try it out, so it should work for you.

To see how your input are working, after loading the code to the UNO, select TOOLS, then SERIAL MONITOR, check the bottom of the window that opens and select 115200 baud.
I have put a 1second delay in the code so you can see the info properly on the monitor.

int ulimitPin = 10;
int llimitPin = 11;
int infeedaugerPin = 12;
int HopperFullPin = 4;
bool HopperFullState = LOW;
int faultsignalPin = 3;
bool uplimitState ;
bool lowlimitState ;
bool infeedaugerState = LOW;
bool faultSignalState = LOW;
void setup()
{
  Serial.begin(115200);
  pinMode( ulimitPin, INPUT_PULLUP);
  pinMode(infeedaugerPin, OUTPUT);
  pinMode (llimitPin, INPUT_PULLUP);
  pinMode (HopperFullPin, OUTPUT);
  pinMode (faultsignalPin, OUTPUT);
}




void loop ()
{


  //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.
  uplimitState = digitalRead(ulimitPin); //LOW when switch ON
  lowlimitState = digitalRead(llimitPin);


  digitalWrite(HopperFullPin, HopperFullState);  //output the outcomes of the decision statements
  digitalWrite(faultsignalPin, faultSignalState);
  Serial.print("\t Uplimit ");
  Serial.print(uplimitState);  // monitor print the state of inputs and outputs
  Serial.print("\t Lolimit ");
  Serial.print(lowlimitState);
  Serial.print("\t FullState ");
  Serial.print(HopperFullState);
  Serial.print("\t InfeedaugerState ");
  Serial.print(infeedaugerState);
  Serial.print("\t FaultSignal ");
  Serial.print(faultSignalState);
  Serial.println("");


  if (uplimitState == LOW && lowlimitState == LOW) //hopper is full.
  {
    infeedaugerState = LOW;
    faultSignalState = LOW;
    HopperFullState = HIGH;
  }
  if (uplimitState == HIGH && lowlimitState == HIGH) //Hopper is empty.
  {
    infeedaugerState = HIGH;
    faultSignalState = LOW;
    HopperFullState = LOW;
  }
  if (uplimitState == HIGH && lowlimitState == LOW && HopperFullState == LOW) //Hopper is filling
  {
    infeedaugerState = HIGH;
    faultSignalState = LOW;
  }
  if (uplimitState == LOW && lowlimitState == HIGH)  //not a possible combination when operating correctly.
  {
    infeedaugerState = LOW;
    faultSignalState = HIGH;
  }
  delay(1000);
}

See how you go.

Tom... :slight_smile:

Thanks Tom! The serial monitor was great to sort out a couple small bugs in my wiring. But for some reason I cannot get the infeedaugerpin to work. I have checked my LED by swapping it with the hopperfull LED and they both work on the hopperfullstate but not the infeedauger pin. I tried changing the pin to a different pin and still nothing. On the serial monitor I can see the infeedaugerstate working as it should.

Post the code you're using.

int ulimitinfeed = 13;
int llimitinfeed = 11;
int infeedauger = 12;
int HopperFullState = 4;
int faultsignal = 3;
bool uplimitState ;
bool lowlimitState ;
bool faultSignal = LOW;
void setup()
{
  pinMode( ulimitinfeed, INPUT);
  pinMode(infeedauger, OUTPUT);
  pinMode (llimitinfeed, INPUT);
  pinMode (HopperFullState, OUTPUT);
  pinMode (faultsignal, OUTPUT);
}


void loop ()
{


  //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.
  uplimitState = digitalRead(ulimitinfeed);
  lowlimitState = digitalRead(llimitinfeed);


  if (uplimitState == LOW && lowlimitState == LOW) //hopper is full.
  {
    infeedauger = LOW;
    faultSignal = LOW;
    HopperFullState = HIGH;
  }
  if (uplimitState == HIGH && lowlimitState == HIGH) //Hopper is empty.
  {
    infeedauger = HIGH;
    faultSignal = LOW;
    HopperFullState = LOW;
  }
  if (uplimitState == HIGH && lowlimitState == LOW & HopperFullState == LOW) //Hopper is filling
  {
    infeedauger = HIGH;
    faultSignal = LOW;
  }
  if (uplimitState == LOW && lowlimitState == HIGH)  //not a possible combination when operating correctly.
  {
    infeedauger = LOW;
    faultSignal = HIGH;
  }
}

HI,
This might do the trick, I'm at work at the moment, so can't test it.

You need to distinguish the difference between pin number and variable numbers, you will see I have added Pin to the end of the pin number variables.
You will also see I have declared them const int, this means the code will regard them as constants and will error your compilation if it sees the code trying to change their value.

const int ulimitinfeedPin = 13;
const int llimitinfeedPin = 11;
const int infeedaugerPin = 12;
const int HopperFullStatePin = 4;
int faultsignal = 3;
bool uplimitState ;
bool lowlimitState ;
bool faultSignal = LOW;
bool infeedauger = LOW;
bool HopperFullState = LOW;
void setup()
{
  pinMode( ulimitinfeedPin, INPUT);
  pinMode(infeedaugerPin, OUTPUT);
  pinMode (llimitinfeedPin, INPUT);
  pinMode (HopperFullStatePin, OUTPUT);
  pinMode (faultsignal, OUTPUT);
}




void loop ()
{




  //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.
  uplimitState = digitalRead(ulimitinfeedPin);
  lowlimitState = digitalRead(llimitinfeedPin);
  digitalWrite(infeedaugerPin, infeedauger);


  if (uplimitState == LOW && lowlimitState == LOW) //hopper is full.
  {
    infeedauger = LOW;
    faultSignal = LOW;
    HopperFullState = HIGH;
  }
  if (uplimitState == HIGH && lowlimitState == HIGH) //Hopper is empty.
  {
    infeedauger = HIGH;
    faultSignal = LOW;
    HopperFullState = LOW;
  }
  if (uplimitState == HIGH && lowlimitState == LOW & HopperFullState == LOW) //Hopper is filling
  {
    infeedauger = HIGH;
    faultSignal = LOW;
  }
  if (uplimitState == LOW && lowlimitState == HIGH)  //not a possible combination when operating correctly.
  {
    infeedauger = LOW;
    faultSignal = HIGH;
  }
}