External Power Problem

Hi I wrote a program. I am using bluetooth module. Relay module and motor. I am making a car.

Everything okay when its working with usb. But when I am working arduino with battery. Arduino resets itself. 

Arduino external power and motor external power different.

I try with 6 v 9v and 12 volt battery.

Thanks

#include

#include <SoftwareSerial.h>// import the serial library

SoftwareSerial Seo(10, 11); // RX, TX
int ledpin=13;
int back=1;
int forward=2;
int right=4;
int left=5;
int BluetoothData; 

void setup() {
  // put your setup code here, to run once:
  Seo.begin(9600);
  pinMode(ledpin,OUTPUT);
  pinMode(back,OUTPUT);    //in 1 in circuit draw
  pinMode(forward,OUTPUT);  //in 2 in circuit draw
  pinMode(right,OUTPUT);  //in 3 in circuit draw
  pinMode(left,OUTPUT); //in 4 in circuit draw
}

void loop() {
  // put your main code here, to run repeatedly:
   if (Seo.available()){
   int BluetoothData=Seo.read();  
   if(BluetoothData==‘1’){   //car going forward
   digitalWrite(back,1);
   digitalWrite(forward,0);
   digitalWrite(right,1);
   digitalWrite(left,1);
   }
   if(BluetoothData==‘2’){   // Car going back.
   digitalWrite(back,0);
   digitalWrite(forward,1);
   digitalWrite(right,1);
   digitalWrite(left,1);
   }
   if(BluetoothData==‘3’){   //car going forward right
   digitalWrite(back,1);
   digitalWrite(forward,0);
   digitalWrite(right,0);
   digitalWrite(left,1);
   }
   if(BluetoothData==‘4’){   // car going forward left
   digitalWrite(back,1);
   digitalWrite(forward,0);
   digitalWrite(right,1);
   digitalWrite(left,0);
   }
   if(BluetoothData==‘5’){   //back right
   digitalWrite(back,0);
   digitalWrite(forward,1);
   digitalWrite(right,0);
   digitalWrite(left,1);
   }
   if(BluetoothData==‘6’){   // back left
   digitalWrite(back,0);
   digitalWrite(forward,1);
   digitalWrite(right,1);
   digitalWrite(left,0);
   }
      if(BluetoothData==‘7’){   //blink
   digitalWrite(ledpin,1);
   delay(500);
   digitalWrite(ledpin,0);
   delay(500);
   digitalWrite(ledpin,1);
   delay(500);
   digitalWrite(ledpin,0);
   delay(500);
   }
      if(BluetoothData==‘0’){   //stop everything
   digitalWrite(back,1);
   digitalWrite(forward,1);
   digitalWrite(right,1);
   digitalWrite(left,1);
   }
   
}
delay(100);// prepare for next data …
}

This is my code.

 have a problem. I am using hc 06 bluetooth module. I wrote a program in visual studio. This program very basic. it is connecting bluetooth module and sending 1 2 3 4 5 6 7 0 
My arduino getting this data. When I send this. first sending working but second sending isnt working. sometimes working sometimes not working. Arduino resetting itself. Or working not normally.
This is my circuit. I added attachment. And I am using an relay module. I added them.

When I send data “1” my car is going forward when I send “2” my car is backward etc.
In circuit draw. I showed relay module connection. 5 V GND in1 in2 in3 in4 using for relay module.
I used (4*1,5Volt AA Battery) for leonardo.
I used 3,7 volt for motors. I attached relay connection image I use for motor turning. I have relay module with 4 relay

This is my code.
Which pin is 0 ? this motor is running. When back pin is 0 motor turning back.

 

index.png

index.jpg

index.jpg


I don’t know if this helps

I don’t know if this helps but two things I’m thinking are…

1. have you got common ground supplies. The gnds from both power sources should be joined.

2. I had trouble with win7 refusing to maintain an open connection with the HC06. It seemed to timeout when the connection was idle for any length of time. This is a common issue I believe and some have solved it with installing new drivers from toshiba but I had no success. To get around it I just kept sending a bit of junk data to maintain the connection.

Make sure that the
Make sure that the -(negative) terminal of both batteries are connected together so you have a common ground would be my first suggestion.

Do you

have all the grounds tied together?

Ground???
In 6 minutes you have 3 seperate suggestion of checking for a common ground, so i think consensus is to check that first :slight_smile: