Sunday, November 29, 2015

Password Access with Arduino

This post will show you how to make a pass code lock system using the Arduino Mega Board.
When you type the right code, an LED lights up an the servo moves to open a lock.


The materials that are needed for this project are:

one Arduino Mega (the arduino uno or duemilianove does not have enough digital pins for this project)
one LCD module
one Keypad
one Battery pack (or you can use the USB cable and PC power)
one 10K Ohm potentiometer
four 10K Ohm resistors
Breadboard
hookup wire
one servo

Step 1: Wire the LCD to the Arduino


The LCD module has 16 pins.
First of all, connect pins 1 and 16 of the LCD to the ground rail on the Breadboard
Then connect pins 2 and 15 of the LCD to the +5v rail on the breadboard
Now connect the ground rail(should be blue) of the breadboard to a ground pin on the Arduino;
Connect the +5v rail of the breadboard(this one is red) to one of the +5v pins on the Arduino board.

Now comes the contrast potentiometer which has to be connected to pin 3 of the LCD.
The potentiometer will have 3 pins. Take the middle pin and connect it to pin 3 of the arduino with hookup wire. Connect the othere two pins one to +5v and the other to GND(ground). The order does not matter.

Now let's do a test: power up the arduino. The LCD should light up. If it does then Great! If the LCD does not light up then turn off the power and check the wires.

Never change, move, or take out wires from the circuit board when the Arduino is powered up. You may permanently damage the Arduino.

If the light works rotate the potentiometer all the way to the right and all the way to the left until you see 2 rows of black squares. That's the contrast.

Now take out the power and let's hook up the LCD to the Arduino with the signal wires so we can display something on it.
Ready? Let's go!

Connect the pins as follows:

LCD Pin 4 --> Arduino Pin 2
LCD Pin 5 --> Arduino Pin 3
LCD Pin 6 --> Arduino Pin 4
LCD Pin 11 --> Arduino Pin 9
LCD Pin 12 --> Arduino Pin 10
LCD Pin 13 --> Arduino Pin 11
LCD Pin 14 --> Arduino Pin 12

And that should do it for the LCD circuit.

A test code for the the LCD: temporary.

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2,3,4,9,10,11,12);

void setup() 
{
    // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);
    // Print a message to the LCD.
    lcd.print("hello, world!");
}

void loop()
{
    // set the cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0):
     lcd.setCursor(0, 1);
   // print the number of seconds since reset:
   lcd.print(millis()/1000);
}

Copy and paste it in an arduino environment window, make sure you have the board and serial port set correct and click UPLOAD after you plug in the usb with the arduino.
You will see the TX and RX led's blinking, that means the code is going to the arduino.

Push the reset botton once on the arduino, tune the contrast, and you should see Hello World displayed.

Step 2: Wire the Keypad to the Arduino



