I'm following this drawing to build the cicuit, but I'm using a toy dc motor and 9v power supply for the h bridge, when i connected the circuit up the pot did nothing and when i pressed on the pushbutton it turned off and back on again when I let go of it, pelase help
There needs to be a connection between the Arduino ground and the L298 ground so that there is a reference for the signals from the Arduino to the L298.
There may need to be a connection from the Arduino 5V to the 5V of the L298 for logic supply. Check the data sheet of the L298 that you have.
Are you going to share your code with us ?
What is that "9 volt power supply"? A 6fc battory? I hope not. I can see You use an Arduino UNO but my X-ray eayes don't manage to read the code under the surface of the UNO. How is the UNO powered?
Use the code tags </> symbol up to the left in this window and attache the code.
So sorry for not including the code, completely forgot about it, here it is:
#define enA 9
#define in1 6
#define in2 7
#define button 4
int rotDirection = 0;
int pressed = false;
void setup() {
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(button, INPUT);
// Set initial rotation direction
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
}
void loop() {
int potValue = analogRead(A0); // Read potentiometer value
int pwmOutput = map(potValue, 0, 1023, 0 , 255); // Map the potentiometer value from 0 to 255
analogWrite(enA, pwmOutput); // Send PWM signal to L298N Enable pin
// Read button - Debounce
if (digitalRead(button) == true) {
pressed = !pressed;
}
while (digitalRead(button) == true);
delay(20);
// If button is pressed - change rotation direction
if (pressed == true & rotDirection == 0) {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
rotDirection = 1;
delay(20);
}
// If button is pressed - change rotation direction
if (pressed == false & rotDirection == 1) {
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
rotDirection = 0;
delay(20);
}
}
groundFungus:
There needs to be a connection between the Arduino ground and the L298 ground so that there is a reference for the signals from the Arduino to the L298.There may need to be a connection from the Arduino 5V to the 5V of the L298 for logic supply. Check the data sheet of the L298 that you have.
Sorry but I'm not quite sure what you mean and I don't know waht a datasheet is, kinda new to electronics.
Data sheet = technical specification, description.
Have a look at this thread. It shows what is wrong with the diagram that you posted.
groundFungus:
Have a look at this thread. It shows what is wrong with the diagram that you posted.
I see, but Im not sure on how to actually make a common ground between the motor driver and the arduino
UPDATE: I connected the grounds together and the 5v to the Vin. but it's still not working, same problem as before, when I push the button it all goes off until I let go of the button
5V to Vin? Do mean the barrel jack?
Railroader:
5V to Vin? Do mean the barrel jack?
Or the Vin pin that is connected to the barrel jack? Either one would be wrong, as @Railroader is correctly thinking. Vin has to be at least 9V for practical purposes.
Pull the button out, turn it 90 degrees, put it back in, try it.
JCA34F:
Pull the button out, turn it 90 degrees, put it back in, try it.
Yes, good idea.
Can you post a picture of your project please, so we can see your component layout?
Do you have a DMM?
What do you mean "all goes off".
Please answer these points.
Place the pot in a midway position.
- What happens when you apply power?
- What happens when you press the button.
- What happens when you then release the button?
Thanks.. Tom.. ![]()
snakeviper123:
When I press the button the Arduino goes off and the motor driver light goes a bit dim, when I let go of the button the Arduino lights come back on, and the motor driver light lights up again. Here is the layout of my components.
Where is the gnd connection between UNO and the motor controller?
Your press button is shorting out the 5v rail by the sounds of it.
Remove the motor and see if the LEDs dim.
Can you post a picture of your project so we can see your component layout.
Do you have a DMM to check the pins on the button?
Tom.. ![]()
A picture? are you sure because the wires are all over the place and it's not really clear, but the pic I sent you is exactly what I did.
And what is a DMM?
The GND connection with the UNO and motor driver is where I connected the motor driver GND to the Breadboard GND powered by the UNO GND
Hi,
DMM == Digital MultiMeter.
In this situation it would be invaluable.
You need to check the wiring around the button, the symptoms sound like the button is shorting the 5V to gnd.
If you are using one of those tactile buttons, make sure the button is mounted the correct way.
This how the tactile is internally wired.
Tom....
Yes, that's how I'm using the button, could you possibly send me a schematic of how the wiring should ideally be, I could try that to see if it would work. Thanks
snakeviper123:
Yes, that's how I'm using the button, could you possibly send me a schematic of how the wiring should ideally be, I could try that to see if it would work. Thanks
To be sure that the switch connection wires actually go to each side of the switch it is better to wire them to a diagonally opposed pair of pins on the switch. Otherwise it is all too easy to orient the switch incorrectly and connect the wires to switch pins that are permanently connected together



