Potato Planter Sensor Read

Hello! I'm looking to install an alarm system on a Grimme potato planter. It has 6 conveyors with hi/low capacitive sensors sitting next to them. They read the cups that are on the belt that carry the potatoes to the ground. The sensors purpose is to flash a light if it sees a state change, caused by the cups. Since there are 6 sensors, and the belt is spinning at about 1 cup per second, the lights are annoying.

However they are still useful. They let us see if there is a jam in one of the conveyors. If there is no state change, a light would be off. Potatoes won't be put in the ground for that row.

What I am trying to do is read the state change of all 6 inputs. I need to monitor each one and send an alarm to an LED that would show that there is a jam if there was no state change. My idea is to start a timer after each pulse and if either the on or off state of each signal stayed on longer than 1000 ms the LED would turn on.

My question is, how can I format an array to read 6 digital inputs at the same time and start and restart a timer for each pulse?

Hello! I'm looking to install an alarm system on a Grimme potato planter. It has 6 conveyors with hi/low capacitive sensors sitting next to them. They read the cups that are on the belt that carry the potatoes to the ground. The sensors purpose is to flash a light if it sees a state change, caused by the cups. Since there are 6 sensors, and the belt is spinning at about 1 cup per second, the lights are annoying.

However they are still useful. They let us see if there is a jam in one of the conveyors. If there is no state change, a light would be off. Potatoes won't be put in the ground for that row.

What I am trying to do is read the state change of all 6 inputs. I need to monitor each one and send an alarm to an LED that would show that there is a jam if there was no state change. My idea is to start a timer after each pulse and if either the on or off state of each signal stayed on longer than 1000 ms the LED would turn on.

My question is, how can I format an array to read 6 digital inputs at the same time and start and restart a timer for each pulse?

Are you just going to leave the existing system alone and install sensors to “watch” the lights or something else?

Details about how your going to send data to the arduino usually makes things easier to understand.

Statements about “light 1 alarm LED” if more than a second passes makes little sense as current system surely does not get “reacted” to by humans within 1 second. Surely you do t want the alarm to go off every time just one cup is empty even though the next has a potato.

There is no working system on the planter. All that exists is the sensors.

The system does not need to see if the cup is empty, just that the cup is moving. For example; if belt 1 is jammed, it will see no change of state. Belts 2 through 6 will continue pulsing. The "light 1 alarm" will be on because of the lack of movement in the belt.

Another way to explain it is if there is an extended high or low from the digital inputs.

Well, you don't really read the six inputs at the same time, but some microseconds apart won't make any difference.

