Pages

Monday 31 March 2014

Bought One New Arduino Mega 2560 - R3, Most Amazing Arduino Board


Arduino Mega 2560 - R3 is an amazing microcontroller board based on ATmega2560. It has 54 Digital input/output pins (Arduino Uno has only 14 Digital input/output pins) of which 14 pins can be used as PWM outputs and 16 Analog inputs (Arduino Uno has only 6 Analog inputs). Apart from these, it has 4 UARTs, a 16 MHz oscillator, a USB connection, a power jack and a reset button.

Arduino Mega is special by it's high performance and amazing look. Portion of Arduino Mega encircled in red in the following figure is exactly similar to Arduino uno. It is designed in such a way that encircled portion will work as Arduino Uno. All the circuits designed using Arduino Uno can be made to work in this portion. Apart from all these, it's most amazing feature is 256k flash memory where Arduino Uno has only 32k of flash memory.


Comparison between Arduino Uno and Arduino Mega.

Saturday 29 March 2014

Control DC Motor Direction Using L293D Motor Driver and Arduino

L293D is a popular motor driver. It is special by its high current and voltage rating. Each L293D can be used to control two motors. Each side controls each motor. 1A and 2A is the control pins for motor M1. Similarly 3A and 4A is the control pins for motor  M2. Here, the circuit is demonstrated to control M1 only. Control pins are normally connected to Microcontrollers. I used Arduino to give control signals. Circuit Diagram is as shown in figure given below.


Direction of rotation as per the control signals is represented in the following table.

Program for clockwise rotation of motor.

int oneA = 13;
int twoA = 12;

void setup() {                
  pinMode(oneA, OUTPUT);      
  pinMode(twoA, OUTPUT);   
}

void loop() {
  digitalWrite(oneA, HIGH);   // 1A = 1
  digitalWrite(twoA, LOW);    // 2A = 0
  delay(1000);                       // wait for a second
}


Program for anticlockwise rotation of motor.

int oneA = 13;
int twoA = 12;

void setup() {                
  pinMode(oneA, OUTPUT);      
  pinMode(twoA, OUTPUT);   
}

void loop() {
  digitalWrite(oneA, LOW);     // 1A = 0
  digitalWrite(twoA, HIGH);    // 2A = 1
  delay(1000);                       // wait for a second
}

Thursday 27 March 2014

Communicate an Xbee Connected to Arduino to Xbee Connected to Xbee Explorer

Xbee communication using Arduino is an interesting task. Here is a demonstration of connecting XBee RF Modules to Arduino. Entire system can be pictorially represented as shown in figure.


XBees have to be configured, according to our purpose, before inserting to the breakout board. In this example, I configured RF Modules for Peer-to-Peer communication. Read this tutorial to configure XBee modules for Peer-to-Peer Communication.

Step 1: Complete the circuit as shown in figure given below.

Step 2: Insert one of the configured XBee to the breakout board (Xbee modules should be inserted       carefully. Improper placing will damage your Xbee module).
Step 3: Connect Arduino board to computer.
Step 4: Open Arduino IDE and paste the following program.

char letter;

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

void loop() {  
  Serial.write('a');
  delay(400); 

  if(Serial.available())
  {         
    letter=Serial.read();
    Serial.print(letter);
  }
}


Step 5: Upload the program to your Arduino board. For successfull uploading, don't forget to disconnect the wires connected to the RX and TX pins of Arduino.
Step 6: Connect the other Xbee module to your computer via a Xbee explorer USB or 
Step 7: Open X-CTU. Enter the Com Port Number. Then press Add button.


Step 8: Press Test / Query button.


Step 9: Open the terminal tab of X-CTU as well as the Serial monitor of Arduino. Letters typed in the terminal of X-CTU will be displayed in the Serial Monitor of the Arduino. Xbee connected to the Arduino will be always sending letter 'a' to the Xbee module connected via Xbee explorer USB or Xbee explorer dongle.

Wednesday 26 March 2014

AT+CPMS - AT Command for Preferred SMS Message Storage

AT+CPMS is the AT command used to get the number of messages stored and the maximum capacity of preferred memory. Here is the demonstration of AT command using Arduino. GSM Modem I used is given in this page

