Sunday, 27 December 2015

Basic Electronics - Lec3 Diodes

The key function of an diode is to control the direction of current-flow. Current passing through a diode can only go in one direction, called the forward direction. Current trying to flow the reverse direction is blocked. They’re like the one-way valve of electronics.
The terminal entering the flat edge of the triangle represents the anode. Current flows in the direction that the triangle/arrow is pointing, but it can’t go the other way.

Forward Voltage
In order to “turn on” and conduct current in the forward direction, a diode requires a certain amount of positive voltage to be applied across it. The typical voltage required to turn the diode on is called the forward voltage (VF). It might also be called either the cut-in voltage or on-voltage.

it is Typically 0.5 volts for Silicon Diode.
BreakDown Voltage :

Breakdown Voltage

If a large enough negative voltage is applied to the diode, it will give in and allow current to flow in the reverse direction. This large negative voltage is called the breakdown voltage. Some diodes are actually designed to operate in the breakdown region, but for most normal diodes it’s not very healthy for them to be subjected to large negative voltages.


Working With LED's :
LED - Light Emitting Diode
The LED does have and "equivalent" resistance, but it's value is wholly dependent on the value of the current flowing through the LED and dynamically changes with it.
To deal with an LED you start with the forward current that you need, typically about half it's maximum rated value (lets use 20 mA).  
Next you estimate what the forward voltage drop will be with that current flowing through the LED.  If you have a datasheet for the LED you may be able to get a fairly accurate value, otherwise you take a guess based upon your experience or the experience of others (I usually use 1.7v for a red LED).  
Next you pick out a supply voltage which must be higher than the voltage you just determined (I'll use 5v).  
Now you can use Ohm's law to determine the required resistance.  The voltage across the resistor will be the difference between the supply voltage you decided to use and the voltage that you guessed would be across the LED (5v - 1.7v = 3.3v).  The current through the resistor will be the same as the current through the LED (20mA).   Ohm's law for the resistor says that R = V/I (R = 3.3/0.020 = 165 ohms).  
You then pick the closest value resistor that you happen to have and stick that in your circuit.  Most likely the current won't be exactly what you desired and the LED voltage won't be what you guessed would be there but you won't see any smoke either and you will see light from the LED.
Check the Data Sheet of Sample LED here.

And see the Maximum Values

Basic Electronics - Les 3 More About Semiconductors

P type and N type Semi Conductors
we can Divide the materials into Three Types According to its Conducting Nature
1. Conductor
2. Insulators
3. Semi Conductors

Insulators : These are having More resistance. have poor Conductivity ex: Rubber

Conductors : Having More Free Electrons than Insulators hence can having High Conductance ex: Copper

Semiconductors: these are having the conductivity range Between the Conductors and Insulators ex: Silicon and Germanium.. with materials they developed all these mysterious Chips.

But the Thing is we cannot use Semiconductors Directly (pure ones i.e intrinsic form), we must able to change number of holes or electrons to change their proper for our cause.

so we are gonna add some known impurities to them so we can alter their properties.

The process of purposefully adding impurities to materials is called doping; semiconductors with impurities are referred to as "doped semiconductors".

ah.. Doping Its just a Fancy Word,,

 p-type and n-type materials are simply semiconductors, such as silicon (Si) or germanium (Ge), with atomic impurities; the type of impurity present determines the type of the semiconductor. 

P-type

In a pure (intrinsic) Si or Ge semiconductor, each nucleus uses its four valence electrons to form four covalent bonds with its neighbors (see figure below). Each ionic core, consisting of the nucleus and non-valent electrons, has a net charge of +4, and is surrounded by 4 valence electrons. Since there are no excess electrons or holes In this case, the number of electrons and holes present at any given time will always be equal.
                                                    An intrinsic semiconductor. Note each +4 ion is surrounded by four electrons


Now, if one of the atoms in the semiconductor lattice is replaced by an element with three valence electrons, such as a Group 3 element like Boron (B) or Gallium (Ga), the electron-hole balance will be changed. This impurity will only be able to contribute three valence electrons to the lattice, therefore leaving one excess hole (see figure below). Since holes will "accept" free electrons, a Group 3 impurity is also called an acceptor.
                                                       A semiconductor doped with an acceptor. An excess hole is now present
Because an acceptor donates excess holes, which are considered to be positively charged, a semiconductor that has been doped with an acceptor is called a p-type semiconductor; "p" stands for positive. Notice that the material as a whole remains electrically neutral. In a p-type semiconductor, current is largely carried by the holes, which outnumber the free electrons. In this case, the holes are the majority carriers, while the electrons are the minority carriers.

N-type

In addition to replacing one of the lattice atoms with a Group 3 atom, we can also replace it by an atom with five valence electrons, such as the Group 5 atoms arsenic (As) or phosphorus (P). In this case, the impurity adds five valence electrons to the lattice where it can only hold four. This means that there is now one excess electron in the lattice (see figure below). Because it donates an electron, a Group 5 impurity is called a donor. Note that the material remains electrically neutral.
                                                        A semiconductor doped with a donor. A free electron is now present.

Donor impurities donate negatively charged electrons to the lattice, so a semiconductor that has been doped with a donor is called an n-type semiconductor; "n" stands for negative. Free electrons outnumber holes in an n-type material, so the electrons are the majority carriers and holes are the minority carriers

(Materail is From http://solarwiki.ucdavis.edu/The_Science_of_Solar/Solar_Basics/D._P-N_Junction_Diodes/I._P-Type,_N-Type_Semiconductors)




Saturday, 26 December 2015

Basic Electronics - Lesson 2 More About Resistors

More About Resistors

Resistors are More Fundamental and Commonly used of all the electronic components.
The Principal job of a Resistor within a electrical or Electronic circuit is to "Resist", regulate or to set the flow of electrons (Current) through them.

Typical Resistor

Standard Resistor symbol

Calculating the Resistance Value using Graphical Representation
like
B-B-R-O-Y-Great-Britain-Very-Good-Worker

We take Consideration from Narrowed Space End

if we have Resistor with Following colors - (Blue Black Brown and Gold)
Then the value of Resistor Would be -
Blue - 6 - First Digit
Black - 0 - Second Digit  which makes Value = 60
Brown - 1  - Multiplier value Which makes --> 60 * 10 = 600 Ohms


How To check Resistance
Finding the value of Resistor using Color Code is easy... But It is A cumbersome if  we have many Resistors With Different values and Going through entire Calculation Every time we need a Value.
So A device Called MULTIMETER is Useful for this purpose.

we can use it To Measure Voltage, Current, And Resistance.


A Multimeter has three Parts

1.Display
2.Selection Knob
3.Ports

Section Knob is used to Select the Parameter which user wanted to measure 

Measuring Resistance:
Points To Note :
Resistance is non-directional

You can only test resistance when the device you're testing is not powered

You can only test a resistor before it has been soldered/inserted into a circuit

If you have a ranging meter you'll need to keep track of what range you are in. Otherwise, you will get strange readings, like OL or similar, or you may think you're in KΩ when really you're in MΩ. 

Selecting the Range.

Please Note the Ohm symbol

Resistance In Series and Parallel
we can Calculate the Resistance of particular material Using formula

R = rho * l /A
where rho  -->  the resistivity of  the Material
l --> length of Material
A --> Cross Sectional Area

If we Connect Two Resistors in Series (End to End)  the Overall resistance is Increased
If we Connect Two Resistors in Parallel (Side by Side) then the Overall Resistance is Decreased

Resistors in series add together as R1 + R2 + R3 + ..... 
While resistors in parallel reduce by 1 / (1 / R1 + 1 / R2 + 1 / R3 + .....)

Measuring the Voltage
We need to Connect the Positive terminal of Battery to the Red wire and Negative terminal to The Black wire.. If we reverse the Polarity we are Gonna Have Negative Voltage.


Friday, 18 December 2015

Hacking the Mp3 Player With Arduino

Adding audio to your project is Much easy If you have a Cheap mp3 Player and few Opto Couplers and Arduino to drive them,...



Here i used the pc817 Optocouplers and 330 Ohms resistors to Drive the optocoupler from arduino Ouput pin...
and second input to Gnd of arduino.. Opto Coupler Outputs to the inner and Output Surfaces of the Each Switch... Then You are Good to go..
It is good to Add a Single or Two audio files.. But if you wanted to have more Control Go for Mp3 shield.  

Arduino Brightness Control

when I started learning Arduino for some projects.. i think Whats the use of doing this besides knowing commands to do?
Then I got a Reply for such stupid question..
I have a Whiteness Meter, Which is used to Measure the Whiteness of some Chemical powder...
But the output Value is changing With the Outside Sun lightning..
so i Did this
 


I made a Box and put the meter in it and placed the Leds Which are controlled Serially..

Tuesday, 24 November 2015

Basic Electronics - Lesson 1

This lies at the Basic 

ATOMS are the Basic building blocks of the matter that make up everyday Object.

a desk, the air, even you made up of atoms
Most atoms have different subatomic particles inside them
Protons
Neutrons
Electrons
The Protons and Neutrons are packed together into the Center of the Atom - which is called Neutron
and Electrons which are very much smaller in size whiz around outside
Electrons are so mobile that every second they orbit the atomic nucleus around the up to 500 trillion times

Electrons and Protons have the Electrical Property Called CHARGE

Protons Have Positive Charge
Electrons have Negative Charge 
Neutrons have no Charge - neutral
Hence they Normally Balance  each other out. So the Total Net charge of  Atom is Zero.


CURRENT:
When electrons move together in a unified way we say there is a current Flowing.
Electrons are actually moving all time in materials like metals But Moving in a Random Disordered Way, A current is Flowing when Movement of Electrons in a PARTICULAR DIRECTION

When Normally electrons are moving Randomly in All materials But we need them to move in Unified way to Produce the Current.. So We FORCE them to move in One unified way.. The Battery Supplies the FORCE that makes the  Electrons move in unified way.. this Force is Called Electromotive Force or Potential Difference or simply Voltage.

Water Analogy of Voltage(Measure in Volts), Current(Measured in Amps) 
and Resistance(Measured in Ohms)

Analogy :    Water - Electrons
             Pressure - Voltage
             Flow - Current



Electrons can't flow through every Material in a same way.
Materials that allow a current Flow easily are called conductors.
Materials that don't allow a current flow are called non conductor or insulators.

Metals are the most common conductors, Plastics are typical Insulators

     Conductors Non Conductors
      --------------------|--------------------
Copper Plastic
Gold wood


We measure how much opposition is to an electric current as resistance
Resistors are somewhere between conductors, which conduct easily, and  insulators,which don't conduct at all.
 
The Main function of resistor is to control the flow of current

The resistance is measured in Ohms and the Symbol for it is


OHM's Law

Combining the elements of Voltage , Current and resistance, a person 
called Georg Simon Ohm Ohm developed the formula

V = IR

where   V = voltage in volts
I = current in amps
R = Resistance in ohms
this is called Ohms law.

Friday, 20 November 2015

Thermal Switch in Automatic Rice Cooker

Recently... My Automatic Rice Cooker Damaged..
   Before Going for the Service centre, I like to know what’s the problem .
I removed four screws in the bottom and  opened the bottom cover and it looked like this.

I take a multimeter and checked the continuity between the three wires. One wire is not making any sound..
so i cut that wire and found this
There is some component from power connection to the heating element of the cooker and I HAVE NO IDEA what it is...

so i asked the google.. and google told me that is a thermal Switch or Thermal Fuse which is a safety precaution.. and it will blown whenever the temperature reached certain threshold..


Thursday, 5 November 2015

Processing GUI Button

Code:
import controlP5.*;
ControlP5 controlP5;

int buttonValue = 0;
void setup() {
size(400,400);
controlP5 = new ControlP5(this);
controlP5.addButton("White").setValue(255).setPosition(100,100).setSize(200,19);
controlP5.addButton("Black").setValue(0).setPosition(100,120).setSize(200,19);
}
void draw() {
background(buttonValue);
}

void controlEvent(ControlEvent event) {
  println("the Event Triggered is");
println(event.getName());
}



public void White( ){
println("white button");
buttonValue = 255;
}
public void Black(){
println("black button");
buttonValue = 0;
}

Output:


Thursday, 29 October 2015

Simple Java Addition Program

Simple Java Addition Program 

package ex1;

import javax.swing.JOptionPane;

public class Addition {

public static void main(String[] args)
{
JOptionPane.showMessageDialog(null,"This is a Simple Addition Example \n Click OK to Continue");

String a_value = JOptionPane.showInputDialog("Enter the Value of A");
String b_value = JOptionPane.showInputDialog("Enter the value of B");
//converting String to Integer
int a = Integer.parseInt(a_value);
int b = Integer.parseInt(b_value);

int result = a+b;

//Converting Integer to String
String result_val = "" + result;

JOptionPane.showMessageDialog(null, "the value of A + B is \n" + result_val +"\n Thankyou");

}

}


Output..


Tuesday, 25 August 2015

converting True color RGB image into grayscale Image

In matlab there is a function rgb2gray() to convert rgb image into gray scale image.
we can do this manually also.


  1. rgb = imread('Sun.jpg');
  2. figure('name','Original Image')
  3. imshow(rgb);

  4. gray_manual = 0.2989 * rgb(:,:,1) + 0.5870 * rgb(:,:,2) + 0.1140 * rgb(:,:,3);
  5. figure
  6. imshow(gray_manual);

Output
Original Image

Converted GrayScale Image
Formula to do this is
Intensity = 0.2980 * red + 0.5870 * green + 0.1140 * blue


Matlab Image Processing

I am trying to do learn image processing using matlab..
I find tutorials here http://www.bogotobogo.com/Matlab/Matlab_Tutorial_Digital_Image_Processing_2_RGB_Indexed_Color_Info.php

Below program explains converting true color rgb image into index image and show the difference between mapping the index image into various levels.

code
  1. image = imread('Sun.jpg');
  2. figure('name','Original Image')
  3. imshow(image);

  4. [IND,map] = rgb2ind(image,32);
  5. figure('name','image with 32  index')
  6. imshow(IND),colormap(map);

  7. [ind_132,map_132] = rgb2ind(image,132);
  8. figure('name','image with 132 index')
  9. imshow(ind_132),colormap(map_132);
you can also found that sum image on the above link or here 

results
Original Image

Image with 32 Index
Image with 132 Index


Thursday, 25 June 2015

For loop in C : Features I never heard of

We usually use for loop when there is a known number of iterations... Where the while loop is when number of iterations not known in advance.

For loop allow us to define Three expressions in its syntax.

1.Initialization
2.Testing condition
3.change or update

Initialization : It is done Just once,when the for loop just starts.
so it will done its job even though the condition is false in the first iteration.

Testing Condition : It is evaluated before each potential execution of loop
If the condition is true then statements in the loop are executed. If not the it will jump from the loop(the loop is terminated).

Change or Update : It is Evaluated at the end of each loop.

In its syntax it is having three Expressions Separated by Semicolon (;) every time i put a colon instead if semicolon which eventually gives me an syntax error.

For loop Must have Two semicolons even though there are no Expressions

for( ;  ;  )
{

}

is considered as infinite loop

initialization will run only once at the beginning of for loop even though the condition is false.

#include<stdio.h>
#include<conio.h>
int main(void)
{
int a = 6;

for(printf("a = %d \n",a);a<3;) // condition is false
{
printf("entered for loop\n");
}

printf("for loop is terminated\n");
getch();
return 0;
}

output :

Please note that condition is false at the first test But initialisation is executed.

Comma Operator :
Comma operator is useful when we wanted to Include more than One initialization or update expression in for loop.
#include<stdio.h>
#include<conio.h>
int main(void)
{
int i,j;

for(printf("i\tj\n"),i=0,j=0;i<3;i++,j++)
{
printf("%d\t%d\n",i,j);
}

printf("for loop is terminated");
getch();

return 0;

}//end of main

Output :

please note that we cant use colon operator in test condition.






Saturday, 30 May 2015

Seven Segment LED display with Arduino and Proteus

In a simpler view seven segment led display have seven led's with their combination we can display decimal numerals.

when connecting a common cathode in a proteus i have no idea which pin is associated to the respective led in display so i write a little code to do that work for me.

Code :
/*
Arduino Sketch to find out which pin is Associated with corresponding LED in 7 segment display
Author : Kunchala Anil

 It is a common cathode 7 Segment Display.
 connect the common cathode to ground and all the remaining pins to the Arduino Digital pins 2 to 8
 */

int pin = 2;
int pin_dummy = 2;
void setup()
{
  Serial.begin(9600);
  Serial.println("Hello World");
  for(int i = 2; i <= 8; i++)
  {
    pinMode(i,OUTPUT);
    Serial.print("pin \t");
    Serial.print(i);
    Serial.println("\t is set as Output");
  }//end of for loop

}//end of setup

void loop()
{
  Serial.println("Please enter y");
  while(!Serial.available())
  {
    //wait until user enters the data
  }//end of while
  if(Serial.available())
  {
    if(Serial.read() == 'y')
    {
      if(pin_dummy <= 8)
      {
        digitalWrite(pin_dummy,LOW);
        Serial.println("you entered y");
        digitalWrite(pin,HIGH);
        Serial.print("pin ");
        Serial.print(pin);
        Serial.println(" is activated");
        pin_dummy = pin; // pin_dummy is used to OFF the LED before ON next led in display
        pin++;
      }
      else{
        Serial.println("Maximum pin number is reached");
        pin = 2;
        pin_dummy =2;
        Serial.println("Pin values are RESET");
      }//end of If else

    }
    else{
      Serial.println("you entered wrong character");
    }//end of If Else 
  }//end of If 

}//end of loop

after executing the above code i get the following combination
GFEDCBA for 2,3,4,5,6,7,8 pins respectively.
The following code is used to display the 0-9 in common cathode seven segment display.

/*
hEXA DECIMAL ENCODING FOR DISPLAYING NUMBERS 0 TO 9
 FOR COMBINATION - GFEDCBA to pins 2,3,4,5,6,7,8 
 */
/*
 Hex codes for displayiing respective values
 */
const int ZERO = 0X7E;
const int ONE = 0X30;
const int TWO = 0X6D;
const int  THREE = 0X79;
const int  FOUR = 0X33;
const int  FIVE = 0X5B;
const int  SIX = 0X5F;
const int  SEVEN = 0X70;
const int   EIGHT = 0X7F;
const int  NINE = 0X7B;

//pins initialization
int pin[] = {
  2,3,4,5,6,7,8};

//calculating the no of pins
int no_pins = sizeof(pin)/sizeof(pin[0]);


void setup(){
  Serial.begin(9600);
  //setting all pins as Outputs
  for(int i = 0; i < no_pins;i++)
  {
    pinMode(pin[i],OUTPUT);

  }//end of for loop
}//end of setup


void loop(){
  for(int i=0;i<=9;i++)
  {
    switch(i)
    {
    case 0:
      display_it(ZERO);
      break;

    case 1:
      display_it(ONE);
      break;

    case 2:
      display_it(TWO);
      break;

    case 3:
      display_it(THREE);
      break;

    case 4:
      display_it(FOUR);
      break;

    case 5:
      display_it(FIVE);
      break;

    case 6:
      display_it(SIX);
      break;

    case 7:
      display_it(SEVEN);
      break;

    case 8:
      display_it(EIGHT);
      break;

    case 9:
      display_it(NINE);
      break;

    default :
      Serial.println("something went wrong");

    }//end of switch
  }//end of for loop()
}//end of loop


void display_it(const int value)
{
  for(int i=2,j=0;i<=8;i++,j++)
  {
    digitalWrite(i,bitRead(value,j));

  }
  delay(1000);
}

Proteus Schematic is :









size of Array Vs No of elements in Array

If we wanted to determine the size of array.. the first thought we get is use of sizeof operator.

for the beginner level the size of array means number of elements in array.. which is a false assumptions.

Normally there is so much difference between size of array and number of elements in the array.
lets look at the arduino reference about size of


sizeof :
Description
The sizeof operator returns the number of bytes in a variable type, or the number of bytes occupied by an array.
Syntax
sizeof(variable)
Parameters
variable: any variable type or array (e.g. int, float, byte)
As it says it returns the number of Bytes Occupied by an Array in the Memory 

lets try simple code:

int ex_array[ ] = {1,2}; //define array
int ex_array_length = sizeof(ex_array);//find length using sizeof
void setup(){
Serial.begin(9600);
Serial.print("the value sizeof returns is ");
Serial.println(ex_array_length);
}

void loop(){
//do nothing 
}

The Output is :
the value sizeof return is 4

But the ex_array is having only two elements and the program returns 4.
It means that the array named ex_array[ ] occupied 4 bytes of memory. since int is 16 bits which is equivalent to 2 bytes and two integer variables occupy 4 bytes of memory.

To find the No of elements in Array:
To find number of elements in that array we need to divide the value sizeof returns by sizeof datatype of that array.

so No of elements in array = sizeof(array)/sizeof(datatype of array)


int ex_array[ ] = {1,2}; //define array
int ex_array_elements = sizeof(ex_array)/sizeof(int);//find length using sizeof
void setup(){
Serial.begin(9600);
Serial.print("the number of elements in array is ");
Serial.println(ex_array_elements);
}

void loop(){
//do nothing 
}

The Output is:
the number of elements in array is 2

which solves our present problem...

But if we accidently changed the datatype of array there will be nasty bug if we didn't change the bottom datatype also..

so to avoid that problem we can we something like this
No of elements in array = sizeof(array)/sizeof(first number in array)

int ex_array[ ] = {1,2}; //define array
int ex_array_elements = sizeof(ex_array)/sizeof(ex_arry[0]);//find length using sizeof
void setup(){
Serial.begin(9600);
Serial.print("the number of elements in array is ");
Serial.println(ex_array_elements);
}

void loop(){
//do nothing 
}




Thursday, 28 May 2015

Interfacing Keypad with Arduino

Keypads Play Vital role in Embedded systems as Human Machine Interface devices.
Interfacing Keypad with arduino very easy.. We can find many tutorials on the web explaining how to do it and many of them are based on the Arduino Keypad library and we can find the sketch for our task....

like many arduino People the only language i know is Arduino Language and I don't want to use that library for simple Keypad interface which involves 12 switches (4 rows and 3 cols) cause i don't understand a bit in it. So i try to write a little code without library.

Basically Keypads as consist of Buttons which we can read the state of button with Arduino Digital Pin. when there are lot of inputs to read, it is not feasible too allocate one pin to each one of them. In this situations matrix keypad is useful.

if you consider reading a 25 inputs we can make 5*5 matrix which can implemented using 10 digital pins.

Internal Arrangement of Matrix Keypad is shown in fig.
Initially all switches are assumed to be released and there is no connection between Rows and Columns. when anyone of the switches are pressed the corresponding row and column is short circuited.... using this logic the button press can be detected.

How to write a Program to find the key pressed ?

The One of the technique to Identify the pressed keys are the method called Column Searching.
In This method particular Row is kept low and other rows are held High and logic state of each column line is scanned.

If a Particular is found to be having a state Low then that means that the key coming from in between that column and row.

steps to implement the program :

1.Declare the Row pins and column pins
2.initialize the key strokes with reference to the rows and cols as multidimensional array
3.set pin mode of Row pins to OUTPUTS
4.set pin mode of Column pins as inputs (remember this method is called column searching)
5.using for loop make one row pin Low each time and read the all column pins
6.if digitalRead returns low on col pins find the key using respective row and col numebrs.

The schematic of connections in proteus is

Arduino Code is:
/*
Keypad Interfacing with Arduino Without Keypad Library
 Author : Kunchala Anil
 It is implemented using a method called Column Searching
 */

const int row_pin[] = {
  5,4,3,2}; 
const int col_pin[] = {
  6,7,8}; // defining row and column pins as integer arrays

const int rows = 4, cols = 3; //defining the multi dimensional array size constants 

const char key[rows][cols] = {               // defining characters //for keystrokes in Multidimensional Array
  {
    '1','2','3'  }
  ,   
  {
    '4','5','6'  }
  ,
  {
    '7','8','9'  }
  ,
  {
    '*','0','#'  }  
};

void setup(){

  Serial.begin(9600); //begin the serial communication

  for(int i = 0; i<4; i++)
  {
    pinMode(row_pin[i],OUTPUT); //Configuring row_pins as Output Pins
    digitalWrite(row_pin[i],HIGH);//write HIGH to all row pins

    if(i<3)//we only have 3 columns
    {
      pinMode(col_pin[i],INPUT_PULLUP);//configure column pin as Input and activate internal //Pullup resistor
    }//end of if

  }//end of for loop

}//end of setup


void loop(){
  char key = read_key();
  if(key !='\n'){
    Serial.println(key);
    delay(100);
  }
}//end of loop

char read_key(){
  for(int row = 0;row < 4;row++)
  {
    digitalWrite(row_pin[0],HIGH);
    digitalWrite(row_pin[1],HIGH);
    digitalWrite(row_pin[2],HIGH);
    digitalWrite(row_pin[3],HIGH);
    digitalWrite(row_pin[row],LOW);
    //Serial.println(row_pin[row]);

    for(int col = 0;col<3;col++)
    {
      int col_state = digitalRead(col_pin[col]);
      if(col_state == LOW)
      {
        return key[row][col];
      }//end of if 
    }//end of col for loop
  }//end of row for loop
  return '\n';
}//end of read_key

Note : delay(100) is used to eliminate debounce 




you can see rows are changing the HIGH to LOW and and Low at column side when key is pressed.


Two Arduino's Communication with USART

In following schematic shows the connections to establish communication between two arduino's using Hardware Usart Arduino Uno connected to the keyboard scans the human inputs using keyboard and send the keystrokes as it is to the second arduino which shows the entered data.



Code for arduino connected to the Keypad (Tx) is :
#include <Keypad.h>

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] = { 
  5,4,3,2 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 
  6,7,8 }; 

// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

#define ledpin 13

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

void loop()
{
  char key = kpd.getKey();
  if(key)  // Check for a valid key.
  {

    Serial.print(key);
  }

}

we need arduino Keyboard library to compile the above code, can be found http://playground.arduino.cc/code/keypad

Arduino Connected to the Virtual Terminal(Rx) is:

#define password 123
#include<SoftwareSerial.h>
SoftwareSerial mySerial(10,11);//10-Rx  11-Tx
char data_buffer[15];
boolean read_data = false;
byte index;
void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);
  mySerial.println("welcome");
  mySerial.println("please enter password with starting letter * and ending letter # like *123#");
}

void loop(){

  if(Serial.available())
  {

    char input = Serial.read();
    if (input == '*')
    {
      read_data = true;
      index = 0;
    }
    else if(input == '#')
    {
      data_buffer[index] = 0;
      read_data  = false;
      mySerial.print("the value value you entered is");
      mySerial.println(atoi(data_buffer));
      if (atoi(data_buffer) == password){
        mySerial.println("password Matched");
      }
      else{
        mySerial.println("wrong Password");
      }
    }
    else
    {
      if(read_data)
      {
        data_buffer[index] = input;
        index = index + 1;
      }
    }
  }
}//end of loop

please see the video below to see how the schematic is done