
In this tutorial, we will create a system allowing LEDs to be turned on and off (by bluetooth) using the Arduino board and a smartphone.
We will create two programs: a mobile application with App Inventor for the smartphone and a program for the Arduino board.
Test plate
Connecting wires
To carry out the assembly, you can connect:
the (-) terminals of the three GND LEDs of the Arduino.
red LED (+) terminal to digital pin 4 of Arduino
the terminal (+) of yellow LED to the digital pin 5 of the Arduino
the terminal (+) of green LED to the digital pin 6 of the Arduino
the GND terminal of the bluetooth module to GND of the Arduino
the VCC pin of the bluetooth module to the 5V pin of the Arduino
the RXD terminal of the bluetooth module to the digital pin 3 of the Arduino
the TXD terminal of the bluetooth module to the digital pin 2 of the Arduino
the SDA pin of the LCD display to A4 PIN of the Arduino
the SCL pin of the LCD display to A5 PIN of the Arduino
the GND pin of the LCD display to GND pin of the Arduino
the VCC pin of the LCD display to 5V pin of the Arduino
Here is the program that allows you to connect the Arduino board to the smartphone and receive a message containing the order to turn the LEDs on or off.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
#include <SoftwareSerial.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 20, 4); SoftwareSerial hc06(2,3); String message=""; void setup(){ pinMode(btnPin,INPUT_PULLUP); pinMode(bouton, INPUT); lcd.init(); //Initialize Serial Monitor //Initialize Bluetooth Serial Port hc06.begin(9600); pinMode(4,OUTPUT); pinMode(5,OUTPUT); pinMode(6,OUTPUT); } 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); }else{ if (message=="allumer_rouge") { digitalWrite(4,HIGH); // the red LED lights up } if (message=="eteindre_rouge") { digitalWrite(4,LOW); //the red LED goes out } if (message=="allumer_jaune") { digitalWrite(5,HIGH); //the yellow LED lights up } if (message=="eteindre_jaune") { digitalWrite(5,LOW); //the yellow LED goes out } if (message=="allumer_verte") { digitalWrite(6,HIGH); //the green LED lights up } if (message=="eteindre_verte") { digitalWrite(6,LOW); //the green LED goes out } message=""; } } |
We are going to create a mobile application named ‘allumer_leds_arduino’ with App Inventor which allows LEDs to be lit.
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: