Tuesday 4 November 2014

HC-05 Bluetooth AT commands configuration




We have been using the serial SPP(Serial Port Profile) Bluetooth modules to interface our embedded hardware and robots to Laptop or a smart phone... hear is an example of Bluetooth controlled POV LED display and a smart phone turned into an intelligent robot....




So this HC-05 is very much useful if you want to make some thing cool like this. So it will be helpful if we are aware of the configurations commands to work with the module. 

AT commands:

AT commands stands for attention commands with which we communicate with the module and alter it's performance.

There are TWO modes of working with HC-05 module. To check with the module you will need a serial port on your PC or laptops. But nowadays our PC won't come with an inbuilt RS232 serial interface  so you can use any USB to serial converters like CP2102 or FT232 devices. After connecting the device to the PC we need any serial terminal software in case of  windows7 and 8 like "Teraterm" or "Putty" .But in case of windows XP you got hyper-terminal. 

In my case i got a CP2102 with me. connect Bluetooth to the CP2102 UART pins (RX and TX)

  
 There is one important thing that you need to keep in mind is....
 "your Bluetooth module logic voltage levels" mine is 3.3V but it got tolerance up to 5V so no problem with my device. and my CP2102 is direct TTL and I am not using any MAX232 in this. so make sure of your device before powering it.

 after connecting the Bluetooth to your serial port device like the one in the picture above. 
connect the device to your PC and power it up...now you will see an LED blinking very fast on your Bluetooth module. This is the normal serial data mode.

Now remove the power. Press and hold the mode button and connect the power. Then the LED will start blinking very slowly...which indicate that you Bluetooth is now in "AT command"mode.

open the serial terminal software and select the "COM" number of your serial port module and configure the following                                
baud rate as"38400"
hardware    "none"
parity          "none"
databits       "8"
stop bits      "1"

better enable local echo in your terminal software...

type "AT" and press <enter> switch you will get response "OK" it means your device is working in AT mode successfully..once if you disconnect the power then the you Bluetooth will be back to serial data mode.

NOTE: in AT mode the baud rate will be 38400. but in serial data mode many baud rate values can be  used.

few of the useful AT commands:

AT    <enter>   it gives the response OK continuously so press <enter> again to stop

AT+NAME?  <enter> it displays the name of Bluetooth module

AT+NAME=new_name  <enter> changes module name to "new_name"

AT+PSWD?  <enter> displays password to enter while pairing with this device

AT+PSWD=4321 <enter> changes the password to 4321
( only 4 digit number is accepted as password )

for more info regarding AT commands refer to the data sheet.

   





Thursday 3 July 2014

PIR motion sensor interfacing with microcontroller



Passive InRrared sensors:


This sensor senses the bodies that emitting IR radiation and are in motion. there are several types of PIR sensors are available in the market. most common types are these TWO..


TYPE.1: with one potentiometer                                                                                

  

 This Pot is used to set the time of out put signal  stays at logic high on object detection width. this  sensor's sensitivity can't be altered. It produces a     3.3V "logic high". 











TYPE.2: with two potentiometers  
The device has two variable resistors that you can adjust to tweak the performance of the module.
The first one (left-hand side on the photo) determines the sensitivity of the device. The default setting is usually 50%.
The second control (right-hand side on the photo and usually marked “time” on the PCB) allows you to adjust the amount of time the output pin stays at 3.3V (high) when it is triggered by movement. This can be set from a few seconds to 200 seconds. The default setting is usually a few seconds.
    WORKING:
But the operation of the both sensors is same. This PIR sensor doesn't respond for the stationary objects. Instead it senses the IR bodies in motions(hot materials and living objects). This sensor accepts DC voltage of 5V. 

NOTE:

Most of the time pin configuration will be printed on the sensor . But some sensors available with in in India are not describing pin configurations properly. But the standard notation of pin will be like all ways middle pin will be output. so if you identify the GROUND then remaining pin will be VCC.
It is very simple. Most of these sensors are made of using BISS0001(16 pin DIL package). 7th pin of this IC is GND. So take a multimeter and  check for short circuit test and beep sound. then it will be your sensor ground and opposite side pin will be VCC


