I am new to this so please be patient with me. I have a project that involves two double relays, two motors and a push button switch. When I wire everything together and run my code, double relay (1)only runs the motor(1) in one direction and instead of going the other direction the relay light flashes on and off quickly and continues in the same direction. I ran the relay without the motor and the lights on the relay flashed as programmed. The second motor and relay work just fine. I’m not sure why this is happening? Does anyone have any ideas? Oh and I tried to debug by having that relay and motor run on its own, and it ran perfectly. But once the push button switch and other relay and motor are added the issue begins. Any ideas?
Here is My Schematic:
#define M1 2 // relay 1 Motor 1
#define M2 3 // relay 2 Motor 1
#define M3 4 // relay 3 Motor 2
#define M4 5 // relay 4 Motor 2
#define LED 7 // for LED
#define SWITCH 8 //switch
void setup() {
pinMode(M1,OUTPUT);
pinMode(M2,OUTPUT);
pinMode(M3,OUTPUT);
pinMode(M4,OUTPUT);
pinMode(Sensor,INPUT);
pinMode(LED,OUTPUT);
pinMode(SWITCH,INPUT);
digitalWrite(M1,HIGH); // start with relay off
digitalWrite(M2,HIGH); // start with relay off
digitalWrite(M3,HIGH); // start with relay off
digitalWrite(M4,HIGH); // start with relay off
delay(1000); // pause for effect
}
void loop() {
while (digitalRead(SWITCH) == LOW){ //does until switch is closed
digitalWrite(LED,HIGH); //flash LED once
delay(250);
digitalWrite(LED,LOW);
delay(250);
}
digitalWrite(M3,LOW); //Motor 2 Direction 1
delay(600);
digitalWrite(M4,LOW); //off
delay(5000); //brief pause to dissipate any voltage spikes
digitalWrite(M1,LOW); //Motor 1 Direction 1
delay(1900);
digitalWrite(M2,LOW); //off
delay(5000);
digitalWrite(M3,HIGH); //Motor 2 Direction 2
delay(600);
digitalWrite(M4,HIGH);//off
delay(5000); //brief pause to dissipate any voltage spikes
digitalWrite(M1,HIGH); //Motor 1 Direction 2
delay(1900);
digitalWrite(M2,HIGH);//off
delay(5000);
}
Please post a schematic. Written descriptions are always more ambiguous than a drawing. Hand drawn, photographed and posted is fine. Include all pin names/numbers, components, their part numbers and/or values and power supplies.
The "H Bridge" which you have formed out of a DPDT relay to reverse the motor looks wrong to me. The N/O and N/C pins should be crossed over something like this:
Do you have a digital multimeter?
If you measure the "output" of your DPDT does the polarity change as expected?
I'm a electronic hobbiest and have quite some experience with schematics.
If I would like to analyse your schematic I would immidiately re-draw your schematic line by line so that the new drawing follows the common rules of how schematics shall be drawn.
And the most important difference would be to draw it in a way that lines do not cross more than nescessary and that the lines do not change their direction more than nescessary.
Using letters "NC" "C" and "NO"
instead of the typical relay-symbols
makes it very hard to follow
The code has the motors turn off when it is finished rotating for a specific amount of time. I am not sure what you mean. Do you mean that it is running forever ?
To clarify, the OP's schematic in No.1
is correct. The motor is stopped when both
poles are Pos or both poles are Neg. (Using DPDT relays is, IMO, a little 'dicey' though - there could be some sparking depending on how they make and break.)