Now that we're done with the LCD and we got it working, it's time to connect the keypad to the arduino. In my case, I used a 3x4 keypad that I had for some time.
If you have a keyboard that is made especially for connecting to an arduino, then it's easy. You just look at the datasheet for it and it tells you exactly how to hook it up.
If you have a keypad and you have no datasheet for it then hang on cause I was in the same situation.
Mine had on the back a diagram that shows you which pins are connected together when you press a certain key.
If you don't have that, you will have to use a multimeter and figure out which pins are connected together when you press each key.
To do that, take your multimeter and set it on continuity(the diode symbol).
Then put the test leads on pins 1 and 2 of the keypad. Now press every key until you get continuity.
Take paper and a pen and write down the key(ex:1, 2, #) and the two pins(ex: 6[1;2]).
Do so for every key until you get all of them figured out.

Make a table:
1=1+5
2=1+6
3=1+7
4=2+5
5=2+6
6=2+7
7=3+5
8=3+6
9=3+7
*=4+5
0=4+6
#=4+7

That is what I got.
Whatever you get, if you write down the keys in that order you will see the logic in it.
From my table I can see that the row pins are 1,2,3,4; and the column pins are 5,6,7.

Now plug the pins of the keypad in a breadboard and let's start connecting it.
Connect the pins for rows 2 and 3( in my case pins 2 and 3) to +5v through 10K Ohm resistors. Do the same with the pins for column 1 and 3 pins( in my case pins 5 and 7).

If you have an arduino mega, connect the keypad as follows:

Keypad pin row1--> arduino pin 25
Keypad pin row2--> arduino pin 24
Keypad pin row3--> arduino pin 23
Keypad pin row4--> arduino pin 22
Keypad pin column1 --> arduino pin 28
Keypad pin column2 --> arduino pin 27
Keypad pin column3 --> arduino pin 26

(The arduino uno does not have enough digital pins so it does not fit this project.)

That should do it for the keypad.

Step 3: Connecting the servo

It has 3 wires: Red, Yellow(or white or orange), and black.
Connect the red wire to +5v, the black wire to GND, and the middle wire to digital pin 8.
That's it for the servo.

Step 4: Preparations for coding

Before we put in the final code we have to make some modifications.


G o to the link above and download the libraries: keypad and password.
They are two files. take the files and put them in /Arduino/Libraries.

if the download does not work for bizarre reasons, go to:



Step 5:The code

Make sure you have all the wires in place and connect the USB cable.
Upload the following code to the arduino. Copy and paste it in the arduino window just like last time.

#include <Password.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <Servo.h>

Servo myservo;
int pos = 0;
LiquidCrystal lcd(2,3,4,9,10,11,12);
Password password = Password( "4321" );
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns

// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3',},
{'4','5','6',},
{'7','8','9',},
{'*','0',' ',}
};

// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {25, 24, 23, 22}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {28, 27, 26}; //connect to the column pinouts of the keypad
const int buttonPin = 7;
int buttonState = 0;

// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

#define ledPin 13

void setup()
{
   myservo.attach(8);
   pinMode(buttonPin, INPUT);
   lcd.begin(16, 2);
   digitalWrite(ledPin, LOW); // sets the LED on
   Serial.begin(9600);
   keypad.addEventListener(keypadEvent); //add an event listener    for this keypad
   keypad.setDebounceTime(250);
}

void loop()
{
   keypad.getKey();
   buttonState = digitalRead(buttonPin);
   if (buttonState == HIGH)
   {
      lcd.clear();
   }
}

//take care of some special events

void keypadEvent(KeypadEvent eKey)
{
  switch (keypad.getState())
  {
    case PRESSED:
    lcd.print(eKey);
    switch (eKey)
    {
      case ' ': guessPassword(); break;
      default:
      password.append(eKey);
    }
  }
}

void guessPassword()
{
   if (password.evaluate())
   {
       digitalWrite(ledPin,HIGH); //activates garaged door relay
       delay(500);
       for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
       { // in steps of 1 degree
          myservo.write(pos); // tell servo to go to position in variable 'pos'
          delay(3); // waits 15ms for the servo to reach the position
       }
       for(pos = 180; pos>=50; pos-=1) // goes from 180 degrees to 0 degrees
       {
  myservo.write(pos); // tell servo to go to position in variable 'pos'
  delay(3); // waits 15ms for the servo to reach the position
        }

digitalWrite(ledPin,LOW); //turns off door relay after .5 sec
lcd.print("VALID PASSWORD "); //
password.reset(); //resets password after correct entry
delay(600);
lcd.print("Welcome");
delay(2000);
lcd.clear();
    }
    else
    {
digitalWrite(ledPin,LOW);
lcd.print("INVALID PASSWORD ");
password.reset(); //resets password after INCORRECT entry
delay(600);
lcd.clear();
    }
}


Give it a test: type 4321 then press #.
You should see the message VALID PASSWORD Welcome

After that the LED on the arduino board will light up for a short time and the servo will move to open the lock. 

And that's it, you've got yourself a password access system.
Put it on your door, or make a safe, or make a..... whatever you want. Put it on your bird cage so no one can steal your expensive exotic talking parrots.
If you have any problems or questions regarding this, feel free to post a comment.I will answer as soon as I can.




Saturday, November 28, 2015

Arduino Bluetooth Car

Hello Everyone,

This is my another post in which I am going to illustrate you about the Arduino Bluetooth Car.Here,I will show you the video which will completely illustrate you about this so that you can easily understand the functioning of the Arduino Bluetooth Car.





The Code:

int motorPin1 = 10;
int motorPin2 = 11;
int motorPin3 = 8;
int motorPin4 = 9;

void setup()
{
   Serial.begin(9600);

   pinMode(motorPin1, OUTPUT);
   pinMode(motorPin2, OUTPUT);
   pinMode(motorPin3, OUTPUT);
   pinMode(motorPin4, OUTPUT);

   digitalWrite(motorPin1, 0);
   digitalWrite(motorPin2, 0);
   digitalWrite(motorPin3, 0);
   digitalWrite(motorPin4, 0);
}

void loop()
{
   char vDados = Serial.read();
   if (vDados == '1')
   {
      fFrente();
   }
   elseif (vDados == '2')
   {
      fFrente();
      fDireita();
   }
   elseif (vDados == '3')
   {
      fDireita();
   }
   elseif (vDados == '4')
   {
      fRe();
      fDireita();
   }
   elseif (vDados == '5')
   {
      fRe();
   }
   elseif (vDados == '6')
   {
      fRe();
      fEsquerda();
   }
   elseif (vDados == '7')
   {
     fEsquerda();
   }
   elseif (vDados == '8')
   {
     fFrente();
     fEsquerda();
   }
   delay(111);

   fParar();
}
void fParar()
{
   digitalWrite(motorPin1, 0);
   digitalWrite(motorPin2, 0);
   digitalWrite(motorPin3, 0);
   digitalWrite(motorPin4, 0);
}
void fFrente()
{
   digitalWrite(motorPin1, 1);
}
void fDireita()
{
  digitalWrite (motorPin3, 1);
}
void fRe()
{
  digitalWrite(motorPin2, 1);
}
void fEsquerda()
{
  digitalWrite (motorPin4, 1);
}

If you have any query regarding my post,you can comment your questions and suggestions in comment section.

Arduino Bluetooth and Ultrasonic Sensor

Hello again,

This is my another post in which I am going to cover Bluetooth and Ultrasonic sensor(HC-SR04).
Now the question arises,Why I have used these two.I made an RC 2 wheel car for my school project. It is  controlled with a free app via bluetooth. To make it "half robot", it has distance sensor, that measures distance. If the distance is (in my case) equal or lower than 10cm, the car stops and after 1.5s the person can control it again.

I will add code at the end of this post.You can go through that code.If you have any problem regarding this,you can comment on the comment section.

Step 1: THE HC-SR04 ULTRASONIC SENSOR

First of all,I am going to tell you about the HC_SR04 ultrasonic sensor.



This component is very simple, as it only has 4 pins.
First  and the last are power pins Vcc and GND. The middle ones are Trigger pin and Echo pin.
If you want to understand what these pins do, you must understand how this thing works.
So,this module is sending ultrasonic waves then these waves reflect from a surface and come back to the module.Arduino is triggering those waves on the trigger pin and than listening for the “echo”. Once it receives it, it calculates the distance based on the time spend waiting for the wave to come back. In the code, we are also going to change that value to cm, as it it easier to read.
The module will be connected to any I/O pins of the arduino.The trigger pin will be output and the echo pin will be input.

I will also describe how the code works in the programming step.

Step 2: PROGRAMMING THE ULTRASONIC SENSOR


int triggerPin = 7; //triggering on pin 7
int echoPin = 8;    //echo on pin 8
void setup()
{

  Serial.begin(9600);  //we'll start serial comunication, so we can see the distance on the serial monitor
  pinMode(triggerPin, OUTPUT); //defining pins
  pinMode(echoPin, INPUT);
}
void loop()
{
  int duration, distance;    //Adding duration and distance
  digitalWrite(triggerPin, HIGH); //triggering the wave(like blinking an LED)
  delay(10);
  digitalWrite(triggerPin, LOW);
  duration = pulseIn(echoPin, HIGH); //a special function for listening and waiting for the wave
  distance = (duration/2) / 29.1; //transforming the number to cm(if you want inches, you have to change the 29.1 with a suitable number
  Serial.print(distance);    //printing the numbers
  Serial.print("cm");       //and the unit
  Serial.println(" ");      //just printing to a new line

  //IF YOU WANT THE PORGRAM SPITTING OUT INFORMATION SLOWER, JUST UNCOMMENT(DELETE THE 2 //) THE NEXT LINE AND CHANGE THE NUMBER
  //delay(500);

}

