
In this tutorial we will see how to connect the Arduino board to the smartphone via bluetooth. This is why we are going to create two programs: a mobile application with App Inventor for the smartphone and a program for the Arduino board.
Here is the program that connects the Arduino board to the smartphone.
The word ‘connected’ is displayed on the LCD display if the Arduino board is connected to the smartphone and the letter ‘disconnected’ otherwise.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include <SoftwareSerial.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 20, 4); SoftwareSerial hc06(2,3); String message=""; void setup(){ lcd.init(); hc06.begin(9600); } void loop(){ lcd.backlight(); lcd.setCursor(0, 0); //Write data from HC06 to Serial Monitor if (hc06.available()){ message+=char(hc06.read()); lcd.clear(); lcd.print(message); //Display the message on the LCD display} else message=""; } |
We create a mobile application called ‘connect_arduino’ with App Inventor which allows you to connect the smartphone to the Arduino board.
We propose to create the design of the application, with the following visual:
To program the application, App Inventor offers us to use the Blocks space, which allows you to create a program in the form of a block diagram. Very easy to use but requiring a little programming logic.
Here is the program of the application created in the Blocks area of the Inventor App: