I'm dipping my toe in on Bluetooth using the Arduino. I basically want to create a simple, "what could possibly go wrong with this setup?" scenario.
I have an Uno R3 with small button assembly that's attached to GND, 3v3, and digital pin 2. For Bluetooth, I have a BlueSMiRF (Silver?) on GND, 5v, RX, and TX... no SoftwareSerial here. When the button is pressed, I want to see something transmitted from my Bluetooth module so I can see it on a terminal.
I have a pretty simple sketch to back it up...
const int buttonPin = 2;
const int ledPin = 13;
int buttonState = 0;
void setup(){
Serial.begin(9600);
Serial.print("Bluetooth");
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop(){
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH)
{
digitalWrite(ledPin, HIGH);
if(Serial.available()) // If the bluetooth sent any characters
{
// Send any characters the bluetooth prints to the serial monitor
Serial.print("I'm a bluetooth module");
}
}
else
{
digitalWrite(ledPin, LOW);
}
}
I've got a connection (a solid one at that) to the module via BlueTerm on Android. When I upload this code onto the Uno and press the button, I don't get anything on BlueTerm. I get the feeling that my implementation is a gross oversimplification of what's required. What am I doing wrong here?
Are you trying to use both the serial monitor and bluetooth module on the same UART? What is on the other end of the bluetooth connection, what terminal are you using?
HazardsMind:
Are you trying to use both the serial monitor and bluetooth module on the same UART? What is on the other end of the bluetooth connection, what terminal are you using?
You need to define how the switch is wired. You are not using the internal pullup resistor, so you MUST have an external one. Why are you connecting the switch to 3.3V on a 5V Arduino?
PaulS:
You need to define how the switch is wired. You are not using the internal pullup resistor, so you MUST have an external one. Why are you connecting the switch to 3.3V on a 5V Arduino?
I've got the Bluetooth module attached to the 5v pin. I've also got the pullup resistor on the button circuit (10k ohms, sorry for not mentioning that).
However, the LED button itself works fine. It's just when the button is pressed, nothing shows up on the BlueTerm screen on my tablet.
Write a simple code to receive from the Serial monitor and see if you can send something to the arduino with Blueterm. Does your phone say it is paired to the bluetooth module?