# Blockage IR sensor

Hello !

I'm quite new to programing but I understand electronics but the problem I'm having is, I'm building a seed counting system for a seed drill but eventually it will be counting seed and telling me seed population over an given area and lots of other things but I haven't got time to do that before planting season so all I want for this year is just a simple blockage system that will light an led and sound a buzzer when it stops counting seed/ stops pulsing. Iv built the sensors my self and its just a brake beam inferred but it can detect small and large seed and when the beam gets broken it pulls the signal wire/ digital input to ground. So all I want it to do is if the digital input stays high or sees no pulse for say 3 seconds it lights the led and buzzer and as soon as it goes low or starts pulsing again the led goes off but its got to be doing this for 8 sensors at a time and it cant be spending to long reading one sensor. It is very simple in theory but I cant seem to find any examples anywhere so I would be very grateful for some help.

Thanks, Chris. ;D

so all I want for this year is just a simple blockage system that will light an led and sound a buzzer when it stops counting seed/ stops pulsing.

How will the Arduino know that that has happened?

So all I want it to do is if the digital input stays high or sees no pulse for say 3 seconds it lights the led and buzzer and as soon as it goes low or starts pulsing again the led goes off but its got to be doing this for 8 sensors at a time and it cant be spending to long reading one sensor.

So what is the problem?

It is very simple in theory

In practice, too.

but I cant seem to find any examples anywhere so I would be very grateful for some help.

What are you currently able to do? Can you detect that the sensor is/is not seeing a seed? Can you tell when the transition happens? If so, record the time.

Periodically, as in on every pass through loop(), see if now minus then (when a seed was last detected) is greater than the desired interval. If so, sound the alarm.

The blink without delay and state change detection examples provide all the pieces you need.

The sensor is connected to an digital input with a resistor pulling it to 5v.
Every time a seed passes thro the sensor the digital input pin on the board will see it go to low the back to high being one seed has passed but I just want it to if the input state is constantly high for more than 3 sec then switches on an led and buzzer. But keeping in mind that multiple seeds are falling/ second.
But I don’t want it to see a high state start timing and look at the pin again in 3 seconds as it could catch it at a high state again after a seed passed in that 3 seconds but that’s all I can figger out what to do at the moment.

I just cant work out what code to write for below:

Read pin 22- if pin is high start reading for 3 seconds if at any point the state goes to low cancel counting and carry on loop (to minimise time wasting)
Has pin 22 stayed high constantly for >3 seconds
yes= turn on ledpin 23
no= turn off ledpin23.

You have to remember the time when a sensor was unblocked. Like this:

if (millis() - pinTime > interval) digitalWrite(LED, ON); //alert
else digitalWrite(LED, OFF);

Repeat for each sensor.

Got it working!

const int sen1 = 22;
const int sen2 = 23;
const int sen3 = 24;
const int sen4 = 25;
const int sen5 = 26;
const int sen6 = 27;
const int sen7 = 28;
const int sen8 = 29;

const int led1 = 32;
const int led2 = 33;
const int led3 = 34;
const int led4 = 35;
const int led5 = 36;
const int led6 = 37;
const int led7 = 38;
const int led8 = 39;

int senState1 = 0; // current state of the sensor
int senState2 = 0; // current state of the sensor
int senState3 = 0; // current state of the sensor
int senState4 = 0; // current state of the sensor
int senState5 = 0; // current state of the sensor
int senState6 = 0; // current state of the sensor
int senState7 = 0; // current state of the sensor
int senState8 = 0; // current state of the sensor

unsigned long pinTime1 = 0; // the time button is hold
unsigned long pinTime2 = 0; // the time button is hold
unsigned long pinTime3 = 0; // the time button is hold
unsigned long pinTime4 = 0; // the time button is hold
unsigned long pinTime5 = 0; // the time button is hold
unsigned long pinTime6 = 0; // the time button is hold
unsigned long pinTime7 = 0; // the time button is hold
unsigned long pinTime8 = 0; // the time button is hold

const long interval = 2000;

void setup() {

pinMode(sen1, INPUT);
pinMode(sen2, INPUT);
pinMode(sen3, INPUT);
pinMode(sen4, INPUT);
pinMode(sen5, INPUT);
pinMode(sen6, INPUT);
pinMode(sen7, INPUT);
pinMode(sen8, INPUT);

pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
pinMode(led8, OUTPUT);
}

void loop() {

// 1 read input pin sen1:
if (millis() - pinTime1 > interval)
else digitalWrite(led1, LOW);

if (millis() - pinTime2 > interval)
else digitalWrite(led2, LOW);

// 3 read input pin sen3:
if (millis() - pinTime3 > interval)
else digitalWrite(led3, LOW);

// 4 read input pin sen4:
if (millis() - pinTime4 > interval)
else digitalWrite(led4, LOW);

// 5 read input pin sen5:
if (millis() - pinTime5 > interval)
else digitalWrite(led5, LOW);

// 6 read input pin sen6:
if (millis() - pinTime6 > interval)
else digitalWrite(led6, LOW);

// 7 read input pin sen7:
if (millis() - pinTime7 > interval)
else digitalWrite(led7, LOW);

// 8 read input pin sen8:
if (millis() - pinTime8 > interval)
else digitalWrite(led8, LOW);

}

Hi,
What model Arduino is it.

Can you please post a copy of your sketch, using code tags?
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Good to see you have it going.

Tom…

When you find yourself tempted to suffix variable names with numbers, such as this:

const int sen1 = 22;
const int sen2 = 23;
const int sen3 = 24;
const int sen4 = 25;
const int sen5 = 26;
const int sen6 = 27;
const int sen7 = 28;
const int sen8 = 29;

const int led1 = 32;
const int led2 = 33;
const int led3 = 34;
const int led4 = 35;
const int led5 = 36;
const int led6 = 37;
const int led7 = 38;
const int led8 = 39;

then it is time to learn about arrays - and in this case, arrays of structs.

Save more space - make them byte, vs int. Nothing higher than 255 there.