hi welcome to an Arduino step-by-step course by Robojax
if you found this tutorial helpful please thumb up and also click on the subscribe on the right
side on the lower corner I really appreciate it in this video I’m going to show you how you can use
the seven segment display with Arduino hi welcome to the video tutorial from Robojax 7
segment display is used in many ways as a counter for clock 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 want to use it for numbers with decimals 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 seven single display that I’ve used is 5611bh 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 anodes are connected
and we need to just connect the cathode to the negative so they will be turned on
and Arduino is sending through this wire just zero when we send zero this will be turned on
the code that I provide will work with both common anode and common cathodes so you don't
have to worry you just select the type by selecting the type one or zero one which
will reflect a common anode or common cathode the only thing that you have to do is proper wiring
common anode will be like this that all the anodes will be together connected to positive because all
of them are connected and the cathode we have resistor that it goes through this to Arduino
this resistors are limiting the current or you can have the resistors instead of in the cathode
you can have it on the anode and all the anodes 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 cathode all the characters are connected
to the ground and anodes have a resistor and a dispense goes to like Arduino or another
source that sends high signal to turn this on and these resistors the same way as before can be on
this side does not matter as long as the 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 middle pin here and the middle pin and here this is a common this will go to
the positive let's start putting the resistors these are one kilo that I’m using you can use
anything between 560 to one kilo for the five volts of Arduino it will be fine
uh so the first is that I’ve been inserted here the rest is empty the
second resistor have 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 resistor and it continues 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 row and the same way we have started
here one resistor one one one so four more resistors here and they've been connected
this way now I’m going to connect this to pin two 3 4 5 and then 6 7 8 and 9. and here now
the wires have been connected from this side one as you can see they have been connected in
order here so this is uh one two three four and then here we have five six seven eight
and I’m connecting all of this in order from pin two to nine and 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 the decimal point has 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
the 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 light 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 the 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 I’ve connected the roll in order this is connected from pin two to pin nine
and then there is one extra wire that is connected to one kilo ohm it is connected
here to one kilo ohm and it's coming to five volts in Arduino at this pin
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 pin 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 pin c
c is this middle one c and then the next one d and so forth all of this has been connected in here
as you can see
here 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 advised 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 you're if your display is common anode just change this
to zero and after that we will define the pins the pins that I’ve used is from pin two to eight just
there in order if you wish or if you need it you can change it but I would not suggest doing that
and then pin 9 is for decimal point they have been defined as constants so below this line you don't
need to change anything and this is a 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 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 cathode right now these two will be on
so this will be written as 1 and so forth as I said I have another video explaining that and
also it prints it here so the array is defined and then I have a function here this is called right
digit which is solved from here to here the job of this one is that when you pass a variable an
integer 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 it prints it as
uh it prints it as a number one two three four five that's 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 uh led on this display so there's this 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 0 this goes to digital pin and take that pin
from this array this is 0 this is 1 two three in terms of position and the values are two three
four five and six but in terms of position this is v zero and this is six so the we type the pin
and then from here we say convert high low I’ve written a function to convert it for high on low
depending on the common cathode and common anode and this will take the value this is the actual
value for the screen it says display led digit when you bring that digit if this is 2 for example
it comes here 0 1 2 it gets all these values but I if I 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 I is 2 3 4 5 6. so we will pick them up
and we send it to this function which I’m going to explain next which will be either high or low the
result of this is high or low this is as if I type here high like this so this will be high and this
will be number of pin 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 line so I did
not put it so 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 has been printed here to print one for us
and this ends now high and low convert the job of high and low is to get that value that you pass
either zero or one we call it v value and the job of this one is to convert it how it converts it
we define a new variable converted value we check the type if the type is zero if it's common anode
what it does is it gets subtracts v from one one minus if this is one minus zero is zero
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
it just changes 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
where we say return converted value because the type is integer this must be integer it returns
it and this will be the value for us after this line we have set up and the setup is the one that
defines all the pins d d from 0 to 8 zero to seven and eight time for all eight pins all those pins
uh as output because we don't want to put this time this
uh seven times for all the pins for or eight times for the all pins so we just used the
loop and also we set the decimal point output and also we set the decimal point high
to make it off initially and then this will be right now as you can see this is on
and then we put the serial monitor that is needed to display this text for us and that number
9600 board 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 0 to 9
equal 9 smaller than equal 9 so it prints age 9 and after that it
represents this line and wait for one second between each digit and then after that we set the
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 catheter common anode just change this to
high and low because I did not consider that important because this is just single digit
and the loop continues like that so if you want to use it for your application and you want to print
some value so you just use this when you write digit four 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 prints four and wait for three seconds and it goes back to the loop
thank you for watching this was how to use the seven segment display with Arduino please make
sure to subscribe by clicking at the subscribe button in here thank you thank you for watching
if you learned something and found this useful please thumb up as this will help my video in the
search algorithm of YouTube if you have comment or question please post it at the comment section
below I try to answer and reply and don't forget subscribe so you get updates on my upcoming videos