Step 3: THE BLUETOOTH MODULE

First of all,I am going to tell you the Bluetooth module.Probably all Bluetooth modules have the same pin-out.
It has power pins Vcc and GND and communication pins RX and TX.
Now you can probably see, that this module connects to the RX and TX pins of a micro controller such as Arduino or a USB to serial converter.
This module works fully with 5V, so there is no problem connecting it to Arduino. All the pins are labeled on the back of the module.


You can see the connections in the images.

Step 4: PROGRAMMING THE BLUETOOTH MODULE

The code is made for turning LED on and OFF, but with the same method of "else if" statements seen in the code, you can do enything.

Another thing is that  When you have your bluetooth module connected to the TX and RX pins to the arduino, remember to pull them out every time you' re uploading the sketch or it will display an error like on the picture 2, than disconnect the RX and TX pins from the bluetooth module and upload the code again. Once the code is uploaded,connect the pins again.
After all that, you need to connect your phone to the bluetooth module. Power the arduino(and at the same time the bluetooth module) and find it in. Once you added the device, download this app for Android.I don't know if this works with Apple devices.

The app used is:https://play.google.com/store/apps/details?id=eu.jahnestacado.arduinorc, so it's called Arduino RC

int LED = 13; //led pin
int info = 0;//variable for the information comming from the bluetooth module
int state = 0;//simple variable for displaying the state
void setup()
{
  Serial.begin(9600); //making serial connection
  pinMode(LED, OUTPUT);    //defining LED pin
  digitalWrite(LED, LOW);  //once the programm starts, it's going to turn of the led, as it can be missleading.
}
void loop()
{
    if(Serial.available() > 0){  //if there is any information comming from the serial lines...
    info = Serial.read();
    state = 0;   //...than store it into the "info" variable
}
   if(info == '1')
   {                //if it gets the number 1(stored in the info variable...
    digitalWrite(LED, HIGH);    //it's gonna turn the led on(the on board one)
      if(state == 0)
      {              //if the flag is 0, than display that the LED is on and than set that value to 1
         Serial.println("LED ON");  //^^that will prevent the arduino sending words LED ON all the time, only when you change the state
         state = 1;
       }
    }
    else if(info == '0')
    {
       digitalWrite(LED, LOW);      //else, it's going to turn it off
       if(state == 0)
       {
         Serial.println("LED OFF");//display that the LED is off
          state = 1;
       }
     }
}

Step 5: TESTING THE BLUETOOTH!





Once you downloaded the app, run it and click connect to device. Choose your bluetooth module(my is the first one) and you will be taken to "the lobby". If you have noticed, this app is for RC(remote control) which is perfect for controllng a car. It has buttons or gyro sensoring. But what makes it not only for RC is the "TERMINAL MODE".There you can type in anything that will be sent to the arduino. In our case, If you send 1, the LED will come on, or if you type 0, the LED will go off.

Step 6: COMBINING DEVICES

Now, I've combine both of the codes, so you can turn on the LED remote and turn it off for 2s when the distance is less than 15cm.


All I did is that:
  • I combined all the int variables above the setups
  • I combine both setups into one
  • I named each loop of each code "bluetooth" and "sensor"
  • In the main loop I added those 2 loops
  • I added stopping function in the sensor part.

int triggerPin = 7; //triggering on pin 7
int echoPin = 8;    //echo on pin 8
int LED = 13; //led pin
int info = 0;//variable for the information comming from the bluetooth module
int state = 0;//simple variable for displaying the state

void setup()
{ //we will be combinig both setups from the codes
  
   Serial.begin(9600);  //we'll start serial comunication, so we can see the distance on the serial monitor
  pinMode(triggerPin, OUTPUT); //defining pins
  pinMode(echoPin, INPUT);
  pinMode(LED, OUTPUT);    //defining LED pin
  digitalWrite(LED, LOW);  //once the programm starts, it's going to turn of the led, as it can be missleading.
}
void loop()
{ //here we combine both codes to work in the loop
  bluetooth();
  sensor();
}
void bluetooth()
{ //loop from the bluetooth code is renamed to "bluetooth" void
  if(Serial.available() > 0)
  {  //if there is any information comming from the serial lines...
    info = Serial.read();   
    state = 0;   //...than store it into the "info" variable
  }
  if(info == '1')
  {                //if it gets the number 1(stored in the info variable...
    digitalWrite(LED, HIGH);    //it's gonna turn the led on(the on board one)
    if(state == 0)
    {              //if the flag is 0, than display that the LED is on and than set that value to 1
      Serial.println("LED ON");  //^^that will prevent the arduino sending words LED ON all the time, only when you change the state
      state = 1;
    }
   }
   else if(info == '0')
   {
    digitalWrite(LED, LOW);      //else, it's going to turn it off
    if(state == 0)
    {
      Serial.println("LED OFF");//display that the LED is off
      state = 1;
    }
  }
}

void sensor()
{ //loop from the sensor code is renamed to the "sensor" void
  
  int duration, distance;    //Adding duration and distance
  digitalWrite(triggerPin, HIGH); //triggering the wave(like blinking an LED)
  delay(10);
  digitalWrite(triggerPin, LOW);
  duration = pulseIn(echoPin, HIGH); //a special function for listening and waiting for the wave
  distance = (duration/2) / 29.1; //transforming the number to cm(if you want inches, you have to change the 29.1 with a suitable number
  Serial.print(distance);    //printing the numbers
  Serial.print("cm");       //and the unit
  Serial.println(" ");      //just printing to a new line
  
  //adding for mesuring distance where the led will turn off, even if we tell it to turn off when we chose so in the app
  
  if(distance <= 15)
  {  //if we get too close, the LED will turn off, that's the method with my RC car, if it gets too close, it turns off, but that will be in the next instructable :)
    digitalWrite(LED, LOW);
    Serial.println("TOO CLOSE!!!");
    delay(2000); //so the stopping is visabl
  }
}






Friday, November 27, 2015

Bluetooth Enabled Door Lock using Arduino

This is my new post which will explain a simple way to make a password protected door lock using your Arduino, and this lock can be unlocked by sending a four digit pin from your Android phone.


 

Step 1: Materials Required

  • Arduino 
  • Electric Door Strike
  • Bluetooth Module 
  • Power Supply (Required voltage and amperage differs among different door strikes/locks)
  • TIP120 Transistor
  • 1N4001 Diode
  • Hookup Wire
  • Solderless Breadboard
  • An Android phone (optional, considering that there are lots of devices you could use to send serial data to our bluetooth modem including Iphones, computers, and other Bluetooth devices).

Step 2: Description of Transistor:

First of all,we will start by focusing on one of the main components of the circuit which is named as transistor.
Our transistor will allow us to control a device that requires more current than our Arduino can supply,by sending the transistor different values. The type of transistor we are using (the TIP120) has a base, collector,and an emitter which are labeled here. We will send the signal from pin 9 on the Arduino to the base of the transistor,and depending on the value sent, current will increase or decrease.

Step 3: Assemble The Circuit

In the diagram,I have shown how the transistor is wired up in our circuit.
As you can see,we have a diode pointed away from ground that is connected to the collector of the transistor as well as the ground of the lock itself.This diode will protect our electronics from any back voltage that might be created when our lock is turned off.At this point you could set pin 9 to high or low to control the lock.

Step 4: Adding Bluetooth

Now,the another step that we will follow in this is to add a Bluetooth module to our project.Simply connect RX on the Bluetooth module to TX on our Arduino board,TX on the module is then connected to RX on the Arduino, GND is obviously connected to ground, and lastly VCC is connected to 3.3 volts or 5 volts depending on your Bluetooth module.

Step 5: Final Product (without the code)

Here is a look at what everything should look like. Its a bit difficult to see everything, but this is just the completed circuit on the breadboard.

Step 6: The Code

Basically the Arduino will check to see if anything is being received through serial. If it is, it will read those chars into an array and from that point verify that what was received matches the password we defined.Here,the password defined is ABCD.

int lock = 9;          //pin 9 on Arduino
char final[4];         //Characters the Arduino will receive
char correct[4] = {'A','B','C','D'};    //User-Defined Password
int pass_correct = 0;          //Does Password match, 0=false 1=true

