2 systems won't work together (L298N, Arduino UNO)


So I am trying to build RC car using Arduino UNO. On the picture below you can see my electric sheme. The problem I have is that when I power up the circuit SERVO motor is working OK (I move servo by rotating potenciometer), but when I try to move DC motor by pressing buttons it doesn't work (there is a red light on L298N modul but I think that is normal since it is on even when the modul is working OK).
I tried the system where I use only L298N, DC motor and 4 PUSH-BUTTONS and everything works as it should, but as soon as I add Servo in the program and in the circet, the Servo is working OK but L298N, DC motor and PUSH-BUTTONS are not responding.
From what I read, L298N needs 2V to operate and the rest goes to motors so in my case the motor should get 5V which is enough.
Doese anyone have any idea why would this happend?

Thank you for your help.

Electric scheme:


#include <Servo.h>
Servo myservo;
int a=0;
int b=0;
int c=0;

#define enA 10 
#define in1 4 
#define in2 5
int motorSpeedA = 0;
int gear = 0;

void setup() {

pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);

pinMode(1, INPUT_PULLUP);    
pinMode(3, INPUT_PULLUP);    

pinMode(6, INPUT_PULLUP);    
pinMode(8, INPUT_PULLUP);    

void loop() {
int forward = digitalRead(1);
int backward = digitalRead(3);
int gear1 = digitalRead(6);
int gear2 = digitalRead( 8 );

if(a !=  b){

c=map(b, 0, 1023, 55, 115);

if(gear1 == 0){
  gear = 110;
if(gear2 == 0){
  gear = 210;

if(forward == 0){
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  motorSpeedA = gear;
else if(backward == 0){
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  motorSpeedA = 110;          
  motorSpeedA = 0;

analogWrite(enA, motorSpeedA);

If you read the Servo library reference information at Servo - Arduino Reference you will see:

"On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10"


1 Like

You should never attempt to power a servo or motor from the Arduino 5V power supply. Doing so will likely cause malfunctions and eventually, damage the Arduino.

Always use a separate supply for motors and servos. Don't forget to connect the grounds.

The problem as pointed out by Steve (slipstick) was Servo library which disabled PWM signal on pin 10. I changed that signal to pin 11 and now everything is working as it should.

Thank you all very much.

According to your wiring diagram, the servo is powered from the Arduino 5V, which is a really stupid thing to do.

I fixed Servo wiring so now it gets power from battery pack rather then Arduino.