As the sensor provides 3.3V signal it may be little difficult to interface with microcontrollers working at Vcc=5V(most 8 bit hobby controllers like AT89S51). At the same time it will be easy to interface with low powered microcontrollers like LPC2148. You better check your microcontroller Logic voltage levels.


Actually i interfaced this sensor to ATmega8 MCU which can detect even 3.3 volt logical signal. So i successfully connected this PIR sensor to the ATmega8 microcontroller.

Basic Program 

#include<avr/io.h>
void main()
{
  DDRC=0xfe; //configuring PortC pin 0 as input
 PORTC=0xff; //enabling internal pull-up resistors
DDRB=0xff;    // configuring PortB as output
PORTB=0x00; // buzzer off

while(1)
{
  if((PINC & 0x01)==0x01) // check for sensor pin PC.0 using bit       {                                            //masking (if sensor detects motion ) 
   PORTB=0xff;                   // buzzer on
   }
  else
  PORTB=0x00;                   // buzzer off
}

}
   

Tuesday 13 May 2014

Bluetooth controlled robot using ARDUINO

This article helps you to make a robot that can be controlled from your android powered mobile through Bluetooth.



 HC-05:

This Bluetooth module works on SPP (serial port profile). It establishes a serial communication(UART) between your android mobile and microcontroller.

This module works in two modes:
1) AT mode
2)COM mode

AT mode:

