Motor started with relay sometimes behaves unexpectedly (maybe because of bootloader)

Hello there. Recently, I decided to work with a relay and motor and Arduino UNO R3, but there had been some issues that seem not to appear by the present time. Though everything is fine by now I hoped to find it out what was the real cause of that. The point is that when I bootloaded a program below there were moments when it switched to the previous one (not precisely). For example, I rotated the motor back and forth, but suddenly it started to rotate only in one direction (the program which I ran previously) as if two different programs switched inside the controller. As I know only one program may be ran after it was bootloaded. Am I not right? Also, sometimes motor stopped and buzzed, but it was rather a bad connection between all the parts which I checked with multimeter (good connectivity means about 0 ohms, please, inform me if I am mistaken). I tend to think that the program which I ran just left the controller for some uknown to me reason, but I am still not sure. Are there any other reasons except for bad connectivity or possible bootloader error that may have caused such a weird behaviour? I am looking forward to hear your replies.

int in1=11;   int in2=12; 

void setup() {  

    pinMode(in1, OUTPUT);  
    pinMode(in2, OUTPUT);
    pinMode(9, OUTPUT); //PWM Speed

}

void loop() {

    analogWrite(9, 80); //Speed of motor (PWM, 0 - 255)
    
    digitalWrite(in1, 1); digitalWrite(in2, 0); //Rotate forward
    delay(2000);
     
    digitalWrite(in1, 0); digitalWrite(in2, 1); //Rotate backward
    delay(2000);

}

Here are some screenshots:



I never heard of two programs to fusion toghether, and I can't think of how it would happen either. Lets move on.

Problem would either be in the program (I can't spot anything there) or the hardware. If it intermittent it can be lose wires, especially if you use a breadboard, otherwise bad solder joints, a component that haven't failed totally.

Are the voltages ok? Can the power supplies source enough current?

Hi, @fixer_84

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Please no Fritzy, reverse engineer YOUR project.

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

1 Like

Check your wiring, motor signals should cross logic signals at a right angle. Running wires side by side will cause mutual coupling which could be severe enough to cause a glitch to trip a logic section. What have you used for bypass? Is the motor on a seperate power supply?

By this time I have been able make a four wheel drive vehicle (all four motors work properly). I have noticed that for all four wheels it was not enough to use only one 9V battery, so I used two ones to double the current and increase its power. Also I changed the board to Leonardo and it still works without any problems, so your idea that current was not enough may be true.

Thank you very much for your reply. For now everything works just fine and I already have a car which moves over the floor in one direction. Here is the photo, if you are interested.

That car looks awesome.

I suspect 2 will drain rather quickly, have a look at 3-4 18650 Li-Ion. Not that much extra weight, but you get a much better run from one charge.

Thank you very much for your reply. Now I have no any problems with motors since I have used original Arduino (at least they said it was from Italy when I bought it). All four motors are connected through two relays (two motors for each relay, screenshot may be seen in the post #2) that are powered with two 9V batteries (I can add more batteries to increase the current and power). The car moves over the floor and all four wheels rotate properly.

Thank you all for your soon attention and replies. And, please, take my apologies for the late reply of mine as I was busy with another Arduino project.

1 Like

Remember give out Solution, and happy making!

Thank you very much for your help. I will definitely acquire it on your advice.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.