I want to describe what I have understood with my own words:
A machine is producing plastic injection molded parts. These parts have three metal inserts.
The device shown in the picture has these three inductive proximity sensors.
A worker will put the new produced injection molded part into the checking device.
The recess ensures that the part is precisely aligned and if all three metal inlets are really inside the injection molded part the green LED should switch on signalising that all three metal inserts are inside the injection molded part.
Does this mean the metal inserts are covered with plastic from all sides?
Are the metal inserts not visible?
From seeing the device now an if-condition is indeed sufficient.
The code has to check
"have all three inductive proximity sensors switched to signal "metal present" ?
And in case of yes switching on the green led.
This means a simple if-condition with two logical "AND"'s will be sufficient
// with each iteration read in all three sensors new
sensorLeftState = digitalRead(sensorLeftPin);
sensorMiddleState = digitalRead(sensorMiddlePin);
sensorRightState = digitalRead(sensorRightPin);
if (sensorLeftState == metalDetected && sensormiddleState == metalDetected && sensorRightState == metalDetected) {
digitalWrite(LED_Pin, ON);
}
else {
digitalWrite(LED_Pin, OFF);
}
The code above uses self-explaining constants which must be defined additionally
You should make a pre-test with your proximity sensors:
The pretest is done without Arduino
connect a 20kOhm-resistor to +5V.
connect other end of the resistor to red probe of digital multimeter
connect black probe of digital multimeter to signal-wire of the proximity-sensor
measure current with no metal present (current should be zero)
measure current with metal present
current should be approximately 0,25 mA
.
.
voltage measuring:
dis-connect digital multimeter
connect signal-wire of the proximity-sensor directly to the resistor.
Adjust digital multimeter to measuring voltage
measure voltage between ground and singnalwire of the proximity-sensor with no metal present should be +5V
measure voltage between ground and singnalwire of the proximity-sensor with metal present should be approx 0 V
If you have done this pre-checking you know inductive proximity-sensor works as expected
next step connecting the signalwires of the proximity-sensors to
digital
inputpins
named D4, D5, D6
The digital input-pins must be configured
pinMode (sensorLeftPin, INPUTPULLUP);
pinMode (sensorMiddlePin, INPUTPULLUP);
pinMode (sensorRightPin, INPUTPULLUP);
write a testcode that does nothing more than printing the logical state of the three IO-pins to the serial monitor all in one line
This will check if the proximity sensors work as expected when connected to the arduino
only after these pre-tests start writing the final code