Step 1: Complete the circuit as shown in the figure given below.

Step 2: Connect Arduino board to your computer.
Step 3: Open Arduino IDE.
Step 4: Now upload the below given program to Arduino board.

Some Important Facts :
1. For successfull uploading, wires connected to the RX and TX pins of Arduino board must be             disconnected before uploading the code.     
2. Don't forget to put a SIM having sufficient balance in the SIM900-TTL MODEM.
3. External power supply should be capable of handling 1A output current.

void setup() 
{
  Serial.begin(2400);
  Serial.write("AT+CMGF=1\r");           //set GSM to text mode
  delay(1500);

  Serial.write("AT+CPMS=\"SM\"\r");     //Preferred SMS Message Storage
  delay(1000);
  while(1)
  {
    if(Serial.available())
    {
      Serial.write(Serial.read());  
    }   
  }   
}

void loop() 
{

}

Step 4: Open your Serial Monitor. Change the baud rate to 2400.

Step 5: Press the Reset button on Arduino board. Now total number of messages and the maximum capacity of the memory will be displayed in the Serial Monitor (Encircled in black).

Tuesday 25 March 2014

AT+CMGR - AT Command to Read SMS Message

Sometimes we have to read a particular message from preferred store using AT commands and SIM900-TTL GSM Modem. Here is the demonstration to list a particular message from SIM memory using AT commands. AT+CMGR is the command used to list particular message. GSM Modem I used is given here http://www.rhydolabz.com/index.php?main_page=product_info&cPath=184_185&products_id=1080


Step 1: Complete the circuit as shown in figure given below.


Step 2: Connect Arduino board to your computer.
Step 3: Open Arduino IDE.
Step 4: Now upload the below given program to Arduino board.

Some Important Facts :
1. For successfull uploading, wires connected to the RX and TX pins of Arduino board must be             disconnected before uploading the code.     
2. Don't forget to put a SIM having sufficient balance in the SIM900-TTL MODEM.
3. External power supply should be capable of handling 1A output current.

void setup() 
{

  Serial.begin(2400);
  Serial.write("AT+CMGF=1\r");           //set GSM to text mode
  delay(1500);

  Serial.write("AT+CPMS=\"SM\"\r");      //Preferred SMS Message Storage
  delay(1000);
    
  Serial.write("AT+CMGR=1\r");         //list the first message from SIM Memory
  while(1)
  {
    if(Serial.available())
    {
      Serial.write(Serial.read());  
    }   
  }
}

void loop() 
{
  
}

Step 4: Open your Serial Monitor. Change the baud rate to 2400.

Step 5: Press the Reset button on Arduino board.  Now that particular message in the SIM Memory will be displayed in the Serial Monitor (Encircled in black).

AT+CMGL="ALL" - AT Command to List SMS Messages from Preferred Store

Sometimes we have to list SMS messages from a preferred store using AT commands. Here is the demonstration to list messages from preferred store by AT commands using SIM900-TTL GSM Modem and Arduino. AT+CMGL is the command used to list messages from preferred store.  Modem, I used is given here.
Step 1: Connections are done as shown in figure given below.  

Step 2: Connect Arduino board to your computer.
Step 3: Open Arduino IDE.
Step 4: Now upload the below given program to Arduino board.

Some Important Facts :
1. For successfull uploading, wires connected to the RX and TX pins of Arduino board must be             disconnected before uploading the code.     
2. Don't forget to put a SIM having sufficient balance in the SIM900-TTL MODEM.
3. External power supply should be capable of handling 1A output current.


void setup() 
{

  Serial.begin(2400);
  Serial.write("AT+CMGF=1\r");           //set GSM to text mode
  delay(1500);

  Serial.write("AT+CPMS=\"SM\"\r");         //Preferred SMS Message Storage
  delay(1000);
    
  Serial.write("AT+CMGL=\"ALL\"\r");       //List SMS Messages from Preferred Storage
  while(1)
  {
    if(Serial.available())
    {
      Serial.write(Serial.read());  
    }   
  }
}

void loop() 
{
}


Step 4:
Open your Serial Monitor. Change the baud rate to 2400.

Step 5: Press the Reset button on Arduino board.  Now all the messages in the SIM Memory will be              displayed in the Serial Monitor.

