Showing posts with label buy arduino kit. Show all posts
Showing posts with label buy arduino kit. 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 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!!!








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:










Tuesday, November 17, 2015

Rover 5 using Xbee and Arduino Mega 2560

Hello everyone, In this post you are going to learn how to work with Dagu Rover 5.I am a big enthusiast for the sharing of knowledge and get lot of information from the internet,so here is me sharing my  collective knowledge to all of you.

I have shown you the image of Dagu rover 5 arduino uno mega 2560 Xbee by which you can get some sort of idea of it.
The various items needed for this project are
Dagu Rover 5  in which I have the 4 motors/ 4 encoder model
rover 5 motor driver Board
arduino uno mega 2560
Xbees ,here I use XBee Series 1
XBee Explorer Dongle v2
XBee Explorer Regulated - plus pins and soldering stuff
Batteries - 6AA and 5v usb bank.
male to female jumper wire
Pololu RP5/Rover 5 Expansion Plate RRC07B (Wide) Transparent Clear.
Step 1: Cut a hole for the motor wire to come through
To attach the Pololu RP5/Rover 5 Expansion Plate to rover you have to cut out a hole in the center for the wires from the motors and encoders to come through. After that, cut some to plastic bit with a pointed knife. then pull the wires through, this will allow for the plate to be mounted flat.

Step 2: Wiring Part A

First of all,you have to attach the motor and encoder wires to the rover 5 motor driver Board. I have shown the image above of how i wired it but it doesn't show how I attach the motor and encoder wires. To wire these, draw them back to the motor and then plug them into the right port. For the encoder wires you have to plug them into bottom row of the pins label "INT ENC1 ENC2" . From left to right it is Red - Yellow - White - Black.

Step 3: Wiring Part B


Above shown image shows you how I wire the rover 5 motor driver Board to the arduino uno mega 2560.
Now, I am showing you some arduino codes of where to wires go.

#define encoderA 2
#define encoderB 3           // Only use one interrupt in this example
#define encoderC 19
#define encoderD 18        // Only use one interrupt in this example

volatile int Lcount;
volatile int Rcount;

int Lcountsaved;
int Rcountsaved;

int speedch1 = 9; // left front
int speedch2 = 10; // left back
int speedch3 = 11; // right front
int speedch4 = 12; // right back

// direction pins 

int dirch1 = 44; // left front
int dirch2 = 45; // left back
int dirch3 = 42; // right front
int dirch4 = 43; // right back
int curch1 = A1; // left front
int curch2 = A2; // left back
int curch3 = A3; // right front

int curch4 = A4; // right back

Here, I have included the cur(current) pins and I have used a breadboard for a common ground, this may be wrong but it works best for me.

Step 4: Platform to hold batteries


After wiring the lower platform, there is no room for batteries. Then I created one for mine out of paper mache and wire.That is not very good, possible alternatives 3d print or shop bought box that fits.Then we have to attach the batteries via velcro.


Step 5: Coding basic

Now, I am presenting you the basic code for all four motor to spin for 5 seconds, and here,there are no encoder or xbee in this code.

//ROBOT CAR CODE 001

int speedch1 = 9;
int speedch2 = 10;
int speedch3 = 11;
int speedch4 = 12;
int dirch1 = 44;
int dirch2 = 45;
int dirch3 = 42;
int dirch4 = 43;
int curch1 = A1;
int curch2 = A2;
int curch3 = A3;
int curch4 = A4;
 void setup() {                
  // initialize the digital pin as an output.
pinMode(dirch1,OUTPUT);
pinMode(dirch2,OUTPUT);
pinMode(dirch3,OUTPUT);
pinMode(dirch4,OUTPUT);
pinMode(speedch1,OUTPUT);
pinMode(speedch2,OUTPUT);
pinMode(speedch3,OUTPUT);
pinMode(speedch4,OUTPUT);
 }
 
// the loop routine runs over and over again forever:
void loop() {
   delay(2000);
   digitalWrite(dirch1,LOW); // direction motor spins 
   digitalWrite(dirch2,HIGH); // 1 and 2 are on the same side but fight against each other.
   digitalWrite(dirch3,LOW);
   digitalWrite(dirch4,HIGH);
   analogWrite(speedch1,200); // speed PWM 0 - 255 
   analogWrite(speedch2,200);
   analogWrite(speedch3,200);
   analogWrite(speedch4,200);
   
   delay(5000);//how long the motors run
   
   analogWrite(speedch1,0); // stop
   analogWrite(speedch2,0);
   analogWrite(speedch3,0);
   analogWrite(speedch4,0);
}

Step 6: Encoders code
Now, I am presenting a easy code for the left encoder.After working for many hours, I       found a linear encoder code that works best for our project.This code will spin the left      motors until the encoder(count) reaches 500.It also print it to the serial monitor.It is same for the other side just have to change the pins and names.
// Interrupt information // pins may be different on uno<br>   // 0 on pin 2
// 1 on pin 3


#define encoderA 2
#define encoderB 3 // Only use one interrupt in this example
volatile int count;


int speedch1 = 9; // left front
int speedch2 = 10; // left back
int speedch3 = 11; // right front
int speedch4 = 12; // right back
// direction pins 
int dirch1 = 44; // left front
int dirch2 = 45; // left back
int dirch3 = 42; // right front
int dirch4 = 43; // right back


int curch1 = A1; // left front
int curch2 = A2; // left back
int curch3 = A3; // right front
int curch4 = A4; // right back
int TIME; //time the command is for
int SPEED;// 0 - 255 motor speed


void setup()
{
Serial.begin(9600);
count=0;
pinMode(dirch1,OUTPUT);
pinMode(dirch2,OUTPUT);
pinMode(dirch3,OUTPUT);
pinMode(dirch4,OUTPUT);


pinMode(speedch1,OUTPUT);
pinMode(speedch2,OUTPUT);
pinMode(speedch3,OUTPUT);
pinMode(speedch4,OUTPUT);
pinMode(encoderA, INPUT);
pinMode(encoderB, INPUT); attachInterrupt(0, handleEncoder, CHANGE);

}

void loop()
{
 delay(1000);
  (SPEED = 200);
   forward();
  if (count > 10) Serial.println(count); 
}

void handleEncoder()
{
if(digitalRead(encoderA) == digitalRead(encoderB))
{ count++;
}
else
{ count--;
}


}
void forward()
{  
     
   digitalWrite(dirch1,LOW);
   digitalWrite(dirch2,HIGH); 
   analogWrite(speedch1,SPEED);
   analogWrite(speedch2,SPEED);
   
   if (count > 500){ 
   
   analogWrite(speedch1,0);
   analogWrite(speedch2,0);
  }
}
Step 7: Xbee
We will need Xbees to solder some pins into it. First of all,take Xbees of your choice and program them to take to each other on the same channel using XBee Explorer Dongle v2 and XCTU.Choose the serial port for the Xbee on the Arduino 2 or 3 and after that you have to run these easy receiving code.This code will turn led 13 on the board on when it  receives processing in the next step.
int incomingByte = 0;   // for incoming serial data

int led = 13;

  void setup() {
  Serial2.begin(9600);  // change to the serial port /2/3
  pinMode(led, OUTPUT);        
}

void loop() {

      // send data only when you receive data:
        if (Serial2.available() > 0)
        {
         // read the incoming byte:
            incomingByte = Serial2.read();

            if(incomingByte == 49) digitalWrite(led, HIGH);
            else if(incomingByte == 50) digitalWrite(led,LOW);
         }
}

Step 8: Processing
This is the another step.Firstly,import processing.serial. plug you other xbee to the XBee Explorer Dongle v2 and into your computer,here I found a USB extensionlead.Then,you  have to button it now should turn on led 13 on the board.I have written this code in pick    the port to which you are attach too and Clicking and holding the mouse v2.1.1.
import processing.serial.*;

Serial myPort;  // Create object from Serial class

void setup(){
  size(640, 360);
  println(Serial.list());// This will list serial ports
  String portName = Serial.list()[5];// port number
  myPort = new Serial(this, portName, 9600);
}

void draw()
{
  if (mousePressed) {
    myPort.write(49);
  } else {
    myPort.write(50);
  }
}
Step 9: Final code

Now,I am presenting you the final code for the arduino uno mega2560.Here,I have          created the subcommands so that it will be easy for all of you to understand.
//ROBOT CAR CODE 004
// commands
// forward()
// backward()
// rotate_left()
// rotate_right()