void setup()
{
   pinMode(lock, OUTPUT);
   Serial.begin(9600);
   digitalWrite(lock, HIGH);  //By default,lock is active(locked)
}
void loop()
{
   while(Serial.available()) 
   {
      for(int i=0; i<4; i++)   //While data is available read 4 bytes
      {
         final[i] = Serial.read();  //Read 4 bytes into the array labled "final"
      }

     for(int i=0; i<4; i++)
     {
       if(final[i]==correct[i]) //Compare each char received to each car in our password in order
       {
         pass_correct = 1;   //If we compare two chars and they match, set the pass_correct variable to true(1)
       }
       else
       {
          pass_correct = 0;  //if the two compared chars do NOT match, set pass_correct variable to false(0)
          break;   //End loop and stop comparing chars
       }
     }
   }
   if(pass_correct==1)  //If all chars compared match, deactivate(unlock) the lock for 5 seconds
   {
      Serial.println("Unlocked");
      digitalWrite(lock, LOW);
      delay(5000);
      Serial.println("Locked");
      pass_correct = 0;
   }
   else
   {
      digitalWrite(lock, HIGH); //Else if there was not a complete match, keep the lock high(locked)
   }

  /* FOR TESTING

    Serial.print(final[0]);
    Serial.print(final[1]);
    Serial.print(final[2]);
    Serial.print(final[3]);
    Serial.print(" | ");
    Serial.print(correct[0]);
    Serial.print(correct[1]);
    Serial.print(correct[2]);
    Serial.print(correct[3]);
    Serial.print(" ");
    Serial.print(pass_correct);
    Serial.println("");
  */
  delay(500);
}

Step 7: Implementing Your Android Phone

On the app market, you can search for Bluetooth SPP (Serial Port Profile). There are many apps that have been made to send serial data through Bluetooth on your phone. Mine is called Bluetooth SPP just like 4 or 5 other apps that are similar and can be found by going to the link below. After you install one of these Bluetooth SPP apps, you can pair with your bluetooth modem connected to the Arduino. If it asks for a key, it will usually be by default "1234" (without quotes of course). After that, you should beable to send ABCD and the door strike will unlock for around 5 and 1/2 seconds, and then lock itself again. This concludes my tutorial on making a Bluetooth enabled door lock. If you have any questions or corrections for my project let me know!








Arduino Bluetooth Remote using LCD Display

Hello everyone,This is my another blog in which I made a simple but useful remote LCD.

Now you have question in your mind that what is basically all about?

In this,you can connect your phone to the Blutooth module of your Arduino,after that enter a text message  and it will appear on the Arduino’s LCD.


Step 1: Requirement of Materials: 

The various materials that are required to make this are: 

•A breadbord.
•A LCD display and potmeter
•Some wires.
•A mobile phone Android, Windows or Apple.


Step 2: Stick the parts in the breadboard.

In this step,you don’t have to do much. Just put the parts in the breadboard.


Step 3: Connect the Bluetooth module.

After putting the parts in the breadboard,you will need to connect the Bluetooth module to the Arduino. 

Module: Arduino
TX ====>pin1
RX ====>pin2
VCC ====>+5v
GND ===>GND


Step 4: Connect the LCD

Now you'll need to connect the LCD screen to the Arduino.
For this,you can see the image.
 


Turn on your Arduno and test if the LCD is working properly. You will see some black filled pixels on the screen.

Step 5: Upload the code.

Now you will need to upload the code to the Arduino.
Start up your Arduino Software and select the correct COM port and board.

Open the file added (Bluetooth Commander.ino) and press "upload"!

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
String inData;
void setup()
{
    Serial.begin(9600);       
    lcd.begin(16, 2);
    lcd.print("Welcome!");
    delay(3000);
    lcd.clear();
}
void loop()
{
  int i=0;
  char commandbuffer[100];
  if(Serial.available())
  {
     delay(100);
     while( Serial.available() && i< 99)
     {
        commandbuffer[i++] = Serial.read();
     }
     commandbuffer[i++]='\0';
  }

  if(i>0)
     Serial.println((char*)commandbuffer);
     lcd.print((char*)commandbuffer);
     delay(1000);
     lcd.clear();
}

