Showing posts with label interface. Show all posts
Showing posts with label interface. Show all posts

Friday, 22 August 2014

Driving DC motors using L293D

DC Motor Basics:


                A DC motor has two terminal pins for supply. Direction of rotation of motor can be reversed by changing the polarities. This is depicted as follows,
 
Motors require high currents to operate. The current and voltage from a microcontroller’s output cannot drive a dc motor. Hence we require an external driving circuit.
A simple motor driving circuit is shown below.,


Diode 1 is used to prevent reverse current flow from the motor to the controller (Protection Diode). When the microcontroller’s output is logic HIGH or ‘1’, then the motor will start to rotate. However the circuit is for only unidirectional control of DC motor i.e, the motor rotates in only single direction and can’t be reversed. For this purpose we will be using a H – bridge.

H – bridge:




             When a logic HIGH or ‘1’ is applied (from microcontroller) at CW, then the transistors T1 and T4 will get shorted and current flows from Vcc - T1 – motor – T4 – Gnd, thus making the motor to rotate in clockwise direction.


On the other hand, when a logic HIGH or ‘1’ is applied (from microcontroller) at CCW, then the transistors T2 and T3 will get shorted and current flows from Vcc – T3 – motor – T2 – Gnd, thus making the motor to rotate in counter clockwise direction (reverse).


                When the input at both CW and CCW is logic ‘0’ or LOW, then no transistor gets shorted and hence no conduction of current from Vcc to Gnd. When the inputs at both CW and CCW is logic ‘1’ or HIGH, then all the transistors gets shorted and all the current goes from Vcc to Gnd through transistors without going through the motor. Hence motor will not rotate in neither directions.


CW
CCW
Output
0
0
Stop
1
0
CW rotation
0
1
CCW rotation
1
1
Brake / Stop


Interfacing with L293D:


                There are several custom made H bridge IC’s available in the market. Commonly used IC by electronic hobbyists is L293D.


Note: if you buy L293B, then you have to put protection diodes additionally, because there is no protection diode inside the IC. L293D has inbuilt protection diodes.

L293D pinout:




Here is the datasheet – L293D

L293D has the capacity to drive two DC motors bi-directionally (2 channels). You may consider IC’s left side pins (Enable 1, Input 1, Output 1, Output 2, Input 2) as channel 1 and right side pins (Enable 2, Input 3, Output 3, Output 4, Input 4).

  • Enable pin is to enable the corresponding channel (Normally 5V – max 7V).
  • Input pins receive logic HIGH or Low from the controller (Normally 5V – max 7V).
  • Output pins are connected to the motors.
  • Vss – logic supply voltage (Normally 5V – max 36V)
  • Vs – Motor supply voltage, as per motor specifications (Normally 5V – max 36V)
  • Gnd pins – All of these ground pins are connected internally and hence they need not be interconnected externally.

General Connection diagram:

 

 If you use a 5V DC motor, the pin 8 (Vs) should be connected to 5V and similarly for different motor ratings. Various colour wires have been used to differentiate between the connctions.

With GR-Sakura (Arduino Compatible):

 

Pins 5, 4, 7 and 6 of sakura board are used as L293D Input pins 1, 2, 3 and 4 respectively.


Pins 5 and 4 – Input 1 and 2 of channel 1 / CW and CCW of motor 1

Pins 7 and 6 – Input 3 and 4 of channel 2 / CW and CCW of motor 2

Since I have used two 5V DC motors, 5V from sakura is connected to Vs of L293D.

Code:


#include<rxduino.h>
main()
{
                pinMode(7,OUTPUT);
                pinMode(6,OUTPUT);
                pinMode(5,OUTPUT);
                pinMode(4,OUTPUT);
                while(1)                                   // repeating / infinite loop
     {
                                digitalWrite(5,1);     // rotates motor 1 Clockwise
                                digitalWrite(7,1);     // rotates motor 2 Clockwise
                                digitalWrite(4,0);   
                                digitalWrite(6,0);
                                delay(5000);             // After 5 seconds
                                digitalWrite(5,0);
                                digitalWrite(7,0);
                                digitalWrite(4,1);     // rotates motor 1 Counter Clockwise
                                digitalWrite(6,1);     // rotates motor 2 Counter Clockwise
}
}



Feel free to comment regarding doubts...............

Wednesday, 6 August 2014

HC - 05 Bluetooth Module Basic interface (Tutorial 1)

HC-05 Bluetooth Module:

             
   HC – 05 is a Bluetooth SPP profile module that can be used as either Master or Slave device.
Master - the module can be configured to search for the nearer Bluetooth devices and can pair with required device (mobiles and computers).
Slave (Default mode) – Other Bluetooth devices can search for this module and pair with the module by simply typing the default password (1234).
There are two modes in HC-05 communication,
1.        Communication mode
2.       AT mode
          In this tutorial, we will just see the communication mode, where data is transmitted between HC-05 and Android mobile phone. An Android App named Blueterm is used to receive this serial data and display it. GR-Sakura board (Arduino Uno Compatible) is used to control HC-05 Bluetooth module.
         The HC-05 Bluetooth module that I use is shown below. I bought it for Rs.1000 from nskelectronics.com. While you buy a HC-05, note that it comes with the interface board as shown below.
 
          If you buy it without the interface board as shown below, then it’s a big ‘headache’.  I bought one, tried to solder it, but it was an utter failure.
 

 

Pin Details:



State – LED output status (Honestly, I don’t exactly know what this does. It is not of much use, hence no worries.)

Key – pin to drive the module into AT mode
 
RX – UART Receiver pin
 
TX – UART Transmit pin
5V – 5 volt supply voltage
 
GND – ground pin
 
Note: In the module I use, RX and TX pins of the module should be connected to the RX and TX pins of the processor respectively.
 

Circuit Diagram:

 
 
 

BlueTerm:

      First pair with HC-05 by searching for bluetooth devices using Android Mobile phone. Then open Blueterm App.
 Blueterm app screen

Tips: In the Preferences tab, select the ‘Local echo’ option or else the characters that you type won’t be visible in the screen.




Once you open Blueterm, click ‘Connect Device’ and select ‘HC-05’.
 

Tera term:

 
            Similar to the app at mobile side, you can have a serial monitor at PC side. One of such serial monitors is Tera Term.




 
 

Code:


#include <rxduino.h>
#include<iodefine_gcc63n.h>

int main()
{
  Serial.begin(9600);

  Serial1.begin(115200, SCI_SCI6B); // the baud rate should be same as that of the module baud rate *
  delay(8000);

  Serial.println("Start sending data.....");
  Serial1.println("Start sending data.....");

  delay(5000);
  while(1)
  {
              if (Serial.available())
              {
                          Serial1.write(Serial.read());
              }
               if (Serial1.available())
              {
                          Serial.write(Serial1.read());
              }
  }
}
Now, whatever you type in Tera term will appear in Blueterm and vice versa.
 
 
 
* The baud rate can be found out using the AT command (AT+UART?). The AT mode will be discussed later.