//notes 
//   FULL 360 rotate
//  (TIME = 12000);   //delay time
//  (SPEED = 200);   //speed 0-255
//  rotate_right(); 
int incomingByte = 0; //  for incoming serial data 
//speed pins 0 - 255 

#define encoderA 2
#define encoderB 3 // Only use one interrupt in this example
#define encoderC 19
#define encoderD 18 // Only use one interrupt in this example
volatile int Lcount;
volatile int Rcount;
int Lcountsaved;
int Rcountsaved;

int speedch1 = 9; // left front
int speedch2 = 10; // left back
int speedch3 = 11; // right front
int speedch4 = 12; // right back
// direction pins 
int dirch1 = 44; // left front
int dirch2 = 45; // left back
int dirch3 = 42; // right front
int dirch4 = 43; // right back

int curch1 = A1; // left front
int curch2 = A2; // left back
int curch3 = A3; // right front
int curch4 = A4; // right back
int TIME; //time the command is for
int SPEED;// 0 - 255 motor speed

int count;
int check1; //see if subcomand has run
int check2; //see if subcomand has run
int check3; //see if subcomand has run
int check4; //see if subcomand has run
int check5; //see if subcomand has run

void setup() 
{                
Lcount=0;
Rcount=0;

// initialize the digital pin as an output.
pinMode(dirch1,OUTPUT);
pinMode(dirch2,OUTPUT);
pinMode(dirch3,OUTPUT);
pinMode(dirch4,OUTPUT);

pinMode(speedch1,OUTPUT);
pinMode(speedch2,OUTPUT);
pinMode(speedch3,OUTPUT);
pinMode(speedch4,OUTPUT);

pinMode(encoderA, INPUT);
pinMode(encoderB, INPUT); attachInterrupt(0, LhandleEncoder, CHANGE);
pinMode(encoderC, INPUT);
pinMode(encoderD, INPUT); attachInterrupt(5, RhandleEncoder, CHANGE);

Serial2.begin(9600);
Serial.begin(9600);

analogWrite(speedch1,0);// stop all
analogWrite(speedch2,0);// stop all
analogWrite(speedch3,0);// stop all
analogWrite(speedch4,0);// stop all

count = 0;
(SPEED = 200);

}

// the loop routine runs over and over again forever:
void loop()
{
   if (Serial2.available() > 0) {
    // read the incoming byte:
   incomingByte = Serial2.read();               
  }
  
  if(incomingByte == 10 && check1 == 0) forward();
  else if(incomingByte == 11 && check2 == 0) rotate_right();
  else if(incomingByte == 12 && check3 == 0) backward();
  else if(incomingByte == 13 && check4 == 0) rotate_left();
  else if(incomingByte == 14 && check5 == 0) pause();

// if(incomingByte == 16){
// if (Lcount != Lcountsaved && Rcount != Rcountsaved)
 Serial2.print(Lcount,DEC);//send encoder data
 Serial2.print(",");
 Serial2.print(Rcount,DEC);
 Serial2.print(",");
 Serial2.println();
 
 incomingByte = 1;
// Lcountsaved = Lcount;
 //Rcountsaved = Rcount;
// }
 }
 
  void LhandleEncoder()
{
if(digitalRead(encoderA) == digitalRead(encoderB))
{ Lcount++;
}
else
{ Lcount--;
}
}

void RhandleEncoder()
{
if(digitalRead(encoderC) == digitalRead(encoderD))
{ Rcount++;
}
else
{ Rcount--;
}
}

void forward()
{             
   check2 = 0;
   check3 = 0;
   check4 = 0;
   check5 = 0;
   
   analogWrite(speedch1,0);
   analogWrite(speedch2,0);
   analogWrite(speedch3,0);
   analogWrite(speedch4,0);
 
   delay(100);
 
   digitalWrite(dirch1,LOW);
   digitalWrite(dirch2,HIGH); 
   digitalWrite(dirch3,LOW);
   digitalWrite(dirch4,HIGH);
   analogWrite(speedch1,SPEED);
   analogWrite(speedch2,SPEED);
   analogWrite(speedch3,SPEED);
   analogWrite(speedch4,SPEED);
   
   check1 = 1;
}

