I am completely new to Arduino programming. We are having a water bottle blowing machine which is semi automatic. We need to manually feed the preform (miniature size of bottle, this will be heated and blown within a mold to make bottle) to the heater holder.
I found some automatic feeders, and want to fabricate and modify our machine with similar type. I want to control the flow of material (preform) by stopping and starting the feeder motor based on the input from two proximity sensors.
Please refer the attached picture for the placement of sensors. I need to write a program for "Arduino Mega" board with below logic(s) and connections.
Let's say
Feeder motor M1 connected to Arduino pin 35 (digital output) to start and stop motor through a relay.
Feeder Sensor S1 connected to Arduino pin 30 (digital input)
Feeder Sensor S2 connected to Arduino pin 31 (digital input)
We also have Auto/Manual toggle switch for motor TS1 connected to Arduino pin 32 (digital input), pin input energized when in Auto mode.
the logic:
If the TS1 = 0 then
M1 = 0
If the TS1 = 1 and
If S1 is "0" for >4 seconds continuously and IF S2 is "0" for >4 seconds continuously THEN
M1 =1
ELSE
If the TS1 = 1 and
If S1 is "1" for >5 seconds continuously and IF S2 is "1" for >5 seconds continuously THEN
M1 =0
How to program this in Arduino ?
Please Note: Arduino board will be kept in fully air-conditioned place (no harsh industrial environment will affect the board)
Create separate programs for each sensor, make them work.
Create a program for the motor, make it work.
Combine all together in a single sketch based on the logic you lined out, with appropriate timing and safeguards.
First thing I'd do, to get folk to understand fully what you mean, is stop using 0's and 1's as you did in your opening post. While they probably mean low and high respectively, that does not mean that they necessarily mean off and on.
I would like to see your logic re-stated with the proximity sensors being described as say "blocked" or "clear", the switch being "open" or "closed" and the motor being "on" or "off".
edit: But what I think it means is:
If the master switch is off, motor is off.
If the master switch is on, and both sensors have been blocked for > 4 seconds, run the motor
If the master switch is on, and both sensors have been clear for > 5 seconds, turn off the motor.
(edit: deleted some stuff I said about state diagrams; it was just going to cloud things )
@OP Just for the heck of it, I wrote code to check the master switch and do the 4 second thing with the sensors. I won't post it unless you ask, on the basis that you might like to bugger around a bit first. (Hint: you should maybe just try to read the state of a button, and if it's been pressed > 4 seconds, turn on the led on pin 13. Then if it's been off more than 5, turn the led off.)
If the master switch is on, and both sensors have been blocked for > 4 seconds, run the motor (and run the motor until both sensors have been clear for > 5 seconds)
If the master switch is on, and both sensors have been clear for > 5 seconds, turn off the motor (and keep the motor off until both sensors blocked for >4 seconds)
Well if you want the code I have written (so far only does the 4s on part) just shout and I'll post it; but you may want to try further on your own first.
(Blackfin will in any case be along soon with a full working solution full of advanced techniques.)