this is my first question. I would like to know what my mistake is, I have been seeking it the whole time.
In my project using an H-bridge with two DC-motors I do get neither any signals regarding the serial monitor nor the motors do not rotate even though I have checked everything.
Thanks in advance.
My Code:
const int m1 = 3;
const int e1 = 5;
const int e2 = 6;
const int m2 = 9;
const int e3 = 10;
const int e4 = 11;
zerogamer38:
I do get neither any signals regarding the serial monitor
There is nothing in your code that prints to Serial, so that's expected. When you are having troubles, it is a good idea to add some Serial.println() statements in strategic locations in your code so you can see what's happening in the program. You can learn how to do that by studying this documentation:
zerogamer38:
for (int i; i<256; i = i + 10)
You need to initialize i. Local variables are not zero-initialized, so i will contain whatever value happens to be in that section of memory at the time.
You will get a helpful warning about this from the compiler, printed in the black console pane at the bottom of the IDE window if you enable warnings (File > Preferences > Compiler Warnings > All).
zerogamer38:
digitalWrite(e1, HIGH);
digitalWrite(e2, LOW);
It probably won't cause any problems (unless you are using a Nano 33 BLE), but setting the pin to the same state over and over again is unnecessary. You could just set it once before entering the for loop.
zerogamer38:
for (int i; i<0; i = i + 10)
This is some odd code. What is your intended behavior here?
To test each motor initially, I would lose the for() loop stuff, and just in setup() do the 2x appropriate digitalWrite()s and analogWrite() the enable pin to 255.
Do that for only one motor, compile and run, then edit the other motor in instead.
Then edit again to do it for both motors together; that way you would be checking you are supplying enough current.
Then if the motors work, and don't later, then you at least know your connections are ok. If they don't work, then you know it's got nothing to do with errors in the for() loops.
Keep that sketch intact, so that if tomorrow something stops working, you can revert to something that had at least worked recently.