blogs

My First Arduino Project

2022-Jun-22

So before getting through how I built my first Arduino project you must have checked out the LED blink project. The basic thing that you need to know about arduino and its programming can be understood from the blink project. Here in this section it’s going to be all about how an app controlled bot could be made using an arduino. 

Before getting started let us be familiar with the components that are to be used for this project:


  1. Arduino UNO


  2. Bluetooth Module HC05


  3. BO  Motor



  4. L298N  Motor Driver

  5. Wheel

  6. Castor Wheel


  7. Jumper Cables



  8. Power Supply


As it has been clear by now that arduino is the primary processor of most of the electronic projects. For this project Arduino receives input bluetooth signal from the bluetooth module then sends the signal accordingly to the motor via a motor driver. The motor driver then controls the direction of the motor based on the signals received.


So, Let us begin our project.

Step 1: Assemble all the components as required. Manage a power source of 12V either from an adapter or by using a battery. Let us work with a 3 cell 2200mAh Lipo battery for this time.



Step 2: Connect the two motor cables of each motor into each side of the L298N motor driver. Screw it properly so that the connection doesn’t get loose and create a problem later on. 

Along with motor connection, connect the positive terminal of the battery at the 12V receiving terminal of the motor driver as indicated in the figure. Connect the negative end at the ground terminal and finally connect a wire at the 5V supply terminal in the motor driver which is later used to power the arduino.



Step 3: Upon completing the connection of the motor driver lets get into the connection of the Arduino board. Since we are using two motors, we need to assign two pins for each motor to control their direction. So let’s use a total of four pins to provide output signal from the arduino to the motor driver. For this case we will be using the pins number 2, 3, 4 and 5.

Each of the mentioned pins are assigned as OUTPUT in the provided code. 


Code:

void setup
{

pinMode (2,OUTPUT);

pinMode (3,OUTPUT);

pinMode (4,OUTPUT);

pinMode (5,OUTPUT);

}


Step 4: Now that the pins are assigned we connect the 2, 3, 4 and 5 number of arduino with the 4 terminals on the L298N motor driver using a Male to Female Jumper cable as shown. 



Note: Image shows the connection at pins 5, 6, 8 and 10 but we will use pin numbers 2, 3, 4 and 5 


Step 5: So, the setup for the output part has been done. Now moving on to the input setup, here we provide input to the arduino using a bluetooth module. The connection of the bluetooth module is done as shown in the image.

Here the bluetooth module that we are using is the HC05 model. It consists of 4 pins where the first two pins are the Receiving and Transmitting terminal commonly known as Rx and Tx. The remaining two pins are labeled vcc and gnd which are used to supply 5V input to the component and a negative ground voltage.





Step 6: Here the Rx of the bluetooth module is connected to the Tx of the Arduino board (pin number 1) and the Tx of the module is connected to the Rx of the Arduino Board (pin number 2). 

Step 7: Now set up the power supply for Arduino Connect the vin pin of arduino to the 5V output that we had taken out from the motor driver as learned in step 2. Then connect the ground terminal in the arduino board to any of the common ground available in the circuit.



Step 8: Finally the circuit has been completed! But before you connect it to a battery lets start the coding process. The entire set of code is shown in the image.


Well we have already defined the 4 codes to work as output so now let’s get to the working part. Let's make four different functions with each function to show the working of the motor to run in one of either direction front, back, left or right. 


Here each of the functions works to drive the motor in one of 4 different directions along with a function to stop the motor. Since we are working inside the void loop of arduino, which is an infinite loop, we need to stop the bot at times. 


Step 9: Upon coding for the motor we now will move on to the part where the arduino receives the input from the bluetooth module. A switch case statement is used to determine which of the buttons is pressed so that the arduino can provide the respective signal to drive the motor. 

Bluetooth module receives character from any android based device, that sends the character to control the direction of the motor. Upon receiving any specific character it then sends it to the arduino which then processes it based on the received character and aligns it to the respective direction function.


Here the code Serial.available() refers to checking if any input is available in the arduino. Likewise Serial.read is used to copy whatever serial data has been obtained in the arduino. In this case input data are obtained as characters from the bluetooth module which are sent by any android based device connected to the module.


Step 10: It seems that everything is now set to run our app controlled bot. Make sure you compile your code to check any sorts of errors in the program. Now using an USB 2.0 cable upload the code into the arduino. 



Now that everything is set up, see if the bluetooth module is working. You will see a blink in the module. Pair your device with the HC05 bluetooth module. The password is usually 0000 or 1234. Then open your bluetooth car app, connect to your car and enjoy your very first arduino project: An App Controlled Bot.