I have connected a RN-42 bluetooth (TX-D0, RX-D1, VCC-5V, GND_GND) to arduino.The problem is that when I run this code ,nothing happens it just upload to infinite or it doesn't. I am checking with tera term. Is there a problem with the connection of the pins? Also when I pair my android phone to the bluetooth it says paired on the phone but the blue light of the bluetooth doesn't switch on, like it's not connected.
#include <SoftwareSerial.h>// import the serial library
SoftwareSerial Genotronex(1, 0); // TX,RX
int ledpin=13; // led on D13 will show blink on / off
int BluetoothData; // the data given from Computer
void setup() {
// put your setup code here, to run once:
Genotronex.begin(9600);
Genotronex.println("Bluetooth On please press 1 or 0 blink LED ..");
pinMode(ledpin,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (Genotronex.available()){
BluetoothData=Genotronex.read();
if(BluetoothData=='1'){ // if number 1 pressed ....
digitalWrite(ledpin,1);
Genotronex.println("LED On D13 ON ! ");
}
if (BluetoothData=='0'){// if number 0 pressed ....
digitalWrite(ledpin,0);
Genotronex.println("LED On D13 Off ! ");
}
}
delay(100);// prepare for next data ...
}
4 Answers 4
As commenter by RSM
The issue you are facing is because you are using pins 0 and 1
These are used by the arduino for uart.
So for starters please use any pin other that 0 and 1. But if you insist that you do need to use these pins, then you don't need softwareserial you can use the default serial itself, but you will need to disconnect the bluetooth while programming.
If you use RX, and TX in default pin then it is not necessary that you should include SoftwareSerial library.
The simplest solution to this is to just unplug the Bluetooth module from the TX and RX ports and click to upload. Your sketch will be uploaded and you can plug the pins back. For a permanent solution use the digital pins aside 1 and 0 because they are the same pins your computer uses to upload your sketch to the Arduino board.
Try taking off the bluetooth module, this will allow communication with the computer, not the bluetooth module. I had the same problems with my hc-06, and have not solved the ladder yet.
D0 and D1
pins are for communication with the PC, in line with what Owen answered try his suggestion.