CommanDuinoBT is an application that can control over Bluetooth the Arduino Uno, Mini, Pro and Nano shields using a mobile device. This is achieved because the bluetooth that is in the mobile device sends signs to the bluetooth module that is connected to the Arduino.
This application avoids to write many lines of code because from the mobile device is possible to configure the pins as either inputs or outputs. Similarly, from this app we can change the state of the pins to HIGH or LOW. Besides, you can generate a PWM signal to the pins that support this type of signal.
Here you can download the application from the Play Store.
Or scan it from your phone:
Before you start using the application, it is necessary to connect the Bluetooth module to Arduino. Before that, we must first configure this module as a slave device. For the configuration you can check this tutorial if you have a master/slave module. Otherwise, if you have a slave module, you can check out this page: Configuring a slave bluetooth module.
Or scan it from your phone:
Once you have configured the bluetooth module, connect it to the Arduino as shown in the circuit.
Needed hardware
- Arduino Uno
- 2 resistors of 220 Ω
- 2 LEDs
- Slave Bluetooth Module
- Breadboard
- Cables
Circuit
After implementing the circuit, download and install the CommanDuino.h library. Here you can download the CommanDuino.h library and if you want to know how to install it, please review the tutorial How to install an Arduino library?
Then, go to the file menu and open the example simple from the CommanDuino library and load it into Arduino. If the circuit is implemented correctly, you can see that the LED on the module flashes quickly, which means it is not paired with any other bluetooth device.
Next, turn on the bluetooth in your mobile and link it with the bluetooth module (if it is not linked), to do this seek the bluetooth module with which you want to link and enter the password. The password is 4 digits and the default is 1111 or 1234. However, to configure the bluetooth module and change its settings, check out the tutorials: Configuring a slave bluetooth module or configuring a master/slave bluetooth module as slave.
After linking, open the application and press the CONNECT button, it will show a list with the available devices, look for the bluetooth module and click on it to pair it with your mobile.
At this point, you can see that the LED blinks more slowly or does not blink, indicating that it has been paired with your mobile device. Similarly, in the application an Arduino board is displayed, which indicates the same, your mobile is already paired with Arduino.
In the code you can see that the CommanDuino.h library is incuded; also, before the setup() function, you must create an instance of CommanDuino class, that allow to use the library functions. This library has 3 functions, CDsetting(), command() and CDreceiveChar().
Within the setup function you must call the CDsetting() function to configure the bluetooth communication. Digital pins 2 and 3 are used for the communication.
Within the loop, it is necessary to call the command() function, which allows to command or control the Arduino board, in other words, this function perform the instructions received by bluetooth.
Within the loop, it is necessary to call the command() function, which allows to command or control the Arduino board, in other words, this function perform the instructions received by bluetooth.
Finally, the CDreceiveChar() function allows to receive by bluetooth one character, char type (obviously). In this example this function is not used because is not necessary. However, in this tutorial you can see an example of the usage of this function.
Code
// library used for serial communication
#include <SoftwareSerial.h>
#include <CommanDuino.h> // library used to control Arduino board
// using the CommanDuino app
// It should be created an instance of the class CommanDuino,
// called App, to call the constructor. The constructor is
// a function that set the pins for the bluetooth communication.
// In this case the digitals pins 2 y 3.
CommanDuino App;
void setup(){
App.CDsetting(); // set the data rate
} // for the software serial port
void loop(){
App.command(); // allows to command the Arduino board
}
///////////////////////////////////////////////////////
Well, the app is very intuitive, easy to use and works as follows:
If you want to set up a pin, simply select it and a options dialog will open. There, you can choose if you want an input or output pin.
When selecting a pin, this will turn yellow. After choosing the settings and pressing the ok button, the button will change color.
If you set a pin as input, it will turn blue; if the pin is configured as output, you must choose whether you want to have a digital output or a PWM waveform (if the pin supports PWM signals). If you chose a digital output with the HIGH state, it will turn red; if placed in LOW, it will turn gray and if configured as PWM, it will turn red in the form of a square wave.
Additionally, there is the Send Data option, with which you can send a character to Aduino. This is useful if you want the Arduino to perform a task when receiving a certain character.
In this simple example, this application is used to turn on and off the LED that is connected to digital pin 13. Likewise with the green LED that is connected to pin 11, but this time using a PWM signal, you could change the LED brightness changing the duty cycle of the PWM signal.
With this simple example you have learned how to use the CommanduinoBT app. You can connect other devices, sensors or motors to Arduino and control them from your mobile.
To better understand the use of the CDreceiveChar() function, check out the tutorial: selecting melodies over Bluetooth.
That's all, if you have any questions or comments let them in the comment box below.
That's all, if you have any questions or comments let them in the comment box below.
No hay comentarios:
Publicar un comentario