Hi, in this video I'm going to show you how you can use the 7-segment display with
Arduino hi welcome to the video tutorial from Robojax you will get the code for this by
clicking at the link which is below the video in the description which will take
you to robojax.com/learn/Arduino let's get started with this
My name is Ahmad Shamshiri, an Electrical Engineer from Canada (Persian from The Great Khurasan now Afghanistan)
7-segment displays used in many ways as a counter for Clark for different purposes but
because it is called seven segment displays it has seven segments one two three four five six
and seven there is also a decimal point in case if you won't use it for numbers with decimal so
you can put multiple of these and turn on the decimal point and the code that I've written and
explained here will make it very easy and you can use it either for common cathode or common
anode I have another video explaining this I will provide you the code I will not go through that
because it will be just waste of time just watch that video the link will be provided I will just
go directly here with Arduino on how to use this the summon thing will display that I've used this
five six one 1bh and this is the common anode common anode means anode is all seven segment
of this is all connected to the positive so anode will be connected to positive common
anode all of the animals are connected and we need to just connect a cathode to the negative
so they will be turned on and Arduino is sending through this wire just zero when we send 0 this
will be turned on the cool that I provide will work with both common anode and common casters
so you don't have to worry you just select the type but by selecting the type 1 or 0 1 which
will reflect common another common cathode the only thing that you have to do is proper wiring
common anode will be like this that all the a notes will be together connected to positive
because all of them are connected and the Cassatt we have resistors that it goes through this to
Arduino those resistors are limiting the current or you can have the resistors instead of in the
classic you can have it on the anode and all the annals are connected still the same common
configuration and this pin will go to the Arduino and these resistors do the same job if they are
here or there or we will have this configuration that this is common cat that all the cat cells
are connected to the ground and a nodes have a resistor and these pens goes to label Arduino or
another source that sends high signal to turn this on and these results are the same way as
before can be on this side does not matter as long as a current passes through it like this
so the resistors are here they do exactly the same job and if I put it on this side and this
is decimal point that is C D and E the metal pen here and the middle pin and here this is a common
this will go to the positive this is sort putting the resistors these are 1 kilo ohm that I'm using
you can use anything between 5 60 to 1 kilo for the 5 volts of Arduino it will be fine so the
first is that have been inserted here the rest is empty the second resistor I've been here connected
to the next line and the rest is empty meaning this line is all connected so one wire is here
and this one also we have one resistor one one is itself and it continuous on this side so this
resistor is ended here the second one one row next to it and then the next row and then the next loop
and the same way we have started here one is this third one one one so for more resistors here and
they have been connected this way now I'm going to connect this to pin 2 3 4 5 and then 6 7 8 & 9
and have now the wires have been corrected from this side one as you can feel they have been
connected in order here so this is one two three four and then here we have five six seven eight
and I'm connecting all of this in order from pen to tonight here now I have connected it
just pay attention to this diagram this is as you can see here this is B a so we have a the
second line now this has been the first one is connected to a the second line here and then
this is connected to B and then the third one is connected where this red wire to C and this is
connected to D the last second and here and this has been connected to e which is the last one if
you see here and then this has been connected to F as you can see the last second and this
has been connected to G and then the last one that the seven point have been connected to H
here and we have resistor for each of this led now the code is here I just need to connect the
positive the common anode in here and as you can see it's running with even
brightness because we have individual LED and if the number of segments increase or decrease
that density of light will not change we have consistent lights for all of those
sometimes people just put one resistor for all for all of these this is not a good practice
because the amount of light or intensity will be different for example if you turn this as one
these two segments will be turned on and there will be a lot of current for that too but if
you put it all of these will be on and there will be a lot of voltage drop and LEDs will be dimmer
so this is not a good practice but it works I've connected a bunch of wires here to the LED display
directly and on this side has connected they're all in order this is connected from pin to the
pin nine and then there is one extra wire that is connected to one kilo ohm and it's connected
here to 1 kilo ohm and it's coming to 5 volts in Arduino at that span but these pins are in
order this is for a b c d e f g h h is a decimal point so this is in this order as you see here
and from this side this is connected to pan a and here that's the second one and then this
is connected to pin B and here the third one have been connected to pan C C is this metal
one C and then the next one D and so forth all of this have been connected in here as you can see
yes we have connected only one resistor to this seven segment
display for that reason the intensity of light when displaying different digits
will be different so it's not advice but it works
let me now explain the code you don't need any library I've written this code from scratch so
the first thing that you define is the type either common cathode or common anode in my case it's
common cathode I put one here and if your if your displays common anode just changes to zero and
after that we will define the Pens the pens that I've used this from pen two to eight just there
in order if you wish or if you need it you can change it but I will not suggest doing that and
then pen 9 is for decimal point they have been defined as constant so below the sign you don't
need to change anything and this is display LEDs status we have seven segments for zero everything
should be zero zero zero and then just one point that's the middle line should be off zero as you
can see here when it comes only this one is off the rest is on that is one would be just off so
in this case in my case II but you don't have to worry about it and the same way for one as
you can see these two will be on and because this is common cut it right now these two will be on
so this will be written as one and so forth as I said I've another video explaining that and also
it prints it here so that is defined and then I have a function here this is called write digit
which is solved from here to here the job of this one is that when you pass a variable and
integers let's say 5 6 or whatever it just prints that number on this so this will receive a number
when you call it and this prints the digit here the number that you pass is printed as
a transit of a number one two three four five dots the number and then we print a space so
this is the space after that we write a for loop the for loop goes to print every pieces for each
led on this display so there's death there's each of those for the depending on the type we have to
set those value and send it through the output so that that particular LEDs will be turned on
and it goes from zero to six and seven elements all of those and then digital right it gets the
digital display when you pass this when I is zero this goes to digital pen and take that pen from
this array this is 0 this is 1 2 3 in terms of position and the values are 2 3 4 5 & 6 but in
terms of position this is v-0 and this is 6 so they we take the pen and then from here we say
convert high-low I've written a function to convert it for high or low depending on the
common cathode and common anode and this will take the value this is actual value for the screen and
says display LED digit when you bring that digit if this is 2 for example it comes here 0 1 2 it
gives all these values but I fi is 0 for example for this one if I is 0 this value will be picked
up if I is 1 this will be picked up by is 2 3 4 5 6 so we will pick them up and we send it to
this function which I'm gonna explain next which will be either high or low the result of this is
high or low this is as f I type here high like this so this will be high and this we number of
pen because digital right high 10 and then higher low and then this displays each value here and I
did not put Ln here Ln mean new line it will go to the next time so I did not put it to it they
put them the way they are for example if you look here for one we have only two zeros here you see
these two zeros so this value have been printed here to print one for us and this ends now high
and low convert the job of higher Lewis to get that value that you pass either 0 or 1 we call
it V value and the job of this one is to convert it how it converts it we define a new variable
convert this value we check the type of the type is 0 if it's common anode what it does is it gets
subtracts V from 1 1 minus if this is 1 minus 0 is 0 so the value will be 0 if the value if this is 1
1 minus 1 it will be 0 so it's simple arithmetic has just changed 1 to 0 0 to 1 and 0 means low 1
means high if it's not if it's common cathode the same value will be placed in this variable it will
be stored in here we where we say return converted value because the type of integers this must be
integer it returns it and this will be the value for us after this line we have setup and the setup
is the one that defines all depends D D from 0 to 8 0 to 7 and 8 time for all 8 pens all those pens
as output because we don't want to put this time this 7 times for all the pencil on 8 times for
the all pens so we just use the loop and also we said that the 7 point output and also we said that
this will point high to make it off initially and then this will be right now as you can see this
as on and then we put the serial monitor that is needed to display this text for us and that number
9600 baud must match this value that is here otherwise you will not be able to see the text and
this is the mean loop that runs continuously printing this for us it goes from zero to nine
equal nine smaller than equal nine so it prints eight nine and after that it explains this line
and wait for one second between each digit and then after that we said decimal point
to be turned on and then go with this one here because decimal point I have not taken care of
it so you have to change it accordingly for your type common catheters common and it just changes
to high and low because I did not consider that important because this is just single digit and
the loop continuous like that so if you want to use it for your application and you want to
plan some value so you just use this new right digit for just say right digit and then four
and wait for three seconds once all these numbers finished you will see after nine it wait for three
seconds and then it plans for and wait for three seconds and it goes back to the loop thank you
for watching this was how to use the 7-segment display with Arduino if you learn something or
like this video please stamp up please subscribe so you can get updates of my other upcoming cool
videos and if you have comment or question please post it I try to answer and reply
you