I ended up adding a 1 second delay to the main loop. It works great!
For the next iteration of the project, I want to add 4 potentiometers and a 4-way selector switch.
I am hoping that the potentiometers will allow me to set the timing of each plug from 1 second to 1 minute. The 4-way selector switch would allow the use of only 1,2,3, or 4 outlets. Now that I think about it, I think 4 3-way switches would be better. This would allow the plugs to be either On 100%, variable delay, or off.
I think I need to draw this out. Any insight would be appreciated
I came across this forum post and it is just what I was looking for. First off I am a newbie to Arduino and am still learning how to program it. So here is my setup, I have a separate dual dpdt relay module that takes two input control, one for each relay, and is controlled by two outputs pin 2, 3 from the Arduino. These two Dpdt relays will be controlling a motor for forward and reverse travel.
I have three momentary switches. Basically, one switch(motor control) will control the dual sequential relays for forward and reverse, and the other two switches will be the forward and reverse limit switches to stop the motor from moving in that direction respectively. For example when the motor is moving forward and engages the forward limit swith, it will stop. Now the next time the motor control switch is pressed, it will reverse the motor and the motor will run until the reverse limit switch is engaged and stops. The next time the motor control switch is pressed again, the motor will travel forward until it hits the forward limit switch and stops. This function will loop over and over again. Also as a precaution, I'm also hoping if it is even possible if neither limit switch is engaged like if a power outage occurred during midway travel, the arduino will know to automatically reverse the motor travel the next time power comes back on.
So far from Jurs code above, I was able to modify it to accommodate my two relays, the timing delay, and the pins I am using.
Would this be even possible with Jurs's code above to add on to it?
muddesk:
I have a separate dual dpdt relay module that takes two input control, one for each relay, and is controlled by two outputs pin 2, 3 from the Arduino. These two DPDT relays will be controlling a motor for forward and reverse travel.
You should not need DPDT relays for reversing. Just use two SPDT relays, one to actuate forward and the other to actuate reverse. Generally, SPDT relays have more robust contacts.
There is a "gotcha" with this - when the respective relay switches off, the motor is short-circuited and brakes rapidly. If you do not want this, you need a diode in each NC relay arm.
Thanks for the suggestion, I do have a dual spst relay module laying around as well I will use that instead. so by mentioning the NC relay arm as the place the diode with be placed, it is the link between NC2 and NC1 is that correct?
Now i"m just not sure how to edit Jurs code to incorporate the two limit switches to stop the motor from running in respective directions.
muddesk:
it is the link between NC2 and NC1 is that correct?
It needs to be a diode from each NC to the power supply. Interestingly, if you do that, there is still the option of implementing dynamic braking if needed by actuating both relays simultaneously as the NO contacts will not have diodes.
muddesk:
Now i"m just not sure how to edit Jurs code to incorporate the two limit switches to stop the motor from running in respective directions.
You have two choices with limit switches. You can use the code to read them and disable the relays if the corresponding one actuates, or if they can handle the full motor current, you put them in series with the respective NO contacts. This is more reliable but the problem then is that the limit switches stop the motor, but the microprocessor does not know that has happened. A third option is to put each limit switch in series with the respective relay coil.
I have a question, in the option where i place the limit switch on the NO open contacts of the relays, is it bad thing that the arduino will keep running because it does not know that the limit switch was engaged? Also i'm assuming that this will be wear and tear on the relay because the coil will always be energized?
muddesk:
I have a question, in the option where i place the limit switch on the NO open contacts of the relays, is it bad thing that the Arduino will keep running because it does not know that the limit switch was engaged?
That depends entirely on what you are doing. If the Arduino needs to wait until the limit is reached before performing some other function, then it needs to be able to sense the limit switch. If however it can do something irrespective of whether the limit is reached, such as reverse the direction, then it does not matter. If you do want to reverse the direction while the motor is running, then you should incorporate a delay to allow the motor to stop before it is powered in reverse.
muddesk:
Also I'm assuming that this will be wear and tear on the relay because the coil will always be energised?
A relay of any usable quality will not care, but you would probably want to switch it off after plenty of time for the motor to reach the limit just to save a little bit of power in your controller.