obligatory obscure reference

self-deprecating yet still self-promotional witty comment


Arduino, Boolean logic, and the magic of “vintage” logic chips

Filed under: Arduino — jet @ 20:09

Two things this time around. The first is advocacy for learning Boolean logic, the second is an example of how to use a somewhat obscure chip to solve a common problem found in Arduino projects.

First off, the advocacy.

If you don’t know it already, spend some time over the next few evenings learning the basics of Boolean logic. I’m not talking about binary numbers, I’m talking about the actual logic used by chips to manipulate the bits that make up a binary number. (Don’t sweat the Boolean algebra, just stick with the easy logic stuff for now.) There are a lot of basic tutorials on the net, I like this one even though it uses Comic Sans. Once you get your head around the basics, you’ll be able to solve some of your problems with chips instead of Arduino code.

Here’s an example I’ve seen plenty of times in the lab: Someone is doing a simple Arduino project, and they want to read multiple switches. Maybe they have four switches and they don’t care which one is closed, only that one (or more) is closed. Or maybe they have tw switches and they only want to know when both of the switches are closed at the same time. If you’re unfamiliar with Boolean logic, you’re probably going to put each switch on its own pin then try to read them in some clever fashion in your Arduino script.

Alternatively, you could use a chip that implements Boolean logic, wire your switches to that, then wire the chip to your Arduino.

In the first case, where you have four switches and you don’t care which one is pressed, you could use a chip that implements “OR”, like the 74LS32. It has 4 OR gates, each with two inputs. Hook two switches each up to two of the OR gates, then hook the outputs of those two OR gates to a third, and the output of that to a single pin on your Arduino. You’ve just implemented, “if switch1 or switch2 or switch3 or switch4 then true” in hardware instead of trying to write a clever Arduino script. You’ve also used only one pin on the Arduino instead of four, which can be a really big deal on complex projects.

In the second case, where you want to know when both switches are closed, you’d hook them to a “AND” gate and run the output of that to your Arduino. In this case, you’ve implemented “if switch1 AND switch2 then true” and saved yourself a pin on the Arduino in the process.

Ok, so how do you find out which chip does what you want? There are endless catalogs of spec sheets on the net (hint: search for “TTL databook”) and if you go to a major component vendor or octopart you might get lucky just typing in what you want, like “4 gate OR” then look at the data sheets for the results. Also, chip vendors often produce huge printed catalogs of their chips or post PDFs on their websites. I find these useful for thumbing through while waiting on my coffee, as I often discover a chip that I would never have thought to look for but that solves some sort of problem I’ve had in the past.

[edit: yes, you can do the examples without chips, but I wanted a simple example to show how Boolean logic can be implemented in hardware instead of software.]

And now, an example of how browsing chip catalogs can be useful.


1 Comment »

  1. Why bother with logic chips in your example of switches? For the ‘or’ example just wire the switches in parallel. If any one of them is closed you’ll bypass the pullup/pulldown resistor and get the new state. For the ‘and’ example wrire the switches in series. Each one of them will need to be pressed to change the logic state.

    Comment by adam — 2009/10/30 @ 23:20

RSS feed for comments on this post.

Leave a comment

Powered by WordPress