Multiplexer: how does it work and how can i make one?

Hi
Im new to Arduino and soldering electronics, but id like to learn more about it, because we have to make an installation using electronics, as a school project.
Now, we would like to make some sort of pressure sensitive floor, using Piezo sensors (pressure sensors).
To cover the floor we would need about 200 Piezos, which obviously doesnt fit on an Arduino board. (we use the Arduino Diecimila at school).

Now, i talked to one of my teachers and he said that we would have to make a matrix so we can send all the data to the arduino.
So, after searching a bit, i found some examples with led matrixes, but couldnt quickly find how to make one and how they work.
And that, is the reason is why i made this topic:
Can someone explain to me how a matrix works, and how to make one?

Thanks in advance!

I found this in a few seconds using Google. I searched for 'keyboard matrix'. Keyboard Matrix Help

Don

Thanks for that, it is kind of helpful.
But I would like to know more about how to make such a thing, like photos maybe? Because I honestly don't understand how you make such a matrix.

Also, I know this might sound stupid, but I also don't understand how such a matrix would work, because what is the difference between a matrix and lots of sensors?
I know what a matrix does, but not how it does it, does that make sense?

A matrix in one sense is a grid of wires laid out looking like a tile floor.
The vertical lines are one set ogf wires, the horizontal lines are another set.
What you are looking to is sense when one wire is pressed against another at an intersection.
Similary you might have an LED at each intersection, with a high on one wire and a low on the other to turn on a particular LED.

In your case, what you are really after is how to read a bunch of discrete pressure points. In which case what you really need to do is make a big electronic switch that can select a switch at a time and see if it is pressed. You are taking many inputs and multiplexing them down into 1 input. You can design it to capture/read 1 at a time (example you have a bank of CD4067 type chips with 16 inputs each, you select 1 of 16, read it, select the next read it etc. After all 16 are read, you enable the next CD4067 and start the next group of 16), you can design it to capture all at once and serially shift them in to see which changed (for example a bank of parallel-in/serial-out shift registers, send out a clock pulse to capture the state of all sensors at one time, then shift in the 200 BITs to see what you captured.) Or a combination, 16 muxes (196 signals) feeding a bank of 2 shift registers: Select address 0 for all 16 Muxes, clock the data into the 2 shift registers, shift in 16 bits & act. Select address 1, clock the data into the 2 shift registers, shift in 16 bits & act. Repeat 14 more times.

What you described is indeed what I am looking for.
I would like to check all of the sensors at once, because multiple sensors can be pressed at once.
Also, because I want to use Piezo sensors/elements which can measure pressure, they need to be monitored constantly.

But I have no idea how to make such a multiplexing device or setting.

Also, what is that CD4067 chip you are talking about?

Go google CD4067 and download its datashee, and browse the forum - I quite recently posted a schematic for scanninng 32 inputs using the same chip.

I described several methods above - you will have to be more clear about which method you are interested on. Setting up the hardware is pretty straightforward, what you do when you detect a closure will be the interesting part.

Here is one the methods, the one I seemed to discuss the most.

Ok, that doesnt seem so complicated.
So basically what I do, is I lay down my grid of Piezo Sensors, and connect each set of 16 with this array?
So if I would like to do this for 100 Piezo Sensors, I'd have to put down 6 of these chips.

Now, I still have a few questions:
What are those "4 Adress Select Lines"? Where do they come from?

No, not complicated at all. Just reading the state of the switches.
The 4 address select lines and the enable line come from the arduino.
You could have them come from a shift register also - but that typically needs 3 pins, so doesn't gain you much.
Same for the '165s control lines.

But what are those address select lines? Are they digital input/output?
Also, I tried googling it, but what is a Shift Register?

Address select lines are digital outputs.
Shift Register: 74HC595.

