DC motor only runs when arduino is connected to pc

Hello! I'm trying to build a very simple toy boat, so far I have a DC motor driven by an L293D chip which is controlled by an IR remote. The DC motor however only works if my arduino is connected directly to my pc via usb... once I upload the code to the arduino, disconnect it from the PC and connect it to a 9v battery the motor stops working.

Your guess is as good as mine as long as we don't have the code and the wiring diagram.
Please post the code within </> code-tags and a drawn schematic (not Fritzing !)

CODE

#include <IRremote.h>

//this pin will be used to power the IR chip (to prevent noise from the motor)
int voltPin = 11;

//IR remote
int IRpin = 5;
IRrecv IR(IRpin);
decode_results cmd;

//MOTOR 
int en1 = 9;
int dir1 = 8;
int dir2 = 7;

void setup() {
IR.enableIRIn();

pinMode(en1, OUTPUT);
pinMode(dir1, OUTPUT);
pinMode(dir2, OUTPUT);

pinMode(voltPin, OUTPUT);
digitalWrite(voltPin, HIGH);

Serial.begin(9600);
}

void loop() {
 
  while (IR.decode(&cmd) == 0){
}
  delay(200);
  IR.resume();

//FORWARD
  if(cmd.value == 0xCC3359A6){
  digitalWrite(dir1, HIGH);
  digitalWrite(dir2, LOW);
  analogWrite(en1, 255);
}

//BACKWARDS
 if(cmd.value == 0xCC33D926){
  digitalWrite(dir1, LOW);
  digitalWrite(dir2, HIGH);
  analogWrite(en1, 255);
} 

//STOPS
  if(cmd.value == 0xCC334BB4){
  digitalWrite(dir1, LOW);
  digitalWrite(dir2, LOW);
  analogWrite(en1, 0);
  }
}

CIRCUIT:

*note: I use a MB102 power supply module on the breadboard (circuit diagram doesn't show it). Also, the circuit shows a 4510 BCD counter instead of the L293D chip because the software I used didn't have it (sorry but I didn't know what to do). This is what the different ports correspond to:

"Load": EN1
"L0": IN1
"L1": OUT1
"L2" and "L3": 0V
"Clock": OUT2
"TC": IN2
"Gnd": +Vmotor

Hi,
Welcome to the forum.

To add code please click this link;

What 9V battery are you using?
One of these?
ab-base_2_142

Do you have a DMM?

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

2 Likes

Yea, I'm using one that came in an Elegoo starter kit but it's still 9V

On this forum we always say to keep those for a smoke detector, it is far too weak for an Arduino board and even worse when you want to use a motor.

The L293D is from the stone age. Today there are mosfet drivers that already work at 5V and don't have the 1.2V voltage drop of the L293D.

Do you only have the Elegoo Starter Kit ?

The breadboards have sometimes bad contacts and jumper wires can be broken.

Sorry that I may be a little negative. Good sellers have good products (Adafruit, Sparkfun, Pololu), but the very cheap parts are sometimes outdated and the quality is sometimes not good enough. It's okay, you have to start somewhere :smiley:

@federicoragno119, your topic has been moved to a more suitable location on the forum.

I'm not quite sure why you thought that this relates to Avrdude, stk500, Bootloader issues

Alright thank you for the advice, unfortunately I already bought the kit. Is there any other way I could power the motor? I'm afraid too much voltage could damage the Arduino...

OK I managed to make it work by just adding more batteries :slight_smile: thanks for the help

Read the technical specifications for the Arduino You use. Maximum voltage usually are among the very first data.

1 Like