So i will start by just explaining what i am trying to do, I have a big grinder that grinds compression type springs, I have a vibrating bowl feeder that channels these thing in line one after another inside of a tube. I have a relay board where i will trigger two separate pneumatic solenoids to push forward and keeps the springs from falling out for the tube. I have an IR sensor and when it senses the next whole it cycles through telling the relays to open and close in a certain order.
My real problem is i want the sensor to read high for a couple of seconds. The way i have it now any little thing will trigger it, and what i got right now.... ot going to work. I will post what i have under
const int Lower = 5;
const int Spare = 6;
const int Upper = 7;
const int ir_sensor = 12;
void setup() {
Serial.begin(9600);
pinMode(Lower, OUTPUT);
pinMode(Upper, OUTPUT);
pinMode(Spare, OUTPUT);
pinMode(ir_sensor, INPUT);
digitalWrite(Lower, HIGH);
digitalWrite(Upper, LOW);
}
void loop(){
int state = digitalRead(ir_sensor);
Serial.println(state);
if (state==HIGH){
Serial.println("Hole Detected");
digitalWrite(Upper, HIGH);
delay(1000);
digitalWrite(Lower, LOW);
delay(3000);
digitalWrite(Lower, HIGH);
delay(1000);
digitalWrite(Upper, LOW);
}
else {
digitalWrite(Lower, HIGH);
digitalWrite(Upper, LOW);
}
}
i had tried something where i tried getting the current time with millis() and i figured there is probably an easier way to do this
unsigned long previousMillis = 0; //will store last time LED was blinked
const long period = 1000; // period at which to blink in ms