Ардуино keypad 4×4

Урок 13. Подключение клавиатуры 4*4 и пьезоизлучателя к Arduino

Теперь научимся подключать устройство ввода к Ардуине. В этом примере разберемся, как подключить мембранную клавиатуру 4*4

Данный пример будет выполнять две задачи:

  1. Первая задача: определяет, какая из клавиш была нажата на клавиатуре и передать информацию по сериал порту на компьютер, где в «мониторе последовательного порта «.
  2. Вторая задача: при каждом нажатии клавиш издавать звуковой сигнал. У каждой клавиши звуковой сигнал будет разный.

В данном уроке нам понадобится:

Для реализации проекта нам необходимо установить библиотеки:

Сборка:

1) Клавиатуру удобнее всего подключить к Ардуине проводками Папа-Папа.

Контакты на клавиатуре отсчитываются слева на право.

Клавиатура 4*4 Arduino (uno)
Контакт 1 pin 11
Контакт 2 pin 10
Контакт 3 pin 9
Контакт 4 pin 8
Контакт 5 pin 7
Контакт 6 pin 6
Контакт 7 pin 5
Контакт 8 pin 4

Контакты к которым подключаем клавиатуру, могут быть перенастроены на любые другие цифровые контакты. Настраиваются здесь:

2) Звуковой сигнал будет издаваться с помощью зуммера, его подключаем следующим образом:

Зуммер Arduino
GND GND
IO pin 3
VCC 5V или 3V

Контакт Pin3 так же может быть изменен на любой удобный вам цифровой выход. Настраивается здесь:

Скетч:

Теперь, если все подключено и библиотеки установлены, можно приступить к загрузке скетча.

Видео:


Источник

Arduino — Keypad

The keypad is widely used in many devices such as door lock, ATM, calculator.

In this tutorial, we will learn:

Hardware Required

About Keypad

The keypad is a set of buttons arranged in rows and columns (called matrix). Each button is called key

Keypad has various types. Two popular types for DIY projects are keypad 3×4 (12 keys) and keypad 4×4 (16 keys).

Pinout

Keypad pins are divided into two groups: row and column.

Keypad 3×4 has 7 pins: 4 row-pins (R1, R2, R3, R4) and 3 column-pin (C1, C2, C3).

Keypad 4×4 has 8 pins: 4 row-pins (R1, R2, R3, R4) and 4 column-pin (C1, C2, C3, C4).

How It Works

The process of detecting the key pressing is called scanning keypad.

It is called “scanning” because it checks one key by one key.

Row-pins are connected to Arduino’s output pins

Column pins are connected to Arduino’s input pins (INPUT_PULLUP, in this state, the value of the input pin is HIGH if the key is not pressed).

The above is one of the methods to scan keypad. We can invert all HIGH to LOW and all LOW to HIGH to scan keypad.

⇒ As we know, an independent button requires one Arduino’s pin and GND . Let’s take keypad 4×4 as an example. If we each key as an independent button, it requires 16 Arduino pin for 16 keys plus GND pin. If we arranged a connected key in matrix form, we just need to use 8 Arduino’s pin, so we can save Arduino’s pin. In short, the answer is: to save the Arduino pins.

Wiring Diagram

Image is developed using Fritzing. Click to enlarge image

How To Program For Keypad

Thanks to Keypad library, using keypad with Arduino is a piece of cake, no matter whether you understand how the keypad works or not.

Источник

Arduino Keypad 4×4 © Apache-2.0

How to use Arduino Keypad Projects

Keypad with Arduino.

There many kind of keypads in Arduino. So you can use any kind of Arduino keypads.

There are some images of keypad.

Pin Config of 4×4 keypad

You can download code from GitHub

Arduino Keypad 4×4C/C++
Arduino Keypad 4×4

Please log in or sign up to comment.

Author

jehankandt
  • 22 projects
  • 5 followers

Additional contributors

Published on

Members who respect this project

Table of contents

Similar projects you might like

Make Music using Arduino, speaker, 4×4 keypad and a couple of connecting cables. No breadboard needed

Arduino Piano Using 4×4 Keypad

Project tutorial by Adewale Paul

MEGA BREAD series #4, the 4 by 4 input keypad.

MEGA BREAD — 4X4 KeyPad

Project in progress by Pigeon-Kicker

Learn how to make an Arduino-controlled door lock system that uses a keypad!

Arduino Keyless Door Lock System with Keypad and LCD

Project tutorial by DIY Hacking

  • 77,247 views
  • 23 comments
  • 100 respects

Basic and useful 4×4 T9 keypad, to text message.

4×4 T9 Keypad

A simple and funny project with an Arduino UNO and the famous keypad shield. Arduino selects a random number, you guess the number.

Guess the Number with Arduino KeyPad

Tweet from your twitter account using Arduino MEGA, ESP-12E and Keypad via ThingSpeak.

Tweet using Arduino, ESP and Keypad

Project tutorial by STEMpedia

Good to see you again

Or connect with your social account:

Источник

Lesson 20 – 4×4 Matrix Keypad

Note: ALL OSOYOO Products for Arduino are Third Party Board which is fully compatitable with Arduino

Content

Introduction

Keypads are a great way to let users interact with your project. You can use them to navigate menus, enter passwords, and control games and robots.

In this tutorial, I’ll show you how to setup a keypad on the Arduino. First I’ll explain how the Arduino detects key presses, then I’ll show you how to find the pinout of any keypad. As a simple example, I’ll show you how to print out the key presses on the serial monitor and an LCD. Finally, I’ll show you how to activate a 5V relay when a password is entered correctly.

Preparations

Hardware

  • Osoyoo Basic Board (Fully compatible with Arduino UNO rev.3) x 1
  • 4×4 Matrix Keypad x 1
  • I2C 1602 LCD Display x 1
  • Relay x 1
  • Jumpers
  • USB Cable x 1
  • PC x 1

Software

About 4×4 Matrix Keypad

What is keypad?

A keypad is a set of buttons arranged in a block or “pad” which bear digits, symbols or alphabetical letters. Pads mostly containing numbers are called a numeric keypad.

The 4 x 4 matrix keypad usually is used as input in a project. It has 16 keys in total, which means the same input values. It is ultra-thin, easy to interface with any microcontroller and has an adhesive backing for easy mounting for a variety of applications.

Features

  • Ultra-thin design
  • Adhesive backing
  • Excellent price/performance ratio
  • Easy interface to any microcontroller
  • Example programs provided for the BASIC Stamp 2 and Propeller P8X32A microcontrollers

Specifications

  • Maximum Rating: 24 VDC, 30 mA
  • Interface: 8-pin access to 4×4 matrix
  • Operating temperature: 32 to 122 °F (0 to 50°C)
  • Dimensions:Keypad, 2.7 x 3.0 in (6.9 x 7.6 cm) Cable: 0.78 x 3.5 in (2.0 x 8.8 cm)

How it Works

Matrix keypads use a combination of four rows and four columns to provide button states to the host device, typically a microcontroller. Underneath each key is a pushbutton, with one end connected to one row, and the other end connected to one column.

In order for the microcontroller to determine which button is pressed, it first needs to pull each of the four columns (pins 1-4) either low or high one at a time, and then poll the states of the four rows (pins 5-8). Depending on the states of the columns, the microcontroller can tell which button is pressed.

For example, say your program pulls all four columns low and then pulls the 2nd row high. It then reads the input states of each column, and reads pin 3 high. This means that a contact has been made between column 2 and row 2, so button ‘5’ has been pressed.

Applications of 4×4 Matrix Keypad:

  • Password Protected Door Security System.
  • Wired Remote Controlled Robot.
  • Electronic Voting Machine.
  • Generating External Interrupt.
  • Musical Keypad and many more.
  • Multiple DIY Projects.

Examples

Dispaly the pressed button in the Serial Monitor

In this project, we will go over how to integrate a keyboard with an Arduino board so that the Arduino can read the keys being pressed by a user. At the end when all is connected properly and programmed, when a key is pressed, it show up at the Serial Monitor on your computer. Whenever you press a key, it shows up on the Serial Monitor.

Connection

Keypad Pin Connects to mainboard Pin…
1 D9
2 D8
3 D7
4 D6
5 D5
6 D4
7 D3
8 D2

Build the circuit as below:

Code Program

After above operations are completed, connect the Arduino board to your computer using the USB cable. The green power LED (labelled PWR) should go on.Open the Arduino IDE and choose corresponding board type and port type for you project.

Here you visually see all the connections that were written above.Now that we have the physical setup, all we need now is the code. Before you can run this, you have to import the Keypad library and then once you import it, then you can enter it into your program. Once it’s entered into your program, you should see the line #include . If you do not see this, that means that the Keypad library has not been successfully put into your code and it won’t work.

This library is available via the Arduino IDE library manager. If you are using a modern IDE (1.6.2 or above), you can simply use the menu:

Sketch->Include Library->Manage Libraries… Then search for Keypad.

Once found, click on its entry and the install button will appear.

Then load up the following sketch onto your Arduino.

Running Result

A few seconds after the upload finishes, once we press a key on the keypad, it should show up on the serial monitor of the Arduino software.

USING AN LCD WITH THE KEYPAD

Now let’s see how to print the key presses on an LCD. 4X4 keypads use 8 pins . That takes up a lot of pins, so I’m going to use an I2C enabled LCD because it only needs 4 wires to connect to the Arduino.

Connection

Build the circuit as below:

Wiring the I2C 1602 LCD display is pretty straightforward!

Pin Wiring to OSOYOO Basic board
SCL A5
SDA A4
VCC 5V
GND GND

If you’re using other Arduino board rather than the uno, chek out what are their SCL and SDA pins.

  • Nano: SDA (A4); SCL(A5)
  • MEGA: SDA (20); SCL(21)
  • Leonardo: SDA (20); SCL(21)

Code Program

We use an I2C enabled LCD on the Arduino, you’ll need to install the LiquidCrystal I2C library . This library is nice because it includes most of the functions available in the standard LiquidCrystal library. To install it, download the ZIP file, then go to Sketch > Include Library > Add .ZIP Library.

The Wire library is needed to add support for I2C communication. It comes packaged with the Arduino IDE, so there’s no need to install it. But if for some reason it’s not installed on your system, go to Sketch > Include Library > Manage Libraries and search for “wire” to install it.

After above operations are completed, connect the Arduino board to your computer using the USB cable. The green power LED (labelled PWR) should go on.Open the Arduino IDE and choose corresponding board type and port type for you project. Once everything is prepared, upload this code to the Arduino:

Each I2C device has an I2C address that it uses to accept commands or send messages. For Uno board, this address usually is 0x27. But sometimes the address might be changed 0x37,0x24 …., So let’s go and look for the one on your device.

Download ic2_scanner sketch zip file , then unzip and load it into Arduino IDE. By opening up the serial monitor in the upright corner, Arduino will scan the address range looking for a reply. Most Arduino board will show 0x27, however it be other number.

Running Result

A few seconds after the upload finishes, once we press a key on the keypad, it should show up on the I2C 1602 LCD display.

USE A PASSWORD TO ACTIVATE A RELAY

One of the most useful applications of a keypad is to use it for keyed entry. You can set up a password and have the Arduino activate a relay or some other module if the password is correct.

Connection

Build the circuit as below digram:

Code Program

After above operations are completed, connect the Arduino board to your computer using the USB cable. The green power LED (labelled PWR) should go on.Open the Arduino IDE and choose corresponding board type and port type for you project.

The following code will activate a 5V relay when the password is entered correctly, load it to your Arduino board.

You can change the password on line 10 by replacing the 123A456 text with your own password:

The length of the password needs to be set on line 5:

The password in the example above is only 7 characters long, but the password length is actually one greater than 7 because there is a null character added to the end of the string. For example, if your password is 5 characters long, you would enter 6 for the password length.

The output pin that activates the relay is defined on line 7:

Running Result

A few seconds after the upload finishes, if you enter the correct password, the relay will be activated.

Troubleshooting

1. You can pretty much connect your keypad to any pins you would like. Be careful not to use the serial pins (0 and 1) if you are using them for communication.

2. If key presses seem to take a long time to show up then you are probably using long delay()’s in your code. The same thing can happen if you use too many small delay()s like delay(10).

3. Make sure you understand the pin mappings and have the keypad wired up to match. If you wired the pins incorrectly (and already soldered them in) then you may be able to fix it by redefining the pins and/or keymap to make your keypad work.

Источник

Adblock
detector