In AT mode you can directly connect the module to your computer hyper terminal or any other serial gate way through DB9 serial port through MAX232 circuit (or you can use any USB to UART gateways like FT232and configure through AT commands. set the baud rate "38400"
some example commands:

AT    <enter>   it gives the response OK continuously so press <enter> again to stop

AT+NAME?  <enter> it displays the name of Bluetooth module

AT+NAME=new_name  <enter> changes module name to "new_name"

AT+PSWD?  <enter> displays password to enter while pairing with this device

AT+PSWD=4321 changes the password to 4321 ( only 4 digit number is accepted as password )

for more info regarding AT commands refer to the data sheet.

COM mode:
this is the mode that to be set when interfacing with a microcontroller through UART.

In this project i'm using an Arduino MEGA 2560 and a Bluetooth shield from Robogenesis

To drive the DC motors i'm using L293D.

CIRCUIT DIAGRAM:



arduino code:

//---------------------------------------------------
//--------------- code starts-------------------------
//---------------------------------------------------
unsigned char blue_data;
void setup()
{
  Serial.begin(9600);// set up serial communications with 9600 baud rate

  pinMode(7, OUTPUT);//motor 1a
  pinMode(6, OUTPUT);//motor 1b
  pinMode(5, OUTPUT);//motor 2a
  pinMode(4, OUTPUT);//motor 2b
digitalWrite(7,LOW);
digitalWrite(6,LOW);
digitalWrite(5,LOW);
digitalWrite(4,LOW);
}

void loop()
{
   if (Serial.available() > 0)
  {
    blue_data = Serial.read();// get incoming byte from bluetooth
          if(blue_data=='F' )//forword
           {
            digitalWrite(7,HIGH);digitalWrite(6,LOW);digitalWrite(5,HIGH);digitalWrite(4,LOW);
           }
  else if(blue_data=='B' )//backword
           {
            digitalWrite(7,LOW);digitalWrite(6,HIGH);digitalWrite(5,LOW);digitalWrite(4,HIGH);
           }
  else  if(blue_data=='L' )//left turn
           {
            digitalWrite(7,LOW);digitalWrite(6,HIGH);digitalWrite(5,HIGH);digitalWrite(4,LOW);
           }
  else  if(blue_data=='R' )// right turn
           {
            digitalWrite(7,HIGH);digitalWrite(6,LOW);digitalWrite(5,LOW);digitalWrite(4,HIGH);
           }
   else if(blue_data=='S' )// stop
           {
             digitalWrite(7,LOW);digitalWrite(6,LOW);digitalWrite(5,LOW);digitalWrite(4,LOW);
           }
   
  }

}

android app:

Description
****This application is designed to be used with a MODIFIED RC car. You have to replace the car's stock control circuit with a micro controller. This involves programming. The application will not work with a brand new, out of the box RC car. Please visit the website before you download the application.
The application allows you to control an Arduino based RC car over Bluetooth. This is done using a Bluetooth enabled Android phone. Visit this sitehttps://sites.google.com/site/bluetoothrccar/ for the Arduino code and control circuit. The app lets you control the car with either buttons or the phone's accelerometer. A slider bar allows you to control your car's velocity if the car's control circuit has this feature. There are also two buttons for front and back lights. A flashing light lets you know when the phone is connected to the car, and arrows light up letting you know the car's driving direction.



WORKING VIDEO


Wednesday 26 February 2014

ZIGBEE (Tarang F4) interfacing with microcontroller

When there is a need of long range two way communications in hobby electronics most of the people prefer "ZIGbee" modules. there are several zigbee modules available in the market...with several ranges and qualities..

Tarang F4 is also a similar module.....

So let's see how to use these modules for normal full duplex serial communication with UART:

  1.  This module can be easily interfaced with  any 8 bit microcontroller with all standard baud-rates between 1200 to 115200.   
  2. Each module consists of a 16 bit address. So user must provide a source address and destination address while configuring the module. which means only the destination module with matched address can only receive the data.
  3. User can select the RF channels among 16 channels with addresses from 0x00 to 0x0F. The modules must be in same channel to establish the communication between them. 


 lets check the pin configuration of this module.

Tarang module works on 3.3v  power supply. so sufficient voltage regulator must be used.

WORKING PROCESS:

By default the tarang F4 module: works at baud-rate of : 9600
                      source address : 0x1000   (hexadecimal)     
destination address : 0x1000            
RF channel : 0x00     
it means :

"by default any tarang F4 module can communicate with any other module".

 So tarang modules can be directly interfaced with microcontroller with baudrate of 9600. The connection circuit will be as follows.

NOTE: if your microcontroller is working at 3.3V then you can directly interface it to the microcontroller. if your microcontroller is working at 5V connect a resistor of 100ohms between TXD pin of MCU and Din pin of Tarang F4.

CONFIGURING THE MODULE:

For configuring the tarang F4 module first connect the module to PC serial Port. Now a days our laptops are not designed with serial ports directly. So we have to go for USB to Serial converters Like FT232, CP2102 or  Prolific connectors.

  1. Connect the module to PC using any above serial interface.
  2. open "hyper terminal"(in xp) or use any similar software in case of  Windows7 or 8 like "Tera Term".
  3. connect to the selected "COM" port and select local echo option select baudrate of 9600,databits 8, hardware : none.
  4. Device must be set to command mode by entering three '+' symbols "+++"  with in one second. and Do not press enter.
  5. you will get a response from module "OK".
  6. Enter the correspond AT commands as per your requirement and press enter. Follow the command as per the data sheet. Some of the useful basic commands are listed below.
  7. After entering the settings the settings must be stored in the memory. "ATGRD" is the command used to store the settings. If this is not used the current settings will be lost.
  8. to exit the command mode "ATGEX" is used. it gives "EXIT" as response.  

SOME TARANG F4 BASIC AT-COMMANDS 

  1. "ATGEX" : exit form command mode ; response: "EXIT"
  2. "ATGRD": set module to default settings(channel(00)baud(9600),address(1000));response:"OK"
  3. "ATGWR":stores current settings; response : "OK"
  4. "ATNCH": sets/read channel number: response:"00" to "0F" (total 16 supporting channels)
  5. "ATNMY":set/read source address: response:"1000"(16 bit hexadecimal number)
  6. "ATNDA":set/read destination address: response:"1000"(16 bit hexadecimal number)
  7. "ATSBD": set/read baudrate: response: "00" to "07". 
00=>1200
01=>2400
02=>4800
03=>9600
  04=>19200
  05=>38400
  06=>57600
    07=>115200