Connect a 4×3 matrix keyboard to a microcontroller using two I/O pins

- May 8, 2013

This is a repost from EDN Magazine's Design Ideas

Matrix keyboards are common as an input device in microcontroller-based projects. A conventional way of connecting a matrix keyboard to a microcontroller is to use multiple I/O pins of the MCU. The MCU then uses a scanning algorithm to identify which keys are pressed. A drawback of this method is that it requires a large number of the MCU’s I/O pins to connect the keyboard. For example, to connect a 4×3 keyboard requires seven digital I/O pins. This becomes a problem when the project is based on a low-pin-count MCU or when the MCU being used does not have enough free I/O pins.

Two solutions for this issue are available: Use readily available I/O expanders, or assign a unique voltage to each key using a resistor network and then use an analog pin to read the voltage and determine which key is pressed. Each solution has its own disadvantages.

Since most of the time I/O expanders require a special communication protocol (I2C or SPI, for example) to read and write data, the MCU should have built-in communication modules, or the user has to implement the relevant communication-protocol software wisely, which adds significantly to the overhead of the MCU. On the other hand, assigning a unique voltage to each key using a resistor network becomes troublesome as the number of keys becomes high, which will lead to tight voltage margins. Then, as resistor values tend to change with temperature, the use of tight voltage margins can cause incorrect readings. Even switch bouncing can play a major role in producing incorrect voltages with this method. Another major drawback of this method is that it requires the presence in the MCU of an analog input pin.

Read more: Connect a 4×3 matrix keyboard to a microcontroller using two I/O pins

Discuss this article in the forums (0 replies).

From EDN: One I/O line drives shift register with strobe

& - March 28, 2013

This is a repost from EDN Magazine's Design Ideas.

This Design Idea shows how a single microcontroller port can drive a lot of output lines through shift register. In this case we use the shift register with strobe control to achieve perfect output line control.

Shift register outputs can drive LEDs, relays, etc. In other words, they can be used as (additional) general purpose outputs.

Today there are shift registers that have DATA and CLOCK inputs only, like 74HC164, and shift registers with same inputs plus STROBE control input, like 74HC4094 or 74HC595. The shift registers without STROBE control have short-term transient states at outputs during shifting. Transients occur because shift register is directly connected to output lines. This kind of shift register can be used for driving LEDs and similar devices where short-term transient is irrelevant. For example, the human eye can't notice LED flickers shorter than 10 msec. The shift registers with STROBE control have two registers.

Read more: From EDN: One I/O line drives shift register with strobe

Discuss this article in the forums (0 replies).

Color Maximite Computer

I saw reference to the Color Maximite single board computer in Circuit Cellar Magazine and am impressed enough to share it here.  Like desktop computers of old, it has a Basic interpreter built in, along with monitor and keyboard support and an SD card " floppy drive."  The unique feature is that it supports ubiquitous Arduino shields along with I2C, SPI and a number of port pins.  Not bad for $50..  Check out Circuit Gizmos web page for some interesting products.  The description below is from their website.

CGCOLORMAX2  - Color Maximite

Color Maximite-type computer/controller with serial circuit support and prototype area


CGCOLORMAX2 - Color Maximite
US dollar
In stock

CircuitGizmos Color Maximite

Read more: Color Maximite Computer

Discuss this article in the forums (4 replies).

What's in an SD card?

sd1What's actually inside an SD card?  I'll bet you've wondered that, but never actually got round to finding out?

I'm sure you've all seen the insides of a USB memory stick - a bunch of chips on a PCB, nothing surprising there.  But what about an SD card?  Considerably slimmer than a USB key they must be going some to fit the chips you'd expect into it.

Well, since the Raspberry Pi handilly blew up an SD card for me, I thought it was about time to rip one apart and see what it's actually made up of.  Well, it contained one or two surprises I must say.  Actually one big surprise.

Read more: What's in an SD card?

Discuss this article in the forums (3 replies).

Simple Circuit Tests Twisted-Pair Cables - Try 2

An EDN Design Idea - Originally published in the May 29, 1986, issue of EDN

Mark D Braunstein, Contel Information Systems, Fairfax, VA; Edited by Paul Rako and Fran Granville - January 19, 2012

Using the system shown in below, you can quickly test a cable containing twisted-wire pairs and detect open or reversed pairs, shorted pairs, and shorts between unrelated pairs. The tester consists of an active test set that plugs into one end of the cable, and a passive terminator that plugs into the other end. (An RS-449 cable is used as an example.)

EDN Cable Tester
A battery or a dc supply delivers 15 to 24V to the test set. The voltage regulator (IC1) is connected as a current regulator to supply a nominal 25 mA to the LED strings at each end of the cable. The cable in this example contains eight twisted pairs, and for a good cable, all eight LEDs in the test set (DA through DH, which are series-connected segments of a bar-graph display) and all eight LEDs in the terminator (D1 through D8) will light. If a twisted pair is open or reversed, the corresponding LED on the terminator will be extinguished; if a pair is shorted, corresponding LEDs at both ends will be extinguished; and if any two unrelated wires of different pairs are shorted, all intervening LEDs in the strings at both ends will be extinguished. For example, if pins 4 and 6 are shorted, LEDs DA, DB, D1, and D2 will not light.

