Go Down

Topic: Leonardo Serial Problem (Read 2079 times) previous topic - next topic

selimerkan

Hi everyone.
I 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.
Code: [Select]
#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 ...
}

PaulS

Code: [Select]
delay(100);// prepare for next data ...
How can you possibly misinterpret sitOnYourFatAssDoingNothing() as preparing anything for the next data?

selimerkan


Code: [Select]
delay(100);// prepare for next data ...
How can you possibly misinterpret sitOnYourFatAssDoingNothing() as preparing anything for the next data?


how can I do?  Am I must delete this line?

PaulS

Quote
how can I do?

How can you do what?

Quote
Am I must delete this line?

I would.

Why are you using SoftwareSerial to talk to the bluetooth device? You aren't using the hardware serial port of serial data read/write operations. You are one of the pins to drive your motors (which you really shouldn't be doing).

selimerkan


Quote
how can I do?

How can you do what?

Quote
Am I must delete this line?

I would.

Why are you using SoftwareSerial to talk to the bluetooth device? You aren't using the hardware serial port of serial data read/write operations. You are one of the pins to drive your motors (which you really shouldn't be doing).

Which is correct code? Im newbie  in arduino?
Will u send an example for bluetooth code with leonardo ?

Go Up