What's going on guys, vald with EEEnthusiast.com
here. In todays video, we're going to be talking
about multiplying your analog inputs with the help of the 74HC4051N IC, which I have
in my hand. This was inspired by a previous video that
I've made on a multiplexer which essentially allowed you to drive different outputs. Essentially up to 16 outputs with the use
of only 4 pins of your Arduino. Without any further delay, lets take a look
at how you can actually read up to 8 different analog channels on your Arduino by utilizing
only one single pin on your A0 channel. The first step is connecting the hardware,
and as you've often heard me say, you will need to look up the datasheet to fully understand
what each of these pins mean and how to actually connect the IC. I highly encourage you to take a look in the
description of this video and look at the datasheet for the 74HC4051N IC which I'm using
on my breadboard right now. I'm going to be walking you through the pins,
so you don't really have to go in depth. You will also see a screenshot of the pin
configurations right now on your screen. Lets take a look at some of the connections
that we have. First and foremost, the green cables right
here, represent the S0, S1 and S2 on pins 9, 10 and 11 of the IC. This pretty much allows you to select which
analog channel you want to use from the IC itself and then feed it back to the Arduino. They are connected currently to pin 8, 9 and
10 on the Arduino itself. I have the channel which feeds the main, or
the selected analog signal back to the Arduino; which goes into A0 in order to read the analog
value. Next, I have my power and ground busses, so
fairly simple. One thing you want to pay attention to, is
that the enable which is pin number 6 on the IC, needs to be connected to ground. As you can see, that is labeled by a black
cable. I have pretty much pins 6, 7 and 8 of the
IC going to ground. Next, all of my blue cables, that you see
going to the buttons and potentiometer, are pretty much analog input or analog channel
pins. You will have as I have in my case, 7 buttons
and then a potentiometer. What I'm going to be reading essentially is
7 different signals and a potentiometer. The last one, as you can see, is jumpered
through the button, so if I want, I can use the button or the potentiometer. Obviously, the potentiometer just acts as
a voltage divider, so I should see a value of 0 to 1023 on the Arduino serial program. You will be selecting one of these 8 channels
and feeding them back to the Arduino on pin A0. Essentially, utilizing one analog channel
of the Arduino and three selector pins in order to read up to 8 different channels. I'm going to be showing you the actual software,
but before that, I wanted to make a quick mention. You can also get these breakout boards which
would allow you to drive up to 16 channels. 16 Analog channels, same one pin on the Arduino
and then you get, obviously, one extra selector switch. I'll post the link on my website for this
particular board, so you can check that out if you want to drive even more analog signals. Lets take a look at the software side. Alright, so just as a quick reminder, all
of this code is going to be available on my website as well as my github page. Lets jump straight into the code. As I've mentioned before, S0, S1 and S2 on
the mux are mapped to Arduino pins 8, 9 and 10. That's what I am doing right here. The input from the mux is mapped to A0, this
is coming back to the analog pin of the Arduino. The state of the 8 mux channels mapped into
this array, so mux1 state 8. It is initialized to 0. The setup function; fairly simple. Three pins set to output. I had experimented with a digital input as
well for the mux, so that's commented out. Serial dot begin 9600, once again this is
used for the console and we're going to be looking at our array through this feature. Loop function update. This is a function which will be defined below;
lets take a look before we look at the rest of the code. void update mux1, I'm going through the 8
channels. A very simple for loop, going from 0 to 8;
incrementing every single time. I'm going to write a digital output high based
on the bit that is set for the i variable. Essentially, what this is doing, this is breaking
down your decimal, 1, 2, 3, 4, 5, 6, 7, 8 into a binary write. It writes them accordingly into pins 0, 1
and 2. Imaging it being a 000 001 010 etc. All the way up to 8. At every stage of that setting, I'm reading
the analog signal that is being sent to pin A0. Essentially, through these lines, I am selecting
the channel on the mux and reading the value of the said channel. Obviously, storing the said value into my
mux1 state array. Lets come back to the loop function. Once I've updated the array through one cycle,
what I do is, go through the for loop through all the channels. 0 to 7. If i = 7, what I want to do is essentially
create a jump line, so this is a println Mux state of i. Otherwise, I do a simple print on the mux1
state of the current channel and put a comma. Lets quickly verify the program, upload it
to the Arduino and I will show you exactly what it does. You can see the useful application. Serial monitor. Right now, as you can see, I have all my buttons
and my potentiometer initialized. Lets start with the buttons; if I press the
button, it reads a signal of 1023. Obviously, if the pin is unpressed, it reads
a 0, if it is full voltage, or 5v, it's 1023. Similar to every single other button, all
the way to 7. On the last pin, I have the potentiometer,
so this divider will go all the way from 0 to whichever value, all the way up to 1023. As you can see, I'm reading 8 distinct analog
inputs on the Arduino and only utilizing the A0 pin. You can already imagine that you can expand
this pretty much indefinitely and read all kinds of analog signals and sensors. Flow, temperature, if you want to read just
a potentiometer reading for whatever reason. If you have 20 potentiometers, you can implement
all of this very easily. Let me know what you think. Let me know what kind of applications you
would use this for. Let me know if you want to have some kind
of a modification; this IC also allows to essentially send out a different analog signal
to the 8 ports. In other words, doing an analog out the same
way as we're doing an analog in. As always, thank you guys for watching, make
sure to subscribe, make sure to visit my web page and thank you again for watching. Bye.