Hello,
I checked for threads with similar questions but wasn't able to find what I am looking for.
I am working on a project that identifies whether a part made in our factory should pass or fail a QC step. The parts run on a conveyor belt that steps at intervals and has a number of stations. At the inspection station a picture is taken and analysed, whether the part passes or fails the belt will continue to step forward.
If it fails though, a signal is sent to the arduino. At this point I need to initiate a counter and after four steps execute an output that will remove the part from the belt. The steps are controlled by a sensor that detects a marker on the belt, so my plan is to use the signal from the sensor and count that four times. Once the counter reaches 4 the output should be triggered.
How do I write a function that will initiate a counter when receiving the camera signal and then count every time the sensor signal is received?
This project is an upgrade to include more processes on the conveyor. The initial version is only used to engrave a batch # on the part. Now we want to have parts that have failed a previous process to be rejected before even making it to the engraver.
Here is what I have so far. I have recycled the code from version 1 and added the additional inputs and outputs to the scope as well as a rejectCount integer. In void setup I have declared whether the new connections are inputs or outputs. I have made no changes to void loop thus far, so this is what the previous conveyor runs on. The "relay" output controls the cut off to the motor to make the belt stop.
I work mostly with design and electronics, with limited coding knowledge, so please excuse anything outside best practise norms. I am using a Mega 2560 for this.
#define reject 40 //Reject output signal to solenoid
#define camera 42 //Reject input signal from camera
#define locator 44 //Locators for belt alignment
#define conSens 46 //Sensor to detect connector presense
#define laser 48 //Engraver
#define relay 52 //Relay for motor cut off
#define beltSens 50 //Sensor to trigger motor cut off
int rejectCount = 0;
int beltState = 0;
void setup() {
pinMode (reject, OUTPUT); //Output signal for rejection
pinMode(camera, INPUT); //Input signal to identify failed connector
pinMode(locator, OUTPUT); //Output signal to trigger locators
pinMode(conSens, INPUT); //Input signal to confirm connector presense
pinMode(laser, OUTPUT); //Output signal to trigger engraver
pinMode(relay, OUTPUT); //Output signal to stop motor
pinMode(beltSens, INPUT); // Input signal to trigger motor stop + camera
}
void loop() {
beltState = digitalRead(beltSens); //Read sensor state to detect part
if(beltState == HIGH)
{
digitalWrite(relay, HIGH); //Cut power passing through relay to bring motor to stop
delay(250); //Delay before engaging locators
digitalWrite(locator, HIGH); //Engage locators
delay(200); //Delay before starting engrave
digitalWrite(laser, HIGH); //Start engraving
delay(200); //Delay to allow engrave to complete
digitalWrite(laser, LOW); //Disengage engraver
delay(1100); //Delay before disengaging locators
digitalWrite(locator, LOW); //Disengage locators
delay(150); //Delay before re-engaging relay
digitalWrite(relay, LOW); //Engage relay to resume motor
delay(350); //Delay to avoid sensor reading HIGH for same part
}
}
void rejected() {
rejectCount = digitalRead(beltSens);
if (camera == HIGH) {
}
}
I think the best way to get this done is to write a function that does the counting and is called when the camera signal is received.
Any assistance will be greatly appreciated.
Regards
Deeds