Hello folks, new to writing code. I'm using an Arduino UNO R3 to control a UR5 robot, vibrating bowl, and a feeder. This is the code I have come up with to have laser 1 detect if a part is in the tool head prior to moving to the next location and depositing the part.
Laser 2 is for the feeder. Parts will go past this laser and I don't want the relay to shut off as soon as a part blocks the sensor. I want to turn the relay on pin 5 LOW only when a part is stuck for 1 second as the feeder is full. THIS IS WHERE I NEED HELP, PUTTING IN CODE FOR THE 1 SECOND DETECTION
Analog Input is to control the relay for the vibrating bowl and is based upon the UR5 beginning and end of that program.
// Define pins
int laserPin2 = 2;
int laserPin3 = 3;
int analogPin = 0;
int outputPin4 = 4;
int outputPin5 = 5;
int outputPin6 = 6;
void setup() {
// Set pin modes
pinMode(laserPin2, INPUT);
pinMode(laserPin3, INPUT);
pinMode(analogPin, INPUT);
pinMode(outputPin4, OUTPUT);
pinMode(outputPin5, OUTPUT);
pinMode(outputPin6, OUTPUT);
pinMode (10, OUTPUT); //Output for Laser
pinMode (11, OUTPUT); //Output for Laser
}
void loop () {
// Read laser inputs and analog input
int laser2 = digitalRead(laserPin2);
int laser3 = digitalRead(laserPin3);
int voltage = analogRead(analogPin);
{digitalWrite(10, HIGH), digitalWrite(11, HIGH);}
// Check if object is detected at laser 2
if (laser2 == HIGH) {
digitalWrite(outputPin4, HIGH); // Set output pin 4 to HIGH
} else {
digitalWrite(outputPin4, LOW); // Set output pin 4 to LOW
}
// Check if object is detected at laser 3
if (laser3 == HIGH) {
digitalWrite(outputPin5, HIGH); // Set output pin 5 to HIGH
} else {
digitalWrite(outputPin5, LOW); // Set output pin 5 to LOW
}
// Check voltage at analog input
if (voltage == 1023) {
digitalWrite(outputPin6, HIGH); // Set output pin 6 to LOW
} else {
digitalWrite(outputPin6, LOW); // Set output pin 6 to HIGH
}}