In this experiment we connect android device and arduino with bluetooth module and send some string after we will see on 16x2 lcd display.
Requirements
-Arduino (I use uno you can use other types.)
-Bluetooth Module (I use HC-06 module.)
-16x2 lcd display
-Android device
-Some jumpers
-If preferred potentiometer.
Arduino Part
Firstly we talk about jumper connections. You can use arduino’s SerialDisplay connection which is below. You don’t have to use potentiometer(connect Vo pin to arduino’s ground.)
Adding Bluetooth Module to arduino.
Module has 4 legs. vcc gnd rxd and txd.
-rxd sends data
-txd receive data
it connects like that.
The most important thing is if you connect rxd and txd with arduino you can not send your code to arduino .Arduino ide shows this error.
avrdude: stk500_recv(): programmer is not responding
To solve this error unplug rxd and txd from arduino when sending code to arduino.
This is the Arduino code.
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup(){
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// initialize the serial communications:
Serial.begin(9600);
}
void loop()
{
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
delay(100);
char s=Serial.read();
lcd.write(s);
//Serial.write(s);// send data to device
}
}
}
if you want to send data arduino from the android device You can add
Serial.write(s); // it send read char.
lcd.write(s); // it show char on display.
Android Part
I use BluetoothChat example. You can download code from
HERE .
the code simply connect with other android devices and send and receive string.
The important thing is we connect android to HC-06 Bluetooth Module not android to android.
we should make some changes.
There are 3 java code in this project. One of them is BluetoothChatService.java we change only one line in this code and android can connect too HC-06 Bluetooth Module.
//Actual Unique UUID for this application generated by Android: fa87c0d0-afac-11de-8a39-0800200c9a66
//common machine UUID that we need to communicate with HC-06 Bluetooth module: 00001101-0000-1000-8000-00805F9B34FB
//private static final UUID MY_UUID = UUID.fromString("fa87c0d0-afac-11de-8a39-0800200c9a66”); // we change it with below.Then android can connect to HC-06
private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB”);
You can see how it works on youtube.
Thank You.
0 comments:
Post a Comment