Showing posts with label buy arduino chennai. Show all posts
Showing posts with label buy arduino chennai. Show all posts

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 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
}

Thursday, November 19, 2015

Arduino Bluetooth Controller

Hello All!

This is my another blog in which I am going to show you how to connect an Arduino to your android phone via Bluetooth and then use voice commands to control high voltage devices using relays.
Electricity is dangerous so you have to be very careful in this…

Step 1: Materials that are required 

The various materials that are required in this project are : 
•Relay Module
•Wires
•LED's
•A Lamp
•Android Phone with Bluetooth
•Electrical Tape
•Wire Strippers (or knife)

Materials Required
Step 2: Relay Test

First of all we have to check if the relay is switching or not.
You can Wire up the relay as shown in the diagram, make sure that the JD-VCC and VCC pins are bridged if you are powering the relay from your arduino. If they are not bridged you will see the LED turning on and off every 2 seconds but there will not be the clicking sound of the relay switching.



Code:

#define relay 2    //attaches the relay to pin 2
void setup()
{
  pinMode(relay, OUTPUT);    //sets the relay as an output
}
void loop()
{
  digitalWrite(relay, HIGH);     //relay open
  delay(2000);                           //wait 2 seconds
  digitalWrite(relay, LOW);     //relay closed
  delay(2000);                          //wait 2 seconds
}

Step 3: Bluetooth Test

First of all wire up the circuit as shown in the images.Here,I have used a breadboard and made one rail positive and one negative.One thing that I found in this that the TXD and RXD pins on the Bluetooth module don’t work when connected to the same pins on the arduino itself.


The TXD pin on the Bluetooth module I have connected to the RXD pin on the arduino (pin 0), and the RXD pin on the Bluetooth module is connected to the TXD pin on the arduino (pin 1). The Bluetooth Module will run off 3.3v but the relay needs 5v to work, hence I have used 5 volts on the arduino.
Now,I am showing you the code that I have written for this 2 switch relay. 

/*
------------------------------------------------------------------------
                            InfidelFish
------------------------------------------------------------------------
*/

String voice;
#define relay1 2    //Connect relay1 to pin 2
#define relay2 3    //Connect relay2 to pin 3
void setup()
{
  Serial.begin(9600);            //Set rate for communicating with phone
  pinMode(relay1, OUTPUT);       //Set relay1 as an output
  pinMode(relay2, OUTPUT);       //Set relay2 as an output
  digitalWrite(relay1, LOW);     //Switch relay1 off
  digitalWrite(relay2, LOW);     //Swtich relay2 off
}
void loop()
{
  while(Serial.available())    //Check if there are available bytes to read
  {
    delay(10);                 //Delay to make it stable
    char c = Serial.read();    //Conduct a serial read
    if (c == '#'){
      break;                   //Stop the loop once # is detected after a word
    }
    voice += c;                //Means voice = voice + c
  }
    if (voice.length() >0)
    {
      Serial.println(voice);
      if(voice == "*switch on"){
        switchon();
      }               //Initiate function switchon if voice is switch on
      else if(voice == "*switch off"){
        switchoff();
      }               //Initiate function switchoff if voice is switch off
      else if(voice == "*lamp on"){   
//You can replace 'lamp on' with anything you want...same applies to others
        digitalWrite(relay1, HIGH);
      }
      else if(voice == "*lamp off"){
        digitalWrite(relay1, LOW);
      }
      else if(voice == "*kettle on"){
        digitalWrite(relay2, HIGH);
      }
      else if(voice == "*kettle off"){
        digitalWrite(relay2, LOW);
      }
      voice="";
    }
}
void switchon()               //Function for turning on relays
{
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
}
void switchoff()              //Function for turning on relays
{
  digitalWrite(relay1, LOW);
  digitalWrite(relay2, LOW);
}

/*

You can add any function you want depending on how many devices you have hooked up.
For example you could have a function called 'cinema' which would dim the lights and
turn the TV on. You can have as many as you have pins on your arduino.
For my relay 'LOW' turns off and 'HIGH' turns on
The outline to follow is this:
   
   void ......()
   {
     digitalWrite(...., LOW/HIGH);
     digitalWrite(...., LOW/HIGH);
   }
   
*/

When you will upload the code to your Arduino,you have to be make sure that you unplug the pins 0 and 1 otherwise you will probably get an error like this:

avrdude: stk500_getsync(): not in sync: resp=0x00

Another thing that you have to do is to download the app on your android phone.You can download it from Google Playstore

https://play.google.com/store/apps/details?id=robotspace.simplelabs.amr_voice&hl=en

Connect it to the Bluetooth module it will probably be called something like ‘HC-06’.
The first time it will ask you for a password.Most of the times password is 1234.

Once you have connected say the commands you have chosen in the code and hopefully the relay will switch on and off!

Step 4: Adding the Appliances

The first thing you have to do is to find an old lamp or any other appliances as we have to cut the lead in this.
Now,remove the outer rubber sleeving but just make sure not to cut the sleeving of the wires inside,we don’t want any live wire visible.

Next cut the positive wire (the red one) and remove a few millimetres of sleeving on each end. Insert the exposed wire in the correct ports of the relay as shown in the diagram and pictures above. MAKE SURE THERE IS NO WIRE VISIBLE! For safety wrap the wires in electrical tape, and cover any of the places that could be live on the relay, such as the screws.

Once this is done we are ready to power on the lamp and test the system.



Step 5: Conclusion

I just hope my blog will be informative and you will be are able to make that.

The possibilities for this I feel are endless you can add loads of devices and then create functions in order to control several at once.
Here is a video of the lamp working: