Build up to 8 digits Seven Segment display using 74HC595 Shift Register | Robojax

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we are going to use two pieces  of 74 HC 595 shift register chip to build two   to eight digits seven segment display we are going  to display integer up to eight digits also we will   be able to display decimal values such as this  we're going to learn how to measure the voltage   of potentiometer and display it on the display  all the wiring diagram is shown and explained code   is provided via the resources page and explained  line by line transistor driver for higher current   or larger LED displays also explained and shown  and I'm going to explain how this project works   so you can customize it if you don't want to learn  then the link to resources page where you can view   the wiring diagram and grab the code is below this  video otherwise Stay With Me before I start please   subscribe to my channel so you are informed  when I post new video let's get started with this first code to demonstrate using this  74 hc5 595 is to use LED and I've used this   circuit here except I've changed the pins  and the wiring is exactly the same as and   here the output from uh qz0 to Q7 from here  q0 to Q7 are connected each to an LED and   I use 330 Ohm resistor because of this 5  volts and exactly the wiring is like this   I've connected it like that only three wire  goes from uino and then these two wires are   uh for the positive on ground and from this red  I've taken one red to the other side so we have   5 volts on that side and from ground which  is blue line also I've taken another wire   so the same way both side we have 5 volts  on ground and the rest is the wiring in here and here is the code we have defined this  pin 10 11 12 pin 14 pin 12 pin 11 of the chip   these are the chip pin these are the names I've  been connected to 10 11 and 12 these are the   values to turn on each segment each LED and as  you can see this is one LED and then one and two   and then one two and three and then four five 6  and seven each one means one is on and then the   eight all of them will be on so this is our data  array and we Define the pins as an output and then   inside the loop we just run this to set the pin  12 the latch pin to low and then we use shift out   we put the data pin uh we use that we pass data  pin clock pin and then we use most significant   bit significant bit first and we pass the data  based on this num num is 0 1 2 3 uh this Loop   goes num is 0 2 3 up to equal 8 so every time it  changes num changes 0 1 2 3 up 8 and it comes to   this array and it goes and pulls up the data so  this is 0 1 2 3 4 5 6 up to eight it starts Zero   from here up to seven and every time it passes  the those bits to this shift out and then we set   this to low half a second and the loop will  continue like that uh to shift out the that and here is the demonstration even though  you saw it so I'm just explaining that it   starts with 0 1 2 3 and it's keeping them on  up to 8 and it comes back again so everything   will go off and then 1 2 3 up to eight  and the delay time is coming from here   after this pin if you want to speed it  up let's say make it 50 let's upload the code and as you can see now it goes very fast and for this second project the wiring  is exactly the same I've connected now this   seven segment display such that pin a b c  d are in order and the last pin is decimal   point and the common is connected here via  this 330 Ohm resistor even though this is   not a proper way each uh segment should  each segment should have a resistor but   for this demonstration and simplicity  I'm just using one resistor and here if I and I've connected the seven segment  display with the same points with the   same pins as you can see now the first  one is a and then we have b c and d e f   g and then decimal point exactly the same as  those because they is connected to the same pins now I've speed it up so you can see all  the segments are turned on so this way   you better understand how seven segment display works and here this is how we turn on a seven  segment display the seven segment display is   arranged in terms of segments a b c d e f g and  this is decimal point and when we connect it to   this 74 HC 595 from q0 a b c d and I've arranged  it such that you can see it easily up to 7 this is   a DP or decimal point because this is a eight  point we start with zero up to seven that's eight the seven segment display is divided into  seven segments and it starts with a b c clockwise   you rotate a b c d e f and then G and then decimal  point so these are seven pieces and the DP that's   eight and for this chip there is an Notch here  uh piece so from this point that you see there   is a deep spot pin one starts and then pin 8  and then 9 to 16 so q0 Z is 1 and then q1 up   to Q7 these are eight pins in total so a b CDE  e FG and then DP we are going to connect it like   this I'm going to show you if we do not connect  it we are going to put transistor one piece we   have like this LEDs and this is arranged in  common cathode so the line the side that we   have the line it's cathode and then anode so  these pins anode we have to connect positive   there and the uh common will be ground and  each element will be turned on and we will read digits and here to connect resistors we will  use the Pince you can stop this and follow the   wiring between each Pince and each segment  for this particular display these are the   segments a b c and d and decimal point and we  have here 330 ohm resistors in between so the   pin is not connected directly to the display but  on the path there is a resistor for example if   you follow this pin one it comes here and it  goes to this line which is connected to this   resistor and this line is all connected and  then Pink goes to the first pin to the right side most of this display needs uh between  5 to 10 mamp uh so the output from the chip   will supply 10 mamp and total will be seven  or eight when the all digits are on so 80   mamp will be drawn from the chip and uh if  you think that this chip get overloaded then   you can use a transistor driver you can use a  transistor driver like this this is a common   cathode the cathode is common connected so you  can connect a transistor such that each input   will come through a 1 K or 10 km resistor this  doesn't matter because we are using transistor   the switch it will be saturated and it goes to  the base this is a PNP transistor or transistor   that the emitter is connected to the positive  one example would be to 2907 and you can also   use 2 N 3906 or any other PNP as long so the  uh this signal for example when it comes for   Segment a this will come to the base uh the zero  will turn this on so then the signal will pass   and drive the that segment that particular  segment and the same way for each segment we   need to have a transistor in order to drive it  and there is a lazy way to do it which we can   put one resistor for all segments this why I  call it lazy because the amount of light will   be inconsistent and this resistor for example  have a act as this resistor acts as a voltage   divider and for each segment when the signal  comes it passes through the res the segment and   comes there is a voltage drop for example if this  draws 10 milliamp the voltage will be calculated   by ohms law lower but when for example when we  display two you will see that we have 1 2 3 4   five segments will be turned on and there will  be 50 milliamp will pass through this resistor   and as a result there will be huge voltage drop  and this will look dimmer so depending on what   digit is displayed the amount of light will not  be consistent it will be either darker or dimmer   for example if you display one two display will  be two segment will be turned on and it will be   very bright and if you display it which all of  them will be turned on it will be very dim but   it works you can test it for test purpose but for  real project this is not the right way and if you   don't want to use a seven segment display maybe  larger LEDs this is how you do it one by one all common and if you're using common anode this  case anode is connected to the positive and   then the cathode will be connected in this case  we are using npn transistor and for example you   could use 2 N 2222 transistor you can pause the  video if you want to follow it but this is proper way here it shows from 0 to 9 and for each segment  this is not human readable so unless you have some   kind of table you will not be able to understand  let me increase the time so I can explain it 5,000   millisecond so zero is everything on except the  middle one and then one is two segment these   two and then the two is like that only G and B  is of three like this so you can see it better four these two and these two so one these  two and these two after each other five as   you can see is like this six only one  is off which is this one and decimal point 7 a b c d you see three of those now the wiring is the same now  the wiring is exact exactly the same   as previous project and I've connected this  seven segment display and we are displaying the numbers and here is the code the only portion  that I've changed is this portion where the   segments or LEDs were turning on before now  these are based on the position of each uh   LED which reflects uh turning on a digit  for example for zero all of this should   be on and on only the e one the seventh would  be off and for one we have only two segment   and for two three and so forth so this will  create the digit for example for eight all   the seven segments are on here and now if I  if you want to slow it down just change this   let's say for 2 seconds and upload the code  and let's see it now once the code is upload it now and then click on this button to upload  the code now once the code is uploaded you will   see the zero one these two and two three 4 and  this is 5 6 4 S as you can see a b c d a b c   is on and for eight all of these are on and that  will create actual digits by turning on different segments and here I've connected two  display to the same pins but the common   has not been connected to different driver as  a result you will see the same number on both displays if you need to use two or more up to eight digits  then we need one extra chip of 74 HC 595 the same   chip and here this is hcp pin is connected to  hcp and then stcp pin is connected to stcp they   together and then shcp will be connected to pin  12 and stcp p is connected to pin 11 and this   pin now DS is connected to pin 10 pay attention  that DS pin we are getting this is a complement   of Q7 it's coming to this DS pin I put a red  color so you can notice it and this goes to   the display any display that you have you will  have common now the common will be connected to   these pins the same way this was a or the first  one and then second third fourth the same way we   start with first second third and fourth for  example if you have this type of display you   can do the same way now when we connect two chips  here is a wiring diagram that I just shown you as   you can see pin 8 9 10 from pin 10 goes to pin 10  and Pin 11 goes to pin 11 and then pin 8 goes to   pin 14 and the Arduin side is not changing  and for the common we are getting this is   for the first digit common goes to the first  one and then go this line goes to the second one and the same way now there's a shortcut to  use one resistor on the path of the common you   see this line the first digit is coming here and  passes through 30 oh resistor again this is not   a right way to do it but this is a quick and lazy  way but it will work with inconsistent brightness   of light and the same way for the other one also  we put one resistor but this is a proper way now   when you add more display in here you just add  second display and uh the rest is not changing   except the display driver let me show you here the  wiring so don't worry about four or five just pay   attention to the second one so one was there  already we added second one and from the left   which was a green wire I put one green wire to the  left of the second one and then there was a yellow   so there was Green for the first uh pin it goes to  the first pin of the second and yellow was to the   second it goes to the second of the other display  the middle one is not connected don't worry this   is for the driver I'm going to explain it or is  connected which is from the fourth pin to the   fourth pin and from the fifth is purple the same  way at the bottom you see from first to the first   second to the second fourth to the fourth fifth to  the fifth the middle is not connected because the   it's common for this display and the same way you  can add more display up to eight so it will be a   little missy if you're using single digit display  but it will work now once that is done then each   display needs to be connected to the second ship  for example as I mentioned this P 15 is a or uh q0   and then it goes q1 2 3 up to seven so up to eight  digit will be connected in here the first one is   this it's coming to the common of the first digit  and then the second one this is q1 that was q0 q1   q1 is coming through this green wire you see here  and it's coming to the second one and then Q2 Q3   are the same way connected uh this brown and red  as you can see brown is connected to the third   one and red is connected to the fourth one and you  can have four more digits if you want up to eight   digits it can be connected the same way this is  the wiring for two7 Segment display as you can see   the left pin of this one is connected to the left  pin and the second pin is connected to the second   pin and the same way from the right first pin is  connected to the first one and the right second   pin is connected to the second one using orange  all of the pins are exactly the same except the   common pin so you will use the common pin this  is for digit one the middle pin is common it   goes through 330 Ohm resistor and it comes to q0  and then the second digit is q1 and then if there   is third fourth it will go like that like this  so the second chip is used so here this one also   goes through 330 ohm to the common as I mentioned  this is a lazy design you are supposed to have   resistor for each now if you need to use seven  segment display four pieces all together then   the wiring will be very clean and here you can  just follow this but this particular display has   been arranged in this way and these are the pins  exact pins common ABCD it has all these pins and   it has been arranged so you can stop and watch it  I will provide you the model for this display in   the description the model for this display that  I'm using is HS 42561 k- C30 one now this was for   the single digit if you connect multiple digit and  you want to drive it with a transistor here is how   it works I give you example of two digits and this  this portion for single digit was exactly the same   each transistor is connected to one segment and  instead of being connected to the ground we will   connect it using a transistor here as I shown  you uh pin 10 is connected to pin 10 and as you   can see pin 12 is connected here to pin 12 in this  portion and so uh and then pin 14 is connected for   the first ship the second chip is not connected  as I shown you in the diagram it comes from the   Q7 which is pin 9 it comes to pin 14 so after  the value reaches the maximum value of Q7 this   will shift the value and send a signal to this  so that will be the first digit or First Signal   or first number that is shifted so then the rest  is exactly the same and we do and then instead of   connecting q0 to first segment second third we are  using it to connect it to the transistor for q1 so   q1 is coming to the base of this transistor which  is off and as soon as it receives the signal it   will connect the common of this transistor to the  ground this is a ground wire this is ground so the   emitter is connected to the ground The Collector  is connected to the seven segment display and the   same way we have the second one now what happens  with the display we will connect all the wires   for example if this was b b was connected to the  transistor bring another wire to this uh P Part   B and then the c and e and f and the same way a b  all of them just connect a wire which means they   are connected in parallel and for the SE for the  seven segment just connect them in parallel for   example the first segment which is connected to  the transistor here just connected to the first   segment and second segment to the second third  to the third so they're all in parallel and here   you see the first on the right side is connected  to the first on the right and so forth so each   segment a b c d will be connected All In Parallel  because we have eight transistor for the eight   segment why we have eight as I mentioned multiple  times we have seven segment plus decimal point and   the transistor that you can use for the positive  or the for the top one with a resistor this is a   PNP 2 N 2907 or you the one that I use is 23906  but for the bottom you can use this is p this is   npn or negative transistor uh this is 222 22 and  here is a code to display two digits I've added   this variable called digits and then put two  uh for this case it must be two this portion is   exactly the same we have this this variable that  is holding for different digits and this portion   is exactly the same and here inside the loop for  example if we want to display two digits such as   18 we have defined a variable called number  of type long and we store this 18 into this   number first we have to split and uh separate this  one and eight we have to get them and this is an   operator called modulo or modulus I have separate  video explain this fully with multiple examples so   this what it does is it gets the 18 and divides it  by 10 as a whole number as a result because this   is long it discards all the decimal value and it  refers to the whole number when so when you divide   18 by 10 the an the result will be division of one  the answer is one and the remainder is eight so   this operation will get you eight and it will be  stored in a variable called digit two then we have   to get one this line gets the number divides it by  10 18 / 10 is 1 eight is automatically discarded   or the remainder is discarded and 1 modulus 10  if you divide one by 10 and get the remainder   you will get one because it uh it's not uh divis  divisible as a whole number so we got one here   and then two this line determines which display  is on because we are using common cathode this   first this is referring to the first display  the second third fourth up to eth display so   this is turning on the first display and keeping  off all the other display this zero means on and   it's stored in here and this line is turning that  display particular display in second uh chip and   this goes displays the value and for and now digit  one so we get this digit one digit one is one and   one comes here in this array and gets element  first of this array let's go and see this array   so if you want to get one you get this value as  you can see 0 1 1 0 so this is elements of each   uh seven segment display and that B and C is on  so we see the digit one and here so this is our   seven segment display a b c d clockwise to display  one this digit B and C must be on so we can see one and the value is here and displayed pushed as  most significant bit this is also most significant   bit because we are uh dealing with the right  side is our value not in this side if this was   our reference we would use least significant bit  and then the latch pin which was low it becomes   high and this was for training or teaching I put  1,000 but this is supposed to be 1 millisecond so   now one is displayed after that we go to the  next one and then first digit is off second   digit is now on if you pay attention here this  was first digit now second digit is on means   zero and the rest everything will be off so the  first digit will be off second digit will be on   and that value will be passed the value that we  put here eight uh this value will so the digit so   digit two is now on so when the that segment  is on then we pass D two here it goes to two   and gets element for the value for segments of  eight and uh this is turning on the second one   so you can do the same thing but so you can do  this like copy and paste it multiple time and   change the values but that will not be the right  way but it will work but you have to also take   care of the number for number of digits you  have to do multiple of these lines which I'm   going to show in the next code which can be  done automatically with uh only this portion   of the code and it can be used for multiple  digits so this was the explanation of the whole code one is for One display the second  one is for the second display and here   the display is uh showing 188 and as you can  see we are showing displaying one and then it   alternately so because I've set the speed so  slow you can see that it's displaying 18 now   the delay is very it's 1 second now if I  change it and this code if I just make it one here I set for both digits one and  let me click to upload the code let's   see as and here it's turning on and off  very quick and we don't see any blank or   anything and the two LEDs are also showing  these are exactly the common point for two digits let's make them 500 so one of them 500 and the second  one quick let's see what we see so we don't see anything because  when is 500 times longer now 500 and   500 so it will alternate and it will be like this our number is now8 you can do  35 for example let's upload it and now it's 35 and here is the circuit with five digits so you  can put up to it did not fit so I went up to here   and the wiring is such that all the segments have  been connected to one digit and then it have been   it has been connected to the next one so the left  pin is connected to the next one like that if I   remove it is like this so they're just in parallel  the left pin of this is connected to the left pin   of the second to the third to the fourth and so  forth now when you add more display in here you   just add second display and uh the rest is not  changing except the display driver let me show   you here the wiring so don't worry about four or  five just pay attention to the second one so one   was there already we added second one and from the  left which was a green wire I put one green wire   to the left of the second one and then there was  a yellow so there was Green for the first pin it   goes to the first pin of the second and yellow  was to the second it goes to the second of the   other display the middle one is not connected  don't worry this is for the driver I'm going to   explain it orange is connected which is from the  fourth pin to the fourth pin and from the fifth   is purple the same way at the bottom you see  from first to the first second to the second   fourth to the fourth to the fifth the middle  is not connected because it's common for this   display and the same way you can add more display  up to eight so it will be a little missy if you're   using single digit display but it will work now  once that is done then each display needs to be   connected to the second ship for example as I  mentioned this pin 15 is a or uh q0 and then   it goes q1 2 3 up to 7 so up to eight digit will  be connected in here the first one is this it's   coming to the common of the first digit and then  the second one this is q1 that was q0 q1 q1 is   coming through this green wire you see here and  it's coming to the second one and then Q2 Q3 are   the same way connected uh this brown and red  as you can see brown is connected to the third   one and red is connected to the fourth one and  you can have four more digits if you want up to   eight digits it can be connected the same way  I have five digits here all of them connected   and we can set in our code I want to make sure  that wiring is not ripped and then each digit   has common and the common have been connected  to uh q0 q1 2 3 and four each with a resistor   this is a lazy connection uh I put resistor in  the common I could put the resistor in here but   for Simplicity I put it like that and here  this is the other one that uh is exactly the   same except this time I have this one piece  all the wiring is done inside it so we have   a b CDE e f g and then common and decimal  Point uh pins here is the model if you need it and here is again I'm repeating it so you  understand it better we use here two chips and   all these segments ABCD up to decimal point are  connected directly to the each segment and then   from here q0 this goes to digit one to the common  this goes to digit two the uh q1 Q2 Q3 to D2 D3 D4   respectively doesn't matter if you have uh this  type of 7even segment display or each digit is separate and now here is a code uh this portion is  exactly the same these are the important elements   that you should remember if you have number of  digits now we add digits here for example if   you have five digits just put five this is very  important if you're displaying a decimal value   or floating uh number value this has this must be  defined either 1 2 3 4 5 whatever you have number   of decimal points and show zeros is disabling  the leading zero if you want to set show zero   to false it will not display it if you set it  to true all lower case t r u e like that it will   display the zeros I've changed this portion now  for common cathode just put C cathode and a for   anode inside single code and these are variables  that are used inside the uh code this array is   holding the digits that is being displayed so  whatever number you sent it will be displayed   this is holding the digit length either if the  value that you're sending is one even though you   have five digits but you want to display for  example one or five for example one digit so   this is holding that this is used inside the code  uh time to remember this uh decimal position do   not change them thebug this is used internally is  floating number so this is also used internally   to uh Mark a value as a decimal and the back  delay this is you can set it uh to learn or   maybe debug uh if you want to display something  every second or something but it should be zero   for normal operation as I change the loop value  for example if you want to display every digit   at 1 second then put 1,000 and you will see in  four digits one digit will be displayed one by   one which I'm going to demonstrated this has not  changed uh this portion is holding the value do   not change these are the prototypes for the two  functions and that are at the bottom of the code   inside the setup nothing has changed and here we  put that debug if you put the value for example   anything other than zero the debug will be set to  True otherwise it will be false inside the loop   this is how you display this line it says show  number and put your number for example 84 933 8   4,933 for 3 seconds you must put some kind of uh  number here so we can display it properly if you   want it very fast put 50 for example that's fine  um so you can put some timing here and then this   is showing 72 this is showing decimal if you  want to show one a floating point value show   number decimal this a this is a function at the  bottom of the code and it will display 1.6 54 for   example this decimal point the decimal point that  you put here I directly related to this if you put   here two the rest will be this uh discarded if  you put here four and you put here three a zero   will be added so that's normal in terms of math  this shows for example 205 and this shows again   another floating point with two so remember we  have 3 + 2 5 so remember we have to count this   otherwise you will get incorrect uh display value  this is just a loop I is zero and it increments   as long as I is less than 131 so it will display  from 0 to 130 and we use the same uh function or   method and we pass the I for 100 millisecond  so this is how we use it inside the loop now   the functions um are doing a lot of work when  you say uh show number the number is assigned   as a long and this is the time that you pass as a  t of a time of long so this remembers the current   time Millis m is a function that I've explained  it check that video the link would be below this video and this is setting the if the value is  floating it sets it to false and this is getting   the length of this uh number for example if you  send 75 this goes to this function at the bottom   of the code and extract uh and gets the length  and stores it here which is a global variable at   the top of the code and this is a k internally and  here we are setting uh extracting our digit from   the number for example and here this Loop the  job of this Loop was to do this one but this uh   will not work because your digits will be maybe  two digits four digits and so that's why I made   this Dynamic I made this Dynamic Loop so it can  accept any number between 0 to eight digits or   whatever number of digits you have so this has  virtually no limit whatever you put the digit   it will work but to understand it it's let's say  your number is 59847 this line is extracting the   seven when you do number that number that comes  this number modulus modulus means divided by 10   and gives the remainder if you divide this by 10  and see the remainder the remainder would be seven   so you will get seven and it will be stored in a  fourth index four of this array and then if you   do it divided by 10 so this is divided by one this  divides it by one and this number is divided by 10   and then modulus exact the same modulus because we  are dividing it by 10 this goes next digit and it   picks up four and then we go by 100 so we get the  100 value which is8 and then the Thousand value   which is N9 and the 10,000 value which is five  and we will store it in this index in this order   so I just put this here uh for people who want  to learn how this Loop works and do you do the   m and see how it works and this is a while loop  that remembers that time and it goes it's true as   long as the uh remember time is as long as this  calculation is less than the amount of time that   you set and it runs this uh function called shift  digits so this was done and once it comes here it   goes to this shift digit first we set the bits  for the display for digits initially we set it   like this so the first digit would be on because  it's I'm using common anode common cathode it   should be off that's why the first digit should be  off and then this line is finding out the leading   zeros this is for Deb back if you set the number  of seconds for Deb you will also see this text   the leading zeros and digits so this is just for  learning so this Loop doesn't do anything it was   just printing something this line is taking care  of each digit dynamically because we initially set   it like that but we see if it is first digit we  put the first one Z if it is one we set the second   digit that is referring to first second third  fourth each one is a digit here so we are turning   them off and the same way up to uh fif because  we start with zero that's the fifth and this line   is checking if the value that we have has decimal  point and if the type is decimal then we this line is setting using this operator we set  the seven digit which means the eight   bit as one 0 1 2 3 4 5 6 7 so we  start with zero and end with seven   so that's the eight bit and in  terms of number that is uh fixed so this is just setting it to display the decimal   point dynamically based on I  which whatever digit it is and here this value this is just remember segment  to display because of this zeros and this line   if say it say if it is not like this you can turn  off the zeros the leading zeros or display them   for example for this these two as well shown  zero then it will turn all the digits on uh on   that digit off otherwise it will set them back  on and here this line is taking care of common   cathode or common anode if you put a cc this  line is just toggling this Mark means toggle   all the bits these bits if they are all zero it  makes it one if they are one it makes them zero   so gets the segments display and stores it here  by toggling them and if we have debug it will   print all the debug information and this is the  line where we use in previous codes to display   so the value comes this turns on the appropriate  digit this sends the segment value so I put proper   naming when you look at them you know digit  bets and seven segment to display segments to display and after that if the decimal point  was uh changed then we toggle it back so for   the next digit it's displayed properly and if  the debug is enabled then we add a delay so it   will weigh that amount of time for each digit  now when we call show decimal again we need to   extract the decimal from the value and uh so I so  we pass the number and this will get the digit and   extract the decimal point position and the number  of digits and store them in a global variable and   then we go to shift which will run now flow to  integer when the number comes for example 2.8   or something we use this function which is from  C++ it gets the value in here and we get we have   to mention how many digit we expect so the digit  plus one is because of the decimal points uh so   first we create this character as a buffer and  then we pass the number the number of Digit to   expect the floating precision and the buffer  that we want to store so this calculation or   extraction will be stored in this uh array of  character type which is defined in here and in   this line we are converting it to string because  we will use string Methods to extract values so   this is debug this line is extracting this is  getting the position of decimal so we check we   go character at this position we check if it is  equal zero then we set the character to I whatever   is either 0 1 2 3 or whatever number and then  we break from the loop and then we create this   array and we of characters from 0 to 9 to check  each character in the array this line is from   string number that we have we remove the decimal  point from that string uh so we have it without   remember it's a string so we remove the point and  then we remember the decimal position because we   found the decimal position now we removed the  decimal point so we are subtracting one so we   know the decimal position is one less and digit  length we set it to zero and then we check this   is now getting each digit character at that string  so for length of the string we go and we go from   0 to 9 or because we expect a number between 0  to 9 and this Loop is extracting it and it sets   the digit length so this will continue extracting  integer length is a function that we need to get   it uh this this is also a lazy way this could  have been done dynamically but this can extract   the length of Digit from 0 to 9 and it will return  and that's was this was the full explanation of code and here's the demonstration the numbers that  I have said here are at the top and they're being   displayed here at the bottom now we are seeing  decimal points and then the counter goes up 230 and it goes back to this value let's make it 3 seconds upload it let's make this 50 and let's go to 10,31 I Chang this to 30 and then 10,31 this is now a 50 millisecond let's make it 10 times faster five  times faster 10 millisecond it will   be very quick so we will not be  able to even see these two digits perhaps now 72 and then this 205  and then 97 the decimal point and here this will take very long because even 10,000 oh yeah so let me disconnect this and connect this one this  will not display the decimal points this is now four digit I  have to make changes in the code let's make it four and the floating  points are not shown on this display   because it does not have it these elements  that you see these are just fake empty dots   so now when we go four digits you can see  that this eight is clamped from the left   side not from the right side so we have  to make sure that we do not pass any five digits so let's see 4,933 72 and this will not be displayed with   the decimal points you see  the decimal points are gone and as you can see it is zero  so this must be greater than 20 I let's put it at five here I removed one of the digits from  this multi-digit and that's all one   pack I've connected it in parallel all  the data comes from that is connected   to this chip the three wire from Arduino  from that point is here and then power 5   Vols and as you can see this doesn't show  the decimal point this shows the decimal points but this has be has been biased  properly with resistors so the intensity   of light is consistent and this is a lazy  design just one resistor for each segment perfect and let me change the anode  and cathode type here let's say I   did not have the common anode but I'm putting a as   common anode and see how it responds  like this because the second Mms are incorrect and if you pay attention carefully   as you can see this is five 4 and this  is seven and two the just read the off points we can read this this is four as you  can see and the number is very quick just pay   attention here this is three and this is now  seven and two I don't know if you can read it and now I'm simply adding this  variable resistor also called   potentiometer so the right pin let's  connect it to 5 volts on the red line here the left pin that's connected to the ground  anywhere on this blue line that's ground on this   or on this side the middle pin is connected  to analog zero where we read the value of the potentiometer we read the analog zero which is  from 0 to 2 1024 it will be stored in a variable   called pot value and then we use a map to get  the Pod value which is from 0 to 1024 and map   it to a z value between zero and 2 seconds so  the maximum value when we rotate it will be 2   seconds if you want to change it just change this  value reduce or increase it and the result of   this calculation is in the delay value and here  we say if the delay is above 20 because it will   fluctuate so if it is 20 then we apply it with a  20 millisecond delay otherwise it will not have   any effect so the only code that have been added  are these lines and here to demonstrate it better   I have set the timing of the delay of each digit  using this potentiometer at the moment the delay   is one millisecond as you can see because each  digit is turned on and off uh and very quickly   you don't see it so let me increase the timing  as soon as I increase the time as you can see   eight flashes here and then four and so forth  but if I slow it down I go to the right and the   time is reduced as you can see so when eight is  displayed the rest are off then four is displayed   the rest is off the same way three and two so  each uh is displayed each digit is displayed   the rest is off originally this is such that it  is displayed in everything but we will turn that   particular digit the rest off and this is on  now if I slow it down you can see that better even so eight and the rest is off in the  same way I can increase it fully so you   can see it better because the four is now  goes to all of digits we have to turn them   off and uh visually we don't see it and  because this is turning on and off very quickly this goes very fast we will see it like this now we are going to see connecting a  potentiometer with the same circuit it has   three wires the right wire is connected  to 5 volts the left is connected to the   ground and the middle pin is connected to  analog zero here the rest is exactly the same and here inside the code the only  changes that I made was inside the loop   here we use using analog read analog zero  pin the result which is from 0 to 1023 is   stored in a variable called sensor value and  this line we get the sensor value multiplied   by this fraction Arduini is 5 volts if yours  is 3 volt 3.3 volts type here 3.3 volts and   this is for 10 bits for uh 12 bits go with a  higher value 2 to the power this is 2 ^ 10 - 1   and you are or do we know if it is 12 bets 2  to the^ of 12 - 1 if it is 16 2 ^ 16 - 1 and   the result of this is a voltage which stores  in this variable and we use this line show   number decimal and we pass the voltage  this 50 means 50 millisecond so give it   a little time or maybe even less than 50 make  it but not less than 20 and it will be display uh and here again I can change it very easily you see the Precision face at three  decimal places uh let's make it two and upload the code and now we have this reading 4.97 and here it says also show  zero false if you want it to make it true now all the zeros have been will all  the zeros will be displayed on the left side and here is a transistor  driver for one digit you can   do the same thing for multiple digits  and I'm going to use this one which is   a common anode display this is a PNP  transistor or uh positive transistor 23906 and here's the wiring diagram for driving  a s segment display I've used this 20 2N 2907   or 2N 3906 P&P transistor and as you can see  each base is connected to the segment so each   transistor is driving a segment because the  this display is common cathode is common it   is connected to the ground but the anode is  driving from 5 volts so the 5 volt is coming   and it's passing through this resistor  the signal is turning it on 1 by one like this and if you need to use two display or more  then we just need one more chip and you can drive   up to eight display like that I'm giving you  example for the two this portion is exactly the   same but instead of common we have used this trans  uh chip which I've explained it before so you   don't need transistors you just need to connect  all the elements these are in parallel for example   the first pin is connected to the first pin second  pin is connected to the second third fourth all   of them except the Comm the base is connected  via these 1 Kil resistor these are not critical   you can put 10 k 20 K or 303 Kil doesn't matter  because we are using the switch and here this is a display and we can use common anode  common cathode in this case this is   a common cathode and in the code  we can select different type if we want if you select the wrong type  of display you see that's now you   see the black is the number I don't  know if you can read it that's seven   one and then two and then three these off  points exactly the same so you can read it
Info
Channel: Robojax
Views: 1,887
Rating: undefined out of 5
Keywords: robojax, tutorial, kit, learn, learning, step by step, arduino, 74Hc595, shift, register, dispaly, wiring, show, 2 digits, 3 dights, 4 digits, 5 digits, 6 digits, 7 digits, 8 digits, seven, segment, common, anode, cathode, how to, leading zeros, ahmad, shamshiri, float, pot, potentiometer, voltage, multiplexing
Id: xhPXovgFhso
Channel Id: undefined
Length: 66min 58sec (4018 seconds)
Published: Mon Mar 25 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.