Arduino Program to Identify Pressed Keys of a Mobile Phone (Part 2 of 2)

<<<< Read Previous Part (Part 1)

Circuit is given in my previous part. After completing the circuit, upload the following program to your arduino board. If uploading is successful, open your serial monitor. Serial monitor will print the binary coded decimal corresponding to each keys.

int Q4 = 10; // Q4 of MT8870D is connected to Digital Pin 10 of Arduino
int Q3 = 11; // Q3 of MT8870D is connected to Digital Pin 11 of Arduino
int Q2 = 12; // Q2 of MT8870D is connected to Digital Pin 12 of Arduino
int Q1 = 13; // Q1 of MT8870D is connected to Digital Pin 13 of Arduino

int key_number=0;

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  // make the digital pins inputs:
  pinMode(Q1, INPUT);
  pinMode(Q2, INPUT);
  pinMode(Q3, INPUT);
  pinMode(Q4, INPUT);

// the loop routine runs over and over again forever:
void loop() {
  // read the input pin:
  int read_from_Q1 = digitalRead(Q1);   // Read data from Q1
  int read_from_Q2 = digitalRead(Q2);   // Read data from Q2
  int read_from_Q3 = digitalRead(Q3);   // Read data from Q3
  int read_from_Q4 = digitalRead(Q4);   // Read data from Q4
  key_number = (read_from_Q4 * pow(2,3)) + (read_from_Q3 * pow(2,2)) + (read_from_Q2 * pow(2,1)) + (read_from_Q1 * pow(2,0));
  Serial.print("Binary of key number :");  
  Serial.print(" ");
  Serial.print("Key pressed is :");
  Serial.println(" ");
  key_number = 0;

Output displayed in the serial monitor is given below. Number pressed in the mobile phone will be displayed in the serial monitor of arduino.

Screenshot from 2015-07-05 14:31:31

Watch the video demonstration here.

Next : Police siren, ambulance siren, fire engine siren and machine gun sound using UM3561 >>>>

(Visited 1,003 times, 1 visits today)
A deep electronic enthusiast who spent most of my time for electronic experiments. I am also interested in publishing my experiments in my blog for helping other electronics enthusiasts.