The type of elements in the array depend upon how you go about programming this task. If it were me, I might have two arrays (or a struct with two arrays or an array of struct's); one array of byte for the pin numbers, and one array of unsigned long to keep track (using millis()) of the time since last seeing a cup.

If you want code written for you, go to Gigs and Collaborations, and bring your wallet.

How do you plan to let someone know that all is well, or that something is wrong?

What is your experience level with Arduino and with electronics?

You don't really need to read all 6 inputs simultaneously. You can do it using a for() loop. On the time scale of an arduino, they won't be "simultaneously" but to you and a machine rotating at 1 cup/sec, it will appear simultaneously.

Look at the example in the IDE, File->Examples->Digital->StateChangeDetection. That will show you how to detect one of your signals. Whenever you detect the change, capture the current time as the start time. Extend this concept to an array of 6 sensor input pins and 6 start times. The second part of your loop() function will compare the current time to the start time of each sensor and if greater than 1000, signal the error.

Give it a try... Start simple and build up your program. When you get stuck, post your code here (using code tags) and an explanation of what the code is doing vs. what you want it to be doing and people can help you

@Jkinsman, do not cross-post. Threads merged.

My question is, how can I format an array to read 6 digital inputs at the same time

You can't make an array do anything except hold data.

As mentioned, the Arduino is fast enough that you don't need to read your slowly changing inputs simultaneously. If you want to do so anyway, you can read about it here: Port manipulation

Jkinsman:
The sensors purpose is to flash a light if it sees a state change, caused by the cups.

Are you proposing to use the existing sensors? If so, can you post a link to their technical details?

An important issue is what voltage they operate at. If it is more than 5v you will need a circuit (voltage divider?) to protect the Arduino.

And the first step will be to write a short Arduino program to detect one of the sensors and display the result on the Arduino Serial Monitor. If you can't do that there is little point in worrying about anything else.

...R

Robin2:
Are you proposing to use the existing sensors? If so, can you post a link to their technical details?

An important issue is what voltage they operate at. If it is more than 5v you will need a circuit (voltage divider?) to protect the Arduino.

And the first step will be to write a short Arduino program to detect one of the sensors and display the result on the Arduino Serial Monitor. If you can't do that there is little point in worrying about anything else.

...R

I do plan on using existing sensors. I've built a jig to test them. They run 12V and I've wired the signal wire into a voltage divider.

I've written a code to see when they have a high or low on the signal wire. I could implement this with 6 LEDs but the operator wants it to only show light up if one state stays too long.

Robin2 I'm currently reading your post on timers "several things at a time" and will try to implement something similar for timing the logic changes. Does it need to be a global timer monitoring all states? can it be in each program...?

 const int Sensor1 = 12;        //  Sensor input
 const int Sensor1High = 2;     //  LED output 

 int Sensor1State = 0;
 int lastSensor1State = 0;


void setup() {
  pinMode (Sensor1, INPUT);
  pinMode (Alarm1, OUTPUT);
  pinMode (Sensor1High, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  checkSensor1();
  
}

void checkSensor1() {  
  Sensor1State = digitalRead(Sensor1);    // Read the sensor state
  Serial.println(Sensor1State);
  

  if (Sensor1State == HIGH) {
    digitalWrite (Sensor1High, HIGH);     // Turn on LED if sensor is blocked ie. potato
    Serial.println ("Sensor1High = ON");
  }else{
    digitalWrite (Sensor1High, LOW);      // Turn LED off if sensor is clear 
    Serial.println("Sensor1High = OFF");
  }
}

Most optical sensors either let the signal float or pull it to ground (aka "open collector" configuration) which means you need to enable the pull-up resistor on your input or supply them yourself externally

pinMode (Sensor1, INPUT_PULLUP);

Jkinsman:
Does it need to be a global timer monitoring all states? can it be in each program...?

I don't understand what you have in mind. Please explain further.

Separately, I suspect that Sensor1LEDpin would be a more meaningful name than Sensor1High. IMHO it does not make a lot of sense to digitalWrite (Sensor1High, LOW) :slight_smile:

...R

Robin2:
I don't understand what you have in mind. Please explain further.

If I want to time each state of the sensor, of all 6 sensors, where do I start, read, and reset the timers? Obviously I am still working in modular code and designing it for 1 sensor at the moment.

Robin2:
Separately, I suspect that Sensor1LEDpin would be a more meaningful name than Sensor1High. IMHO it does not make a lot of sense to digitalWrite (Sensor1High, LOW) :slight_smile:

Something I've forgotten about code; it should be understandable to everyone qualified. I'll update that.

blh64:
Most optical sensors either let the signal float or pull it to ground (aka "open collector" configuration) which means you need to enable the pull-up resistor on your input or supply them yourself externally

Thanks Blh64. I'll have to do it externally. Thats likely why the LED was bouncy when testing it.

Jkinsman:
If I want to time each state of the sensor, of all 6 sensors, where do I start, read, and reset the timers? Obviously I am still working in modular code and designing it for 1 sensor at the moment.

Do you mean that you want to time the intervals between sensing potatoes so that when the interval is too long you know there is a problem?

From my limited understanding of your project that seems to me to require a separate process for timing each part of the machine otherwise a failure in one part would be obscured by the working parts.

The simple way for an inexperienced programmer is probably to repeat the code for one part 5 more times with different variable names.

A more experienced programmer would create a struct that defines the data for any one part and would create an array of the structs for the 6 parts. It would make the programming much shorter and less prone to silly errors.There was a good example of this in a recent Thread but I did not bookmark it.

...R

Jkinsman:
Thanks Blh64. I’ll have to do it externally. Thats likely why the LED was bouncy when testing it.

Why? It is far easier to simply enable the arduino internal pull-ups than phyiscally wire in external pull-up resistors.