So I am using a Bluetooth module with the Arduino called HC-05 and all worked well until I noticed it keeps returning unavailable.
Code:
#include <SoftwareSerial.h>// import the serial library
SoftwareSerial BTSerial(0, 1);
int ledpin=13; // led on D13 will show blink on / off
char BluetoothData; // the data given from Computer
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
BTSerial.begin(38400);
Serial.println("Started:");
pinMode(ledpin,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (BTSerial.available() > 0){
BluetoothData=BTSerial.read();
Serial.println(BluetoothData);
} else {
Serial.println("Unavailable!")
}
delay(100);// prepare for next data ...
}
Don't use pins 0 and 1 for SoftwareSerial. They are used by the hardware Serial UART of AVR based Arduinos such as the Uno and Nano. Use 2 other GPIO pins of your choice
Does the Bluetooth pairing work OK ?
I assime the you have cross connected Rx/Tx between the Arduino and the Bluetooth module and that the baud rate is correct