How to build and control an LED on an Arduino using a keypad switch:
by J.B. Wylzan
Project 17: Arduino Keypad Basics
This tutorial shows how to connect a Membrane Switch Keypad to an Arduino Board to control an led. The input of pressing a key is posted as output on a serial monitor.
ROW1 - Arduino pin 4
ROW2 - Arduino pin 5
ROW3 - Arduino pin 6
ROW4 - Arduino pin 7
COL1 - Arduino pin 8
COL2 - Arduino pin 9
COL3 - Arduino pin 10
Block Diagram:
Hardware:
1 Keypad; 4x3 Matrix
connecting wires
Arduino R3 UNO board
Code # 17:
/*
iHacklab Membrane Switch Keypad
powered by Arduino
modified by Lawsinium
Note: Keypad Library for Arduino
Authored by Mark Stanley, Alexander Brevig
Downloaded from http://playground.arduino.cc/Code/Keypad
Reads keypad input where output projected on Arduino Serial Monitor
The example code is public domain.
*/
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'#','0','*'}
};
byte rowPins[ROWS] = {4, 5, 6, 7}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 9, 10}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
}
void loop(){
char key = keypad.getKey();
if (key != NO_KEY){
Serial.println(key);
}
}
Challenge: Us the number 9 to turn On all four Leds and number 0 to turn OFF all four leds.
Procedure:
1. Build the prototype as shown above
2. Run the Arduino Interface
3. Select File > New
4. Copy Code #17 above
5. Paste Code #17
6. Click File > Save
7. Click Verify
8. Click Upload
9. Open the Arduino Serial Monitor
10. Press any key and that number is posted on your serial monitor.
Disclaimer: We shall not be liable for any loss or damage of whatever nature - direct, indirect, consequential, or otherwise - which may arise as a result of your use of any information on this website. However, if you are interested in using any of the projects for personal or educational purposes, please inform the author by email.
Public Domain Notice: Copyright (c) 2000. All rights reserved. This article is part of a book entitled iHackRobot. Copies are welcome to be shared or distributed publicly as long proper citations are observed. Please cite as follows: Biotronics: The Silver Species, Joey Lawsin, 1988, USA.
==================================================================
Patent Pending. 2000 © ®
A L.A.W.S.I.N. Educational Production
No comments:
Post a Comment