You can add a heat sink to the IC1 regulator as a safety precaution, but normal tester operation is well within the regulator’s power-dissipation limits. Even with many shorted pairs, a dissipation of 700 mW would cause no more than 60°C junction temperature, and the IC is guaranteed to turn itself off at 160°C. The complete tester costs less than $50 to build.

Simple Circuit Tests Twisted-Pair Cables

This circuit should prove useful to anyone using multi-pair cables.  The idea would work well for an RJ-45 network cable tester.


Discuss this article in the forums (3 replies).

Control an LM317T with a PWM signal

An EDN Design Idea

Aruna Prabath Rubasinghe, University of Moratuwa, Moratuwa, Sri Lanka; Edited by Martin Rowe and Fran Granville - February 3, 2011


Control an LM317T with a PWM signal figure 1The LM317T from National Semiconductor is a popular adjustable-voltage regulator that provides output voltages of 1.25 to 37V with maximum 1.5A current. You can adjust the output voltage with a potentiometer. The circuit in Figure 1 replaces the potentiometer with an analog voltage that you can control from a PWM (pulse-width-modulation) signal. You control this signal with a microcontroller or any other digital circuit. You can use the same microcontroller to dynamically monitor the output and adjust the LM317T.

Using an RC lowpass filter and an op amp, you can convert the PWM signal to a dc level that can adjust the LM317T’s voltage output. Varying the pulse width of the input signal lets you generate an analog voltage of 0 to 5V at the output of the lowpass filter. The op amp multiplies the voltage to achieve the desired voltage range.

For scenarios in which you must multiply the input voltage by two, the LM317T’s adjustment pin receives 0 to 10V. Its output-voltage range is 1.25 to 11.25V. The equation VOUT=VADJ+1.25V governs the LM3175T’s output voltage. You can change the op amp’s gain by choosing proper values for R4 and R2. You must be able to remove offset voltages from the op amp. Use an op amp, such as a National Semiconductor LM741, with null adjustment. The selection of values for the capacitor and resistor for the RC lowpass filter depends on the PWM signal’s frequency. This circuit uses values for a 1-kHz PWM signal.

You can improve the circuit by replacing the RC lowpass filter with an active filter and then feeding a feedback signal from the circuit’s output into the microcontroller for dynamic adjustments.

Comments to this article at EDN suggest that the LM741 op amp is not an ideal choice for this circuit; a better choice would be a rail-rail op amp.

 Control an LM317T with a PWM signal

Discuss this article in the forums (2 replies).

Wow! A Scientific Calculator From The Dollar Store

teaserYou may have seen the ads for The Dollar Store.  How much is this flower arrangement?  One Dollar.   How much is this tea kettle?  One Dollar.  How much is this package of light bulbs?  ONE DOLLAR.  How much is this 56 function, 10 digit scientific calculator?  ONE DOLLAR.  EVERYTHING IN THE STORE IS ONE DOLLAR.

I'm dating myself to say my first "real calculator" was a Texas Instruments SR-50A, slightly newer than the SR-50 shown here.  It had a price tag of around $170 35 years ago.  Nice red LED display, many functions and a rechargeable battery that would last all day provided I remembered to plug it in.  i had a few moments of panic in college when I had forgetten to recharge the night before a test!


Read more: Wow! A Scientific Calculator From The Dollar Store

Discuss this article in the forums (2 replies).


thumb mramHands up any of you that have heard of MRAM?  That's "Magneto-Resistive Random Access Memory", by the way.

MRAM is set to blow the socks off the microcontroller world, or my name's not Felicity Kendall.  Until recently I didn't even know they were actually commercially making this stuff yet, but it turns out they are.

But, what is Magneto-watsit thingummyjig?  Simply put, it's RAM that uses a magical combination of magnetism and resistance to store data.  Now, I'm not going to even pretend to know how it works, so here's my friend Wikipedia to explain it:

Read more: MRAM Joy

Discuss this article in the forums (4 replies).

Site Migration Complete

Just a quick message to let everyone know that the site migration is complete. We are now on SSD hardware and double the processing power.

If you are viewing this message from facebook / twitter / RSS and the link takes you to an offline page then your DNS settings are old. Either wait a few hours or try using Google public DNS.

Enjoy and please report any issues via the feedback page.

Discuss this article in the forums (3 replies).

Using Optical Switches

breadboard -300Applying micro controllers to the real world often involves sensing motion, position or the proximity of objects.  A very simple sensor is the optical switch consisting of an IR LED emitter and an IR-sensitive phototransistor.  These can be arranged to detect directly transmitted light (photo interrupter) or the reflection of light (proximity detector) and they can be packaged into a self-contained sensor or used as separate emitter / receivers.  The photo below shows an interrupter type and a proximity detector type that may be purchased for less than a buck a piece.

Read more: Using Optical Switches

Discuss this article in the forums (10 replies).

Forum Activity

Member Access