Sunday 23 March 2014

AT+CMGS - Send SMS Message Using SIM900 - TTL GSM Modem

Sending SMS Messsage using SIM900-TTL Modem is an interesting task. First of all connections
had to be done as shown in figure. GSM Modem I used is given in this page











Now Open your Arduino IDE. Connect Arduino board to your computer. Then paste the following code in the IDE. Now compile and upload the Code to your Arduino Board.

Some Important Facts :
1. For successfull uploading, wires connected to the RX and TX pins of Arduino board must be             disconnected before uploading the code.     
2. Don't forget to put a SIM having sufficient balance in the SIM900 TTL-MODEM.
3. External power supply should be capable of handling 1A output current.
4. Phone number written in a blue box in program must be replaced by a phone number to which you       want to send SMS message.

void setup() 
{
  Serial.begin(2400);           //Open Serial connection at baud 2400
  delay(2000);
  Serial.write("AT+CMGF=1\r");           //set GSM to text mode
  delay(1500);
  Serial.print("AT+CMGS=\"+918281342098\"\r");   //phone number to which you want to send sms
  delay(1000);
  Serial.print("Message From GSM");           //SMS body 
  delay(1000); 
  Serial.write(0x1A);           // sends ctrl+z end of message 
}

void loop() 
{
  
}

After uploading the code. Reconnect the disconnected wires to Arduino board. Then press the reset button on Arduino board.

Be patient for some time. A new message will come to your phone within 15 seconds.

Wednesday 19 March 2014

Reset Arduino using Program - Program code to reset Arduino

Sometimes we will want to reset our Arduino using program. Resetting arduino using code is simple. A function is used for resetting Arduino. Function is given below.

void(*resetFunc) (void) = 0; 

To reset arduino, call the function using following code.

resetFunc();

Sample Program.

void setup(){
}

void(*resetFunc) (void) = 0; 


void loop() {

  resetFunc();
  delay(1000); 
}

Above program will reset arduino each and every second.


Tuesday 18 March 2014

How to Interface Graphic LCD to Arduino Uno and ATmega328 ?


Interfacing JHD12864E to Arduino is a simple task. Interfacing Circuit is as shown below. Pin numbers given on the right side is the Arduino pins and the pin numbers given on the left side is the GLCD pins.


Pin numbers of JHD12864E GLCD is as shown in the figure given below.

Pin numbers of Arduino Uno is as shown in the figure given below.

After completing the circuit, download the latest version of GLCD library from http://code.google.com/p/glcd-arduino/downloads/detail?name=glcd-v3-20111205.zip. Downloaded file will be a zip file. Extract the file. Now we will get a GLCD folder. Put this GLCD folder in your arduino libraries folder. Now your libraries folder will be as shown below.


1. Now run your Arduino IDE. Connect Arduino Board to your computer. 
2. Open HelloWorld.pde from /arduino-1.0.5/libraries/glcd/examples/HelloWorld/ in a text editor. Copy the code in HelloWorld.pde to Arduino IDE. 


3. Now compile and upload the code. HelloWorld will be displayed in the GLCD.

Sunday 2 March 2014

How to use ATmega Microcontroller from Arduino Board on Another Circuit

             Using Arduino boards for electronic circuits are easier to implement, but is very much costlier. Also any damage to the board will result in high economic loss. To avoid this, after uploading the programme, we will seperate the ATmega microcontroller from the Arduino board and then will put on the circuit. While putting the ATmega microcontroller programmed using arduino on another circuit, some facts have to be noted.


1. A Crystal Oscillator of 16 MHz should be connected across the XTAL1 and XTAL2 of the microcontroller.

2. Constant 5V power supply from 7805 Regulator IC.

Step 1. Upload the below given program to blink an LED to the microcontroller using Arduino Board.

int led = 13;

void setup() {              

    pinMode(led, OUTPUT);  
}

void loop() {

    digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(1000);                     // wait for a second
    digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
    delay(1000);                     // wait for a second
}

Step 2.

Create a circuit as shown in the figure given below. When the power supply is given, LED will start blinking.


ATmega168 / 328 pin mapping can be obtained from the following image.