Step 6: Set up your phone.

First you will need to pair to the Bluetooth network called HC-05 you can do this with password 1234.

Download from the phone store some app where you can send serial commands to the module.



I used Bluetooth Terminal for Android. When you have done that open the app click on connect to a device and tap on HC-05 it should connect now.

Step 7: Test it!

Now test it!
Just type some text into the commander and then the text will appear on the Arduino!



When you have a problem uploading the Arduino sketch try unplugging the Bluetooth module's TX and RX pins, upload then. 

Post your comments and suggestions in the comments section Below!!!








Monday, November 23, 2015

Arduino Bluetooth RC-Car

This project is about a car that is controlled via Bluetooth.


Step 1: Materials Requirement

Arduino UNO
•Arduino Motor Shield
HC-05 Bluetooth module
•Jumper Wires
•Robot Wheels
•Omni Wheel
•Base to mount the parts (Here,I have used wood plank 10.5cmx14cm)
•Relay sheild or my relay circuit
•Power source


Step 2: Assembling the components






Now that we have all the components we connect the motor shield to the Arduino.I did a small trick to connect the RX and TX pin to the motor shield because mine didn't have female pin headers. I took two small female pin headers and soldered to my motor shield.

Next we have to mount the Arduino to the base of the car then mount the motor sheild on top of it. Next mount the Bluetooth module on the base remembering the Vcc,GND,RX and TX pins by noting it down.

Next mount the omni wheel onto the base and the dc motor robot wheels too.
Then connect the dc motors to the M1 and M2 ports of the motor shield.

Thereafter connect the RX pin in the module to the TX pin of Arduino and TX pin of module to RX pin of Arduino.

Lastly connect the relay circuit i made to digital pin 6 so that we can switch on the front light via Bluetooth.

Step 3: Coding and the android apk
Before uploading the code remove the 5v or RX and TX pins from the arduino which is connected to the Bluetooth module because there would be problems in uploading the code if not.

Go to play store and download the "Arduino Bluetooth RC Car" apk or scan the Qr code to download easily and install it switch on the car and connect the module using 1234 as the password

//Arduino Bluetooth car
//Author: Manu Goswami
//Function:Controls car via Bluetooth

#include <AFMotor.h>

//creates two objects to control the terminal 1 and 2 of motor shield
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
char command;
const int FrontLed = 6;
void setup()
{    
  Serial.begin(38400);  //Set the baud rate to your Bluetooth module.
  // Front LEDs
  pinMode(FrontLed, OUTPUT);  // declare FrontRightLed as output
}
void loop(){
  if(Serial.available() > 0){
    command = Serial.read();
    Stop(); //initialize with motors stoped
    //Change pin mode only if new command is different from previous.
    //Serial.println(command);
    switch(command){
    case 'F':
      forward();
      break;
    case 'B':
       back();
      break;
    case 'L':
      left();
      break;
    case 'R':
      right();
      break;
      case 'W':
      digitalWrite(6,HIGH);
      break;
      case 'w':
      digitalWrite(6,LOW);
      break;
     }
  }
}
void forward()
{
  motor1.setSpeed(90); //Define maximum velocity
  motor1.run(FORWARD); //rotate the motor clockwise
  motor2.setSpeed(90); //Define maximum velocity
  motor2.run(FORWARD); //rotate the motor clockwise
}
void back()
{
  motor1.setSpeed(90);
  motor1.run(BACKWARD); //rotate the motor counterclockwise
  motor2.setSpeed(90);
  motor2.run(BACKWARD); //rotate the motor counterclockwise
}
void left()
{
  motor1.setSpeed(90); //Define maximum velocity
  motor1.run(FORWARD); //rotate the motor clockwise
  motor2.setSpeed(0);
  motor2.run(RELEASE); //turn motor2 off
}
void right()
{
  motor1.setSpeed(0);
  motor1.run(RELEASE); //turn motor1 off
  motor2.setSpeed(90); //Define maximum velocity
  motor2.run(FORWARD); //rotate the motor clockwise
}
void Stop()
{
  motor1.setSpeed(0);
  motor2.run(RELEASE); //turn motor1 off
  motor2.setSpeed(0);
  motor2.run(RELEASE); //turn motor2 off
}