Arduino Multiplexor - MUX INPUTS & OUTPUTS - ANALOG and PWM

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this will be yet another episode of basic arduino modules today we'll 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 let's 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 don't hesitate and for only five dollars order your pcbs in just a couple of minutes and improve your projects i've 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 what's up my friends welcome back today we'll 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 that's exactly what happened with my version of the arduino based multimeter this is the old circuit of that project and if you haven't seen it please check it out because it's 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 don't 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 that's 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 i've 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 that's enough story for today let's 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 let's 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 that's 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 can't so you have these connections now let's 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 let's 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 don't 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 don't 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 let's 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 let's 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 that's how you could multiplex your inputs and outputs for both digital and analog signals i've 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 that's why i'll 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 so thank you for all the support and i'll see you in the next video
Info
Channel: Electronoobs
Views: 101,160
Rating: undefined out of 5
Keywords: arduino, multiplexor, MUX, CD74hc4067, 74HC4051, Module, tutorial, analog input, PWM output, signal, library
Id: Dco6jo9xgAo
Channel Id: undefined
Length: 13min 21sec (801 seconds)
Published: Sun Aug 28 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.