HC-05 Bluetooth module not working after trying to use analog pins for RX/TX

Hello,

I am working on a project in which i can't use pins 0 and 1 for RX and TX.
After browsing online I found several sources stating that you can use analog pins as RX and TX.

Initial code used tx=0 and rx=1

#include <SoftwareSerial.h>

int tx=0;
int rx=1;

SoftwareSerial bluetooth(tx, rx);

void setup(){
  
  bluetooth.begin(9600);
  pinMode(tx, OUTPUT);
  pinMode(rx, INPUT);
}


void loop(){
  
}

Since i need those pins I tried initializing pins A0 and A1 as RX and TX.

#include <SoftwareSerial.h>

int tx=0;
int rx=1;

SoftwareSerial bluetooth(tx, rx);

void setup(){
  
  bluetooth.begin(9600);
  pinMode(tx, OUTPUT);
  pinMode(rx, INPUT);
}


void loop(){
  
}

This didn't work, but when I tried switching back to the initial code it didn't work anymore.

Can someone tell me what may have been wrong with my code?
And why doesn't my old code (that worked before) work anymore?

Thank you in advance for helping me out :slight_smile:

Sabre

Sabre254:
can't use pins 0 and 1 for RX and TX.

Explain this.

I don't suppose anybody will tell you why the old code works no more, it should never have worked in the first place. Much the same applies to the new code, which seems the same as the old. Pins 0,1 are for hardware serial. Never use them for software serial.

You might find the following background notes useful.

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf
http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

Hello Nick,

I might have switched them around in my explanation. My apologies.

But as you can see in the code I took TX as 0 and RX as 1.

I also made a mistake in the second piece of code.
I will correct the code.

#include <SoftwareSerial.h>

int tx=A0;
int rx=A1;

SoftwareSerial bluetooth(tx, rx);

void setup(){
  
  bluetooth.begin(9600);
  pinMode(tx, OUTPUT);
  pinMode(rx, INPUT);
}


void loop(){
  
}

I will take a look in these notes, thanks.
If any other questions pop up I will ask again.