Well take a look at a multiplexer or so called a max. Actually this could multiplex or demultiplex so output or input. It could work with both digital and analog signals. So analog read pwm signals and digital write or read. It could also divide a track into multiple paths and that could be very useful, so guys lets get started. Music, Music pcb way is creating high quality pcbs for prototyping and for very low cost, so everyone could use their services, so dont hesitate and for only five dollars order. Your pcbs in just a couple of minutes and improve your projects, ive used their services for years, and the pcbs are just as i wanted them to be. The finished surface is perfect. The solder mask as well the size, the vias and the markings are precise. You can select all sorts of settings starting from the thickness and the color up to the gold finish for the better conductivity, the copper thickness for more current and other specific settings so check pcbway.com for pcbs and other services such as cnc metal, engraving, 3d, printing services And mold injected parts, so you could make the entire project at the same time. So if you have a good project, why not make it perfect using pcb way whats up? My friends welcome back today. Well, take a look at another useful module used with the arduino. This is not an adc is not a dac or other type of sensor.

This time we will use a module called a max or multiplexer. This module is very useful when you want to use more inputs or outputs than the arduino has. So let me tell you why, with the real life example, so the arduino uno has 14 digital inputs or outputs and 6 analog inputs. So what if your project needs more than that thats exactly what happened with my version of the arduino based multimeter? This is the old circuit of that project and, if you havent seen it, please check it out because its very interesting – and these are all the pins of my microcontroller and they are all used in different parts of the circuit as inputs or outputs. I want to remove these two slide switches because they are too big for my pcb. They dont work very well and they are still controlled manually. But i want to make my multimeter to be able to digitally change between the modes and not have to slide any switch, and for that thanks to your feedback, i want to use ssrs or solid state relays. Basically, this multimeter has two main inputs: the negative probe and the positive probe just as any other multimeter, but on the circuit we have a block for measuring the voltage another one for measuring resistance, one for the current and so on, and the input for these blocks Can be connected together, so we can connect the positive probe to all the blocks at the same time, because the voltage part will work with up to 60 volts.

But the resistance part, for example, works a digital value of 5 volts, so they can be connected together and the current mode, for example, is basically a short circuit through the current measurement module. So this block can be connected to the voltage mode, neither thats why we have the sliding switch. This is in charge of switching the positive input between these modes, but this is done mechanically by sliding the switch i want to make it digital. Basically, i want to add a few solid state relays, one for each mode and to enable or disable this release. We need signals from the arduino, but as ive shown you before, all my analog and the digital pins are already in use. I only have three left, but i need more than five. So how can we get that? Well, we use a max ic with a max module like this one. With the cd74 hc 4067 ic. We can control 16 outputs or inputs using 4 control pins from the arduino, so we lose 4 pins, but we get 16 so we can have 12 extra pins. So let me tell you how this works. I connect the max to the arduino and some output pins to each of the ssrs by sending a 0 0 1. I activate the first output by sending a 0 1 0, the second one and so on. In this way i could control 5 ssrs or more okay, so thats enough story for today lets use the max module.

This module has 16 inputs or outputs, but for my multimeter module i will use the 74 hc 4051, which has only eight, but it works. The same as this one first, we use this in output mode and then with the input mode, because this could go both ways for the output mode. You have to make these connections to test each output. I want to place an led and a resistor at each of the 16 pins, and then we have to supply 5 volts and connect ground to the module at the vcc and the ground pins in order to select the output. Since we have 16 different outputs, we need 4 pins, which are the pins as 0 to s3, and the signal pin is used to define the value of each output between high low or maybe a pwm signal. So let me explain: the max module can control the value of each output separately by itself. It only makes a connection between the signal pin and one of the 16 outputs or inputs. So lets say that you want to set height the output 5.. You send a 0 1 0 1 to those control pins and that will make a connection between the signal pin and the sixth output. Now you place the signal pin to high or low, and that will also set the sixth output to high or low, so the value is given by the signal pin and not by the max, which only selects on which output will that signal be placed.

That means that you could only control one output at a time and thats the disadvantage of this module. If you want to set, for example, the pin 5 and 6 to high at the same time, well, you cant, so you have. These connections now lets check the code. We select the control pins as the digital pins of the arduino 345 and 6.. They could be any other four pins if you want. I also set the signal pin to be the p9. For example, in the setup loop we set all pins to be outputs and now, for example, lets turn on the output 5 of the marks module and remember that for that we need to send a 0 1 0 1.. So we set the s0 to a 1. The s1 to a 0, the s2 to a 1 and the s3 was 0. now all is left to do – is to set the signal pin to high and then to low. So i run this code and, as you can see, the output 5 is now blinking on and off. So that was very easy. If you dont want to control each of the control pins separately, we have an easier way to do that and we use the bid. Read function, you have to know that a byte has 8 bits and the position of the bits are marked from 0 to 7.. So if i use the function bit read of the number 5 in binary, it will fill the byte with 0.

0. 0. 0. 0. 1 0 1, which is 5 in binary. If i tell the bitrate function to give me the position 2, for example, it will give me the value of the second position, which in this case is a 1.. So in the code i make this function using the bit read, and this will associate the s0 to the first position of the byte, the s1 to the second position and so on. So if i write the channel 5, it will automatically send a 0 1. 0. 1 to the control pins, we dont have to do it manually every time as before. So this is the new code, so i call the set max channel function and select the channel 10. For example, i run the code and now the output 10 is turned on, and now i run this other code where i make a for loop in order to pass through all the outputs from 0 to 15., with a delay of 100 milliseconds in between, i run The code and as you can see, i can select each of the 16 outputs by first selecting the max output and then switching the signal pin to high and then to low. But hey. Since the max is just a connection between the signal pin and any of the outputs, we can also apply a pwm signal right. The signal pin is connected on d9, which is a plan pin of the arduino and instead of using digitalwrite in the code.

This time i make an analog write, i run this code and, as you can see, i could also fade in and out on led with any of the outputs. Okay guys now lets use the multiplexer for reading inputs instead of controlling outputs. The process is the same. We use the s0 to s3 pins to multiplex one of the inputs to the signal pin. Then we use the analog grid in the code, but this time we need to connect the signal pin to one of the analog inputs lets say to a0. As you can see in the code again we select the input pin and then we make the analog read. I run this code and, as you can see, we can get the analog value from the potentiometer connected on pin 5 of the marks, and once again it could be any of the 16 pins. If you want and the same could be done using digital read, the code is the same, but we make a digital rate. I add some push buttons connected to the max. I run this code and, as you can see on the monitor, when i push the buttons i get the digital read. So this module is a multiplexer and also a demultiplexer okay, some things to have in mind this module works with voltages to up to 7 volts, and this is the truth table for each output. According to the s0 to s3 pins, the on resistance between the signal pin and the outputs is 60 to 70 ohms at 5 volts, which is quite high, but working with digital signals is okay.

Also, the propagation delay between the switch in and out is of around 90 nanoseconds, and the turn on delay could be up to 375 nanoseconds as well. So that might limit your frequency so guys thats, how you could multiplex your inputs and outputs for both digital and analog signals. Ive actually bought a bunch of these modules to use with a lot of capacitive sensors for a future project. I want to be able to create a grid of capacitive sensors and reading the columns and the rows with a simple arduino is impossible. I need a lot of inputs and thats why ill use maxis, but you could now use this to read values from ldrs. For example, from a lot of push buttons control, a lot of leds and other stuff and in general, increase the pin out of your microcontroller have in mind the max has its limitations, the bad one being that you could only select one channel at a time. So stay tuned for my new version of the multimeter using relays and this max. I hope that it will work, and i also hope that you have learned something new. If so, consider giving me a like or comment below thanks again and see you later guys, hey so one more video that ends. I hope that you like it. Okay, so listen! If you want to buy my merch, my t, shirts, you have the links below for my shop and i promise that i will make more designs and also maybe you would comment below which one you like more and what more designs you would like to see.

Because in that way i could start designing them and post my new t shirts.

https://www.youtube.com/watch?v=Dco6jo9xgAo