Send Input from Keypad to Serial Monitor
Last updated May 2019
Introduction
Welcome to ProteShea – in this tutorial, you’ll learn how to send inputs from a keypad to a serial monitor with the Arduino Uno. This project represents a simple form of a human machine interface (HMI), but hey you have to start somewhere! An extra benefit to using Arduino’s IDE is that it already has a built-in serial monitor, so no extra downloads are needed.
Disclaimer
ProteShea, LLC is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Some links may be affiliate links, in which ProteShea, LLC earns a commission if you use that affiliate link. Please note that this is at no additional cost to you and helps us in creating more content.
Here’s what you’ll need to get started:
- FuelCan
- Modulus or solderless breadboard
- 1.2k ohm resistor array from the Modulus Kit
- Arduino Uno Rev3
- 16-key matrix keypad
- 8″ M/M jumpers
16-Key Matrix Keypad
Please see Arduino Uno Project 2 to learn more about the 16-key keypad layout and circuitry.
Serial Terminal
The serial terminal is useful when you want to send serial data to and from your computer and Arduino. It uses a UART (Universal Asynchronous Receiver/Transmitter) protocol which consists of two wires, a transmit (Tx) and receive (Rx) line. There is a start and stop bit to define the beginning and end of the data packet being sent or received. You can configure the baud rate which is the transmission speed of the data. Typically, you see baud rates such as 1200, 2400, 4800, 9600, 19200, 38400, 57600, and 115200. To ensure that you have a successful communication link, both devices that are communicating with each other must be set to the same baud rate. Otherwise, one device will sample the data either too fast or too slow, resulting in corrupt data.
For example, if you set the baud rate on one device to 9600, the other device it is communicating with must also be set to 9600. To set the Uno’s baud rate, we can leverage the function Serial.begin(). All you have to do is pass in the baud rate as the argument. For the example above, we would use Serial.begin(9600).
To open up the Serial Monitor in the Arduino IDE, click on Tools -> Serial Monitor as shown in the image below.
Once the Serial Monitor opens up, we have to specify the baud rate which is located in the bottom-right corner of the window. In the top-left corner, you will see which COM port it is connected to. Make sure this port is set to the one that your Uno is connected to.
The serial terminal is a half-duplex system which means that it can transmit and receive data, but not simultaneously. For example, while we are transmitting data from the computer to the Uno, we can not receive data from the Uno.
Wiring
I’m using a breadboard instead of Modulus to mount the keypad and resistor array.
Place the 1.2k ohm resistor array as shown in the image below. Tie pin 1 of the array to GND, and make sure it does not connect to any of the pins on the keypad. The breadboard holes outlined in blue-grey will be tied to Uno pins 2-5. For example, pin 1 (column 1) on the keypad will be wired to Uno pin 2, pin 2 (column 2) on the keypad will get wired to Uno pin 3, and so on. The breadboard holes outlined in yellow get routed to Uno pins 6-9. For example, pin 5 (row 1) on the keypad will be wired to Uno pin 6, pin 6 (row 2) on the keypad will get wired to Uno pin 7, and so on.
FuelCan Setup
I placed the breadboard in the bottom storage compartment to limit the length of the jumper wires and mounted the Arduino Uno to the FuelCan’s prototyping area. We need to supply GND to the ground rail on the breadboard. Use the provided banana jack to test-lead clip cable to do so. You will need one male header pin to mount the test-lead clip to the breadboard side. Plug the Type A side of the USB cable into the USB1 receptacle and the Type B side into the Uno’s receptacle, as shown in the animation below. There is a UART-to-USB chip on the Uno so the serial data will get sent through the USB cable. Plug in the Type A to Type A USB cable into a USB port on your computer and the external USB connector of the FuelCan. Power up the FuelCan with the AC-DC power adapter.
For additional information about the Fuelcan-910, click here or download the user guide.
Software
Once the wiring is complete and the FuelCan is powered up, we can now load the sketch onto the Uno. The sketch is below. If you do not have the Serial Monitor open, go ahead and open that and make sure that the baud rate is set to 9600. Press each key on the keypad and watch as it displays the key pressed on the serial terminal. If you notice that the number or letter gets displayed twice, you can increase the delay to add more time for the switch to settle.
About Author
Eric Shea is the founder of ProteShea and is an electrical engineer. He wishes to have a major impact on bridging the gap between engineering theory and real-world applications. He has worked at Kratos Defense, SpaceX, Air Force Research Laboratory, and Polaris Industries. He received a M.S. in electrical engineering from the University of Pittsburgh and a B.S. in electrical engineering from the University of Florida.
Categories
About Author
Eric Shea is the founder of ProteShea and is an electrical engineer. He wishes to have a major impact on bridging the gap between engineering theory and real-world applications. He has worked at Kratos Defense, SpaceX, Air Force Research Laboratory, and Polaris Industries. He received a M.S. in electrical engineering from the University of Pittsburgh and a B.S. in electrical engineering from the University of Florida.