Yes…I’m alive.
It’s about 1 year that I didn’t post something on this wonderful blog but I’ve been quite busy.
But some days ago I bought a bluetooth module (HC-06, the cheapest module for Arduino) in order to integrate wireless capability in my HomeTemp project, and I want to share a simple thing about its configuration:
DO NOT WIRE THE MODULE TO RX1 (pin 0) AND TX1 (pin 1).
I tried the easiest way to connect the module to an Arduino UNO board, using the standard RX1 and TX1 pin, but the behavior was a little confusing:
- The module sends correctly data via bluetooth
- The module does not receive any data via bluetooth
I didn’t understand why…maybe a “conflict” with the standard Serial USB communication. But after some experiments I found a post somewhere that suggests to use the “SoftwareSerial” Arduino Library and use two others PIN (10 and 11). With this simple configuration the following example works like a charm 🙂 Not all pins support change interrupts, check the SoftwareSerial page and check which pins should work.
Pair the device with your PC (the default pairing PIN is 1234) and then open a serial console (on Mac OSX I use “screen /dev/tty.XXXYYZZZ). You are now able to read and send data.
I hope it could be helpful to someone.
#include <SoftwareSerial.h> #define LED_PIN 12 SoftwareSerial bluetoothSerial(10, 11); void setup() { pinMode(LED_PIN, OUTPUT); Serial.begin(57600); bluetoothSerial.begin(9600); bluetoothSerial.println("I'm ready"); digitalWrite(LED_PIN, LOW); delay(300); digitalWrite(LED_PIN, HIGH); delay(300); digitalWrite(LED_PIN, LOW); delay(300); digitalWrite(LED_PIN, HIGH); delay(300); digitalWrite(LED_PIN, LOW); Serial.print("Ready to go"); } void loop() { if (bluetoothSerial.available() > 0) { char inChar = bluetoothSerial.read(); if (inChar == '1') { digitalWrite(LED_PIN, HIGH); bluetoothSerial.print("ON"); } else if (inChar == '0'){ digitalWrite(LED_PIN, LOW); bluetoothSerial.print("OFF"); } } }