Now, we are all set to design a robot which can easily be controlled from your mobile phones using the application named 'Dabble'.
Understanding the circuit and its components:Component 1: HC-05 Bluetooth ModuleHC-05 module operates using the Serial Port Protocol (SPP).
Pin 1:Enable / Key
This pin is used to toggle between Data Mode (set low) and AT command mode (set high). By default it is in Data mode. The HC-05 has two operating modes, one is the Data mode in which it can send and receive data from other Bluetooth devices and the other is the AT Command mode where the default device settings can be changed.
Pin 2:Vcc
Powers the module (connected to +5V Supply voltage)
Pin 3:Ground
Ground pin
Pin 4:TX – Transmitter
Transmits Serial Data. Everything received via Bluetooth will be given out by this pin as serial data.
Pin 5:RX – Receiver
Receive Serial Data. Every serial data given to this pin will be broadcasted via Bluetooth
Pin 6:State
The state pin is connected to on board LED, it can be used as a feedback to check if Bluetooth is working properly.
Pin 7:LED
Indicates the status of Module:
Blink once in 2 sec: Module is in the Command Mode
Repeated Blinking: Waiting for connection in Data Mode
Blink twice in 1 sec: Connection successful in Data Mode
Pin 8:Button
Used to control the Key/Enable pin to toggle between Data and command Mode
As soon as the module is powered you should be able to discover the Bluetooth device as “HC-05” then connect with it using the default password 1234 and start communicating with it.
Component 2 : L298N H-Bridge Motor DriverThe H-Bridge Motor Drivers L298N is used to drive DC motors as they require much more current that the arduino can provide.
The L298N motor controller follows the H-bridge configuration, which is handy when controlling the direction of rotation of a DC motor. The other benefit of using an H-bridge is that we can provide a separate power supply to the motors. This is very significant especially when using an Arduino board where the 5V power source is simply not enough for two DC motors.
We have Motor A and Motor B terminals. These connect to the microcontroller. Motor A connects to terminals 1 and 2 while Motor B connects to terminals 3 and 4.
L298N H-Bridge Motor Driver
If we want the left motor to rotate in one direction, we apply a high pulse to IN1 and a low pulse to IN2. To reverse the direction, reverse the pulses to IN1 and IN2. The same applies to the right motor.
If we want the left motor to rotate in one direction, we apply a high pulse to IN1 and a low pulse to IN2. To reverse the direction, reverse the pulses to IN1 and IN2. The same applies to the right motor.
Speed control is also possible with the L298N motor driver. All we need is feed PWM ( Pulse Width Modulation) signals to the motor enable pins. The speed of the motor will vary according to the width of the pulses. The wider the pulses, the faster the motor rotates. In Arduino this can be done using analogWrite(pinNumber, duration). Pins on Arduino with ‘~’ support PWM.
In order to use the 'Dabble' application you need to include the dabble library. The dabble library can be downloaded by clicking on the link shown below: https://thestempedia.com/wp-content/uploads/2018/12/Dabble.zip
To include this ZIP file, follow the steps shown below:
After selecting the option 'Add.ZIP Library' select the zip file from your computer to import.
HeaderCertain macros names depending upon which module you want to use need to be defined. There are unique define terms(macro) made for each module.
For example, to use the Gamepad module in the Arduino program, you have to define the following header:
#define CUSTOM_SETTINGS
#define INCLUDE_GAMEPAD_MODULE
Enabling Bluetooth CommunicationTo enable Bluetooth communication, you have to initialize serial communication using the following code:
Dabble.begin(Baud_Rate);
The baud rate is the rate at which information is transferred in a communication channel. Baud rate is commonly used when discussing electronics that use serial communication. In the serial port context, "9600 baud" means that the serial port is capable of transferring a maximum of 9600 bits per second.
Here Baud_Rate is the baud rate set for the Bluetooth module. For evive, we normally get 115200 baud rate modules and for other boards Baud_Rate is set to 9600.
Refreshing the dataTo refresh the data that the device gets from the Dabble app, you have to use the following line of code:
Dabble.processInput();
This function is included in the loop to process the data obtained from the mobile.
For details regarding other functions, kindly refer to:
https://thestempedia.com/docs/dabble/getting-started-with-dabble/
For more information regarding the HC-05 Bluetooth Module visit:
https://components101.com/wireless/hc-05-bluetooth-module
Note:
Dabble app for iOS devices supports only Bluetooth Low Energy, therefore you need to use BLE module HM-10 on your hardware while working with iOS devices.
Comments