void backward()
{  
   check1 = 0; 
   check2 = 0; 
   check4 = 0;
   check5 = 0;
   
   analogWrite(speedch1,0);
   analogWrite(speedch2,0);
   analogWrite(speedch3,0);
   analogWrite(speedch4,0);
   
   delay(100);
 
   digitalWrite(dirch1,HIGH);
   digitalWrite(dirch2,LOW); 
   digitalWrite(dirch3,HIGH);
   digitalWrite(dirch4,LOW);
   analogWrite(speedch1,SPEED);
   analogWrite(speedch2,SPEED);
   analogWrite(speedch3,SPEED);
   analogWrite(speedch4,SPEED);

   check3 = 1;
  
}
void rotate_right()
{  
   check1 = 0;
   check3 = 0;
   check4 = 0;
   check5 = 0;
   
   analogWrite(speedch1,0);
   analogWrite(speedch2,0);
   analogWrite(speedch3,0);
   analogWrite(speedch4,0);
   
   delay(100); //wait to stop
   
   digitalWrite(dirch1,LOW);
   digitalWrite(dirch2,HIGH); 
   digitalWrite(dirch3,HIGH);
   digitalWrite(dirch4,LOW);
   analogWrite(speedch1,SPEED);
   analogWrite(speedch2,SPEED);
   analogWrite(speedch3,SPEED);
   analogWrite(speedch4,SPEED);
   
   check2 = 1;
}
void rotate_left()
{  
   check1 = 0;
   check2 = 0;
   check3 = 0;
   check5 = 0;  
   
   analogWrite(speedch1,0);
   analogWrite(speedch2,0);
   analogWrite(speedch3,0);
   analogWrite(speedch4,0);
   
   delay(100);
   
   digitalWrite(dirch1,HIGH);
   digitalWrite(dirch2,LOW); 
   digitalWrite(dirch3,LOW);
   digitalWrite(dirch4,HIGH);
   analogWrite(speedch1,SPEED);
   analogWrite(speedch2,SPEED);
   analogWrite(speedch3,SPEED);
   analogWrite(speedch4,SPEED);
  
  check4 = 1;
}
void pause()
{ 
   check1 = 0;
   check2 = 0;
   check3 = 0;
   check4 = 0;  
  
   analogWrite(speedch1,0);
   analogWrite(speedch2,0);
   analogWrite(speedch3,0);
   analogWrite(speedch4,0);
  
   check5 = 1; 
}
Step 10: Final Processing code
Now,I am presenting you the processing code which is used to run the Xbee.I have used arrow keys for the direction and ctrl key for stop.I have included the data in channel to receive the encoders.Sometimes,it crashes when it only receives 1 Encoder Code is written in step 2.
 import processing.serial.*;
 Serial myPort;  // Create object from Serial class
 int lf = 10;    // Linefeed in ASCII
 int source1; 
 int source2;
 String myString = null;

void setup()
{
  size(640, 360);
  println(Serial.list());
  String portName = Serial.list()[5]; // pick the port connected
  myPort = new Serial(this, portName, 9600);
  myPort.clear();

  myString = myPort.readStringUntil(lf);
  myString = null;
  source1 = 0;
  source2 = 0;

}
 
 void draw()
{
   background(255,255,255);
   textSize(32);
   text(source1,20,60);
   text(source2,20,120);
   fill(0,0,0);
   while (myPort.available() > 0) 
   {
    myString = myPort.readStringUntil(lf);
    if (myString != null) 
    {
      println(myString);  

     String[] q = splitTokens(myString, ",");//split at ","
     println(q.length + " values found");  // Prints 2 values found"
     source1 = int(q[0]);
     source2 = int(q[1]);
     }
    }
}
 void keyPressed() 
{
  if (key == CODED)
  {
    if (keyCode == UP)
    {
     myPort.write(10);//Forward
    } 
    else if (keyCode == DOWN)
    {
      myPort.write(12);//Backward
    }
    else if(keyCode == LEFT)
    {
      myPort.write(13);//LEFT
    }
    else if(keyCode == RIGHT)
    {
      myPort.write(11);//Right
    }
    else if(keyCode == CONTROL)
    {
    myPort.write(14); //Pause
    }
   }
}
Step 11: How It works.
Below I have uploaded a video of the rover rolling over some obstacles.I just hope my blog will be helpful to you.