Let's see if I get it:
The piezo sensor sends an analog signal to the Multiplexer.
The Multiplexer captures this, and the other signals.
Then the Multiplexer sends a signal out via de Adress Select Lines?
And what signal goes into the Shift Register? (why isn't that also a Multiplexer?)

That is not it.

The multiplexers are a big switch.
The Common I/O line is connected to one of the I/O lines when the Enable line is active (high or low, need to look it up on the datasheet). The address lines ABCD select which one is connected. The arduino will create those addresses and control the enable line.
The shift register will then store the state of the selected I/O line when its Load line is active. For a '165 type part, that happens when the Load line is low and goes high (pin 1 for 74hc165).
The clock line is driven by the shift-in command to bring the data into the arduino.

So what you doing is this:
enable the multiplexers (can be enabled all the time for this use)
for (address_bit_d = 0 to 1)
for (address_bit_c = 0 to 1)
for (address_bit_b = 0 to 1)
for (address_bit_a = 1 to 1)
digitalwrite (address_bit_a)
digitalwrite (address_bit_b)
digitalwrite (address_bit_c)
digitalwrite (address_bit_d)
// address is now setup, piezo sensor state goes thru the multiplexer to the shift register input
// activate the shift register latch
// shift in the data:
shiftIn(dataPin, clockPin, bitOrder)
next address_bit_a
next address_bit_b
next address_bit_c
next address_bit_d

so you have 4 loops within loops controlling the address lines, and reading in the data.
If the piezo sensors are not putting out good digital data, then maybe you will have to read them in analog input pins instead - with 6 4051s, you can use 6 analog inputs.
Or run them thru another analog mux as you noted above.
You said the sensors are on the floor, so I am thinking you will have relatively slowly changing outputs that could look digital.

Now, we would like to make some sort of pressure sensitive floor, using Piezo sensors (pressure sensors).

A Piezo sensor does not measure pressure. It turns the differential of the sensor deformation into voltage.
That means as you stand on it you get a signal, as you continue to stand on it the signal goes away and is the same as a sensor not being stood on.
Are you sure this is what you want?
You can get force sensitive resistors.
http://www.sparkfun.com/products/9375
but buying 200 will cost some.
You can make your own using conductive foam:-
http://www.thebox.myzen.co.uk/Hardware/MIDI_Footsteps.html
I think you will have to scale your ambition down, making those 16 took me long enough.

CrossRoads:
That is not it.

The multiplexers are a big switch.
The Common I/O line is connected to one of the I/O lines when the Enable line is active (high or low, need to look it up on the datasheet). The address lines ABCD select which one is connected. The arduino will create those addresses and control the enable line.
The shift register will then store the state of the selected I/O line when its Load line is active. For a '165 type part, that happens when the Load line is low and goes high (pin 1 for 74hc165).
The clock line is driven by the shift-in command to bring the data into the arduino.

So what you doing is this:
enable the multiplexers (can be enabled all the time for this use)
for (address_bit_d = 0 to 1)
for (address_bit_c = 0 to 1)
for (address_bit_b = 0 to 1)
for (address_bit_a = 1 to 1)
digitalwrite (address_bit_a)
digitalwrite (address_bit_b)
digitalwrite (address_bit_c)
digitalwrite (address_bit_d)
// address is now setup, piezo sensor state goes thru the multiplexer to the shift register input
// activate the shift register latch
// shift in the data:
shiftIn(dataPin, clockPin, bitOrder)
next address_bit_a
next address_bit_b
next address_bit_c
next address_bit_d

so you have 4 loops within loops controlling the address lines, and reading in the data.

Ok, I get the part about the abcd bits, but i still dont understand what those address lines are...
What kind of data do they send to the arduino?

CrossRoads:
If the piezo sensors are not putting out good digital data, then maybe you will have to read them in analog input pins instead - with 6 4051s, you can use 6 analog inputs.
Or run them thru another analog mux as you noted above.
You said the sensors are on the floor, so I am thinking you will have relatively slowly changing outputs that could look digital.

Well, the piezo sensors are not putting out digital data at all, just an analog signal: voltage
As for the change, that is what we want to measure: the force/speed used to "press" the sensor.

Grumpy_Mike:

Now, we would like to make some sort of pressure sensitive floor, using Piezo sensors (pressure sensors).

A Piezo sensor does not measure pressure. It turns the differential of the sensor deformation into voltage.
That means as you stand on it you get a signal, as you continue to stand on it the signal goes away and is the same as a sensor not being stood on.
Are you sure this is what you want?
You can get force sensitive resistors.
Force Sensitive Resistor 0.5" - SEN-09375 - SparkFun Electronics
but buying 200 will cost some.
You can make your own using conductive foam:-
MIDI Footsteps
I think you will have to scale your ambition down, making those 16 took me long enough.

Well, basically what we want is a floor made of buttons, simply said.
But we want to measure the speed/force used to press these buttons, where Piezo elements are supposed to be perfect for. (however, I didnt manage to get it working yet, and i think the problem is my arduino board)
Also, we have a €100,- budget from school to make this project, and we already checked, and those Piezo sensors will fit inside this budget. Note that we only need about 100, not 200. (we changed it a bit)
And yeah, it is ok that the signal dies when you arent standing on the island anymore, and actually, that is exactly what we want :slight_smile:

PS: i modified the topic title, it seems more suited like this

it is ok that the signal dies when you arent standing on the island anymore,

Yes but I also said that the signal dies when you continue to stand on it, it is only at the moment of impact you get a signal.

we want to measure the speed/force used to press these buttons

That means you need an analogue measure. That will be hard even with the reduced number of sensors because you won't have time to scan them all in the time the signal lasts, so you might miss some.

Using Piezo sensors is not the way to do this project if you want it to work. I fear you have underestimated the difficulty of your task.

The address lines are created by the arduino to select which signal is going thru the multiplexer.

How quickly do you expect these sensors to be pressed? 10,15 at a time? Or just 1 person walking around?

Grumpy_Mike:
Yes but I also said that the signal dies when you continue to stand on it, it is only at the moment of impact you get a signal.
That means you need an analogue measure. That will be hard even with the reduced number of sensors because you won't have time to scan them all in the time the signal lasts, so you might miss some.
Using Piezo sensors is not the way to do this project if you want it to work. I fear you have underestimated the difficulty of your task.

I know, but this is what we want.
We have also considered the contact sensor you showed, but because our sensors will need a certain radius to be effective in, the piezo elements are perfect.
Also, the values comming from piezo elements are perfect for converting into a scaled force, which allows us to easily use it in Flash.

CrossRoads:
The address lines are created by the arduino to select which signal is going thru the multiplexer.

How quickly do you expect these sensors to be pressed? 10,15 at a time? Or just 1 person walking around?

Well, we've changed the amount once again today, as we reduced it to 25 sensors.
Our installation will provide access for about 4 kids, which is not that hard to monitor.
Also, I've discussed this with a teacher at college today, and he explained it perfectly to me, how a multiplexer works!
Sorry for all the hard questions, but a real life example always is the best explanation :wink:

We also decided to use a CD74HC4067 twice, so we can connect up to 32 sensors, which is perfect for our 25 sensors.
This is an overview of the chip mentioned above:

Combining this with the code provided here: Mux Shield | Mayhew Labs, it is easy to use and provides all the data we need.

PS: I also figured out why the piezo didn't work: I thought I had to use the resistor used in the image, but as it turned out, I needed 1 Megohm, while I was using 100 Kiloohm...

Now, I have another question: when the multiplexer passes and shows the data in an array, I can easily read the array using this code, right? :
mux1array
where mux1array is the name of the array and i the number of the value in the array i'd like to read.

Ok, so I just tested it all, and it works aaaawesome!

What I made:
I hooked up 3 Piezo sensors to a CD74HC4067 Multiplexer, which was plugged into the Arduino.

Just testing, but this seems perfect for our purpose!

How it works:
-I print the array values, so i can see what is happening
-When you press a piezo element a led goes on/off, and a message is printed.

Here is my setup: