Arduino robot stops working when I disconnect it from the laptop

I'm making this small ir controlled car using Arduino it all works properly when arduino is hooked up to laptop after i upload the code but as soon as i disconnect it from the laptop and use external power supply it stops working...and when i say it stops working as in the Arduino does turn on and the light does blink but it just simply does not perform the actions it is supposed to...and i think it's this tx light which stops blinking when i disconnect it from laptop and use external power source...any help would be highly appreciated!

#include <IRremote.h>

/*
   Left Motor
*/
// IN 1
#define LM_IN1    2
// IN 2
#define LM_IN2    4
/*
   Right Motor
*/
// IN 3
#define RM_IN3    5
// IN 4
#define RM_IN4    7


// IR receiver
# define RECV_PIN 10

IRrecv irrecv(RECV_PIN);

decode_results results;

//HEX codes for buttons
#define FWD       0xFD8877 // go forward
#define LFT       0xFD28D7 // go left
#define RGT       0xFD6897 // go right
#define BWD       0xFD9867 // go backward
#define STOP      0xFD30CF // stop
#define RESET     0xFD00FF // Resets the Arduino Board(RED)

unsigned long int value=0;

/*
 ************Arduino Reset Pin**************
 */
#define RESET_PIN A0

void setup() {
  
  // set mode of the pins as output
  for (int i = 2; i <= 7; i++) {
    pinMode(i, OUTPUT);
  }


  // start serial communication
  Serial.begin(9600);
  // In case the interrupt driver crashes on setup, give a clue
  // to the user what's going on.
  Serial.println("Enabling IRin");
  irrecv.enableIRIn(); // Start the receiver
  Serial.println("Enabled IRin");

}

void loop() {
  if (irrecv.decode(&results)) {
    value = results.value;
    Serial.println(value, HEX);
    irrecv.resume(); // Receive the next value
    delay(200);
  }

  delay(100);
  check_Inst(value);
  value=0;
}

void check_Inst(long int value) {

  switch (value) {
    case FWD:
      go_Forward();
      break;
    case LFT:
      go_Left();
      break;
    case RGT:
      go_Right();
      break;
    case BWD:
      go_Backward();
      break;
    case STOP:
      go_Stop();
      break;
    case RESET:
      pinMode(RESET_PIN,OUTPUT);
      digitalWrite(RESET_PIN,HIGH);   
      break;  

    default:
      value = 0;
  }
}

void go_Forward() {
 
  movement_Inst_Fwd();
  delay(10);
}

void go_Left() {
   
  movement_Inst_Lft();
  delay(10);
}

void go_Right() {
  
  movement_Inst_Rgt();
  delay(10);
}

void go_Backward(){

  movement_Inst_Bwd();
  delay(10);
}  

void go_Stop(){
  
  movement_Inst_Stp();
  delay(10);
}  

/*
 * These movement instruction are repeated several times in the code
 */
void movement_Inst_Fwd(void){
  Serial.println("Going_Forward");
  
  // forward movement instructions
  digitalWrite(LM_IN1,HIGH);
  digitalWrite(LM_IN2,LOW);
  digitalWrite(RM_IN3,HIGH);
  digitalWrite(RM_IN4,LOW);   
  } 
  
void movement_Inst_Lft(void){
  Serial.println("Going_Left");
  
  // Left movement instructions
  digitalWrite(LM_IN1,LOW);
  digitalWrite(LM_IN2,LOW);
  digitalWrite(RM_IN3,HIGH);
  digitalWrite(RM_IN4,LOW);  
  delay(500);
  digitalWrite(LM_IN1,LOW);
  digitalWrite(LM_IN2,LOW);
  digitalWrite(RM_IN3,LOW);
  digitalWrite(RM_IN4,LOW);    
  delay(500);
  }
  
