
In this tutorial we will see how to turn on the smartphone torch using the Arduino board.
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.
Test plate
Connecting wires
For the assembly you can see the following article:
https://www.robotique.tech/robotics/send-a-message-from-arduino-to-smartphone/
Here is the program that allows you to connect the Arduino board to the smartphone and send a message containing the order to turn on the smartphone torch.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include <SoftwareSerial.h> const int btnPin = A0; //the push button is connected to pin A0 of the Adruino int btnVal = 0; SoftwareSerial hc06(2,3); int allumer=0; void setup(){ pinMode(btnPin,INPUT_PULLUP); hc06.begin(9600); } void loop(){ btnVal=analogRead(btnPin); if(btnVal<200) // We press the push button {if (allumer==0){ hc06.print("allumer"); //send message to smartphone allumer=1; } else{ hc06.print("eteindre"); //send message to smartphone allumer=0; }delay(500); } } |
We are going to create a mobile application named ‘allumer_torche_arduino’ with App Inventor which allows you to receive a message from 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: