Controlling LED In Keypad App By Android App

Introduction

In this article, I am going to explain about controlling the LED in Keypad app by an Android app. It will be run in  a real time process for the home application.
 
Software Requirement
  1. Arduino Uno
  2. Leds
  3. Bread Board
  4. Hook Up Wires 
Connection from Arduino Board to LEDs

 Leds  Arduino Board
 Led1  11
 Led1  12
 Led1  13
 Led1  14
 
Programming
  1. #define CUSTOM_SETTINGS  
  2. #define INCLUDE_KEYPAD_SHIELD  
  3. /* Include 1Sheeld library. */  
  4. #include <OneSheeld.h>  
  5. int A, B, C, D; //vaiables with names of buttons in keypad  
  6. /* A name for the LED on pin 8. */  
  7. int yellow = 8;  
  8. /* A name for the LED on pin 9. */  
  9. int green = 9;  
  10. /* A name for the LED on pin 10. */  
  11. int white = 10;  
  12. /* A name for the LED on pin 11. */  
  13. int red = 11;  
  14.   
  15. void setup()  
  16. {  
  17.   /* Start communication. */  
  18.   OneSheeld.begin();  
  19.   /* Set LEDs as output. */  
  20.   pinMode(yellow, OUTPUT);  
  21.   pinMode(red, OUTPUT);  
  22.   pinMode(green, OUTPUT);  
  23.   pinMode(white, OUTPUT);  
  24. }  
  25.   
  26. void loop()  
  27. {  
  28.   Keypad.setOnButtonChange(&lightLed);  
  29. }  
  30. void lightLed (byte rowNumber , byte coloumnNumber)  
  31. {  
  32.     /* If keypad's button A is pressed. */  
  33.   if(Keypad.isRowPressed(0) && Keypad.isColumnPressed(3))  
  34.   {  
  35.     A = 1; // press A   
  36.     B = 0;  
  37.     C = 0;  
  38.     D = 0;  
  39.   }  
  40.     
  41.   else if(Keypad.isRowPressed(1) && Keypad.isColumnPressed(3))  
  42.   {  
  43.     A = 0;  
  44.     B = 1;// press B  
  45.     C = 0;  
  46.     D = 0;  
  47.   }  
  48.     
  49.    else if(Keypad.isRowPressed(2) && Keypad.isColumnPressed(3))  
  50.   {  
  51.     A = 0;  
  52.     B = 0;  
  53.     C = 1;  // press c  
  54.     D = 0;  
  55.   }  
  56.   
  57.    else if(Keypad.isRowPressed(3) && Keypad.isColumnPressed(3))  
  58.   {  
  59.     A = 0;  
  60.     B = 0;  
  61.     C = 0;  
  62.     D = 1; // press D  
  63.   }  
  64.   else  
  65.   {  
  66.     /* Turn off all of LEDs. */  
  67.     digitalWrite(yellow,LOW);  
  68.     digitalWrite(green,LOW);  
  69.     digitalWrite(white,LOW);  
  70.     digitalWrite(red,LOW);  
  71.   }  
  72.   if(A) //press button A  
  73.     digitalWrite(yellow, HIGH);  
  74.   if(B) //press button B  
  75.     digitalWrite(green, HIGH);  
  76.   if(C) //press button C  
  77.     digitalWrite(white, HIGH);  
  78.   if(D) //press button D  
  79.     digitalWrite(red, HIGH);  
  80. }  
Explanation

According to the connection, upload program to the board and download the keypad app in the Playstore, install, and see the result. In the LEDs, when you press the 1 key, it is switched ON. Similarly, the other LEDs also get turned ON and OFF by the keypad app, without bluetooth.
 
Output

image

Next Recommended Readings