void movement_Inst_Rgt(void){
  Serial.println("Going_Right");  
  
  // Rgt movement instructions
  digitalWrite(LM_IN1,HIGH);
  digitalWrite(LM_IN2,LOW);
  digitalWrite(RM_IN3,LOW);
  digitalWrite(RM_IN4,LOW); 
  delay(500);
  digitalWrite(LM_IN1,LOW);
  digitalWrite(LM_IN2,LOW);
  digitalWrite(RM_IN3,LOW);
  digitalWrite(RM_IN4,LOW); 
  delay(500);
    
  }
  
void movement_Inst_Bwd(void){
  Serial.println("Going_Backward"); 
    
  // Bwd movement instructions
  digitalWrite(LM_IN1,LOW);
  digitalWrite(LM_IN2,HIGH);
  digitalWrite(RM_IN3,LOW);
  digitalWrite(RM_IN4,HIGH);   
  }
  
void movement_Inst_Stp(void){  
  Serial.println("Stopping");    
  
  // Stp movement instructions
  digitalWrite(LM_IN1,LOW);
  digitalWrite(LM_IN2,LOW);
  digitalWrite(RM_IN3,LOW);
  digitalWrite(RM_IN4,LOW);  
  }
  1. Which Arduino?
  2. Please provide a complete wiring diagram / schematic; a photo (size max. around 300 kB) of a hand-drawn one is fine. It should clearly indicate all power connections.
  3. Your code (correctly posted using code tags) might be useful as well. Use edit -> copy for forum in the IDE and paste it in a reply.

Your topic is moved to a more suitable location on the forum.

Suspect you may be attempting to use "external power" to the "Vin" or "barrel jack".

Don't! :roll_eyes:

An Arduino requires 5 V power.

  1. arduino Uno
  2. https://csg.tinkercad.com/things/73bMPNPUEKh/t725.png?rev=1598182108524000000&s=&v=1&type=circuits

the code and schematic are there for you to see. Thanks!

Hi, @dave_10
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

You can paste you images directly into your postings.
@dave_10 image.

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

1 Like

So what u are saying is i might be supplying more voltage than Arduino requires?

Hi,
When you disconnect the USB plug, how are you powering the UNO?

Can you draw a proper circuit diagram, pen(cil) and paper would be fine, labelling ALL pins and power supplies?
I gather you are not really trying to use a 9V smoke detector battery?

Do you have a DMM?

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

Actually, I am....Quite honestly I am still a beginner so I am trying to figure it all out...but once Arduino is disconnected I believe it is being powered through the 5v pin which is connected to the common positive terminal of the power supply as shown in the schematic

You definitely have the red wire going to the wrong pin, that is likely your problem. Good thing the board is not fried, you could also fry the usb port of your pc like that. The positive of the battery needs to go to the vin pin. 7 to 12 volts is ok on that pin.

1 Like

Hi,
If you are thinking the 9V is also supplying current to the UNO, I'm afraid it isn't, it is there just to supply current to the motor through the motor control IC.

What IC is it, the image has very little fine detail.
The UNO and the digital circuit in that IC need 5V supply, and not from the 9V battery.

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

1 Like

Ahhhh that makes sense...It is a l293d btw...so i should use the 9v supply just to power the IC and then arduino and that ir receiver as shown on breadboard should have a separate power supply?

Umm i understand....but then what i am confused about is when the uno is connected to laptop the robot/car works normal even though the 9v battery is not connected...essentially everything is just powered through laptop and it all works fine

Hi,
It would be best, yes, BUT that 9V battery will not last long.

The 9V is not powering the IC, it is just providing power for the motors.
You need 5V to the IC, as you have from the UNO to power the 293 logic circuits.

I asked if you have a DMM?

Tom... :grinning: :+1: :coffee: :australia:
PS, I'm off to bed, its almost midnight here and have work in the morning.

1 Like

Well i'll look to replace it with a lipo/lion battery
I do have a DMM

So like now i should just look for a 5v power supply for arduino which will then further give power to ir receiver, and the enable pins of the IC?

Simply connect positive contact (+) of your 9V battery with Vin pin of your Arduino Uno.
Be careful.

When your Uno is connected to laptop it takes 5V supply from USB connector.

1 Like

I was finally able to get it working thank you so much for your help!

Hi,

What was the solution?

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

just followed what you told me and it worked properly.