loading

This instructable shows how to display 0-9 digits on 7 Segment Display using Arduino.

What do you need:

  • Arduino Uno 3
  • 7 Seven Segment Display
  • 2 x 220 Ohm Resistors
  • Jumper Wires

Step 1: Making Connections

Connect the pins described below:

  1. Arduino Pin 2 to Pin 9.
  2. Arduino Pin 3 to Pin 10.
  3. Arduino Pin 4 to Pin 4.

  4. Arduino Pin 5 to Pin 2..

  5. Arduino Pin 6 to Pin 1.

  6. Arduino Pin 8 to Pin 7.

  7. Arduino Pin 9 to Pin 6.

  8. GND to Pin 3 and Pin 8 each connected with 220 ohm resistors.

<p>Single digit is working properly, but how to combine two digits, like 11 12 13 14 etc.</p><p>int a = 2; //For displaying segment &quot;a&quot;</p><p>int b = 3;</p><p>int c = 4;</p><p>int d = 5;</p><p>int e = 6;</p><p>int f = 7; </p><p>int g = 8;</p><p>int gnd1l = 9;</p><p>int gnd2l = 10;</p><p>int gnd1r = 12;</p><p>int gnd2r = 13;</p><p>int buzz = 11;</p><p>void setup() {</p><p> pinMode(2, OUTPUT);//a</p><p> pinMode(3, OUTPUT);//b</p><p> pinMode(4, OUTPUT);//c</p><p> pinMode(5, OUTPUT);//d</p><p> pinMode(6, OUTPUT);//e</p><p> pinMode(7, OUTPUT);//f</p><p> pinMode(8, OUTPUT);//g</p><p> pinMode(9, OUTPUT);//com1l</p><p> pinMode(10, OUTPUT);//com2l</p><p> pinMode(12, OUTPUT);//com1r</p><p> pinMode(13, OUTPUT);//com2r</p><p> pinMode(11, OUTPUT);//buzzer</p><p>}</p><p>void displayDigit(int digit)</p><p>{</p><p> digitalWrite(gnd1l,HIGH);</p><p> //digitalWrite(gnd2l,HIGH);</p><p> //Conditions for displaying segment a</p><p> if(digit!=1 &amp;&amp; digit != 4)</p><p> digitalWrite(a,LOW);</p><p> //Conditions for displaying segment b</p><p> if(digit != 5 &amp;&amp; digit != 6)</p><p> digitalWrite(b,LOW);</p><p> //Conditions for displaying segment c</p><p> if(digit !=2)</p><p> digitalWrite(c,LOW);</p><p> //Conditions for displaying segment d</p><p> if(digit != 1 &amp;&amp; digit !=4 &amp;&amp; digit !=7)</p><p> digitalWrite(d,LOW);</p><p> //Conditions for displaying segment e </p><p> if(digit == 2 || digit ==6 || digit == 8 || digit==0)</p><p> digitalWrite(e,LOW);</p><p> //Conditions for displaying segment f</p><p> if(digit != 1 &amp;&amp; digit !=2 &amp;&amp; digit!=3 &amp;&amp; digit !=7)</p><p> digitalWrite(f,LOW);</p><p> if (digit!=0 &amp;&amp; digit!=1 &amp;&amp; digit !=7)</p><p> digitalWrite(g,LOW);</p><p>}</p><p>void displayDigit1(int digit)</p><p>{</p><p> digitalWrite(gnd1r,HIGH);</p><p> //digitalWrite(gnd2r,HIGH);</p><p> //Conditions for displaying segment a</p><p> if(digit!=1 &amp;&amp; digit != 4)</p><p> digitalWrite(a,LOW);</p><p> //Conditions for displaying segment b</p><p> if(digit != 5 &amp;&amp; digit != 6)</p><p> digitalWrite(b,LOW);</p><p> //Conditions for displaying segment c</p><p> if(digit !=2)</p><p> digitalWrite(c,LOW);</p><p> //Conditions for displaying segment d</p><p> if(digit != 1 &amp;&amp; digit !=4 &amp;&amp; digit !=7)</p><p> digitalWrite(d,LOW);</p><p> //Conditions for displaying segment e </p><p> if(digit == 2 || digit ==6 || digit == 8 || digit==0)</p><p> digitalWrite(e,LOW);</p><p> //Conditions for displaying segment f</p><p> if(digit != 1 &amp;&amp; digit !=2 &amp;&amp; digit!=3 &amp;&amp; digit !=7)</p><p> digitalWrite(f,LOW);</p><p> if (digit!=0 &amp;&amp; digit!=1 &amp;&amp; digit !=7)</p><p> digitalWrite(g,LOW);</p><p>}</p><p>void turnOff()</p><p>{</p><p> digitalWrite(a,HIGH);</p><p> digitalWrite(b,HIGH);</p><p> digitalWrite(c,HIGH);</p><p> digitalWrite(d,HIGH);</p><p> digitalWrite(e,HIGH);</p><p> digitalWrite(f,HIGH);</p><p> digitalWrite(g,HIGH);</p><p>}</p><p>void loop() </p><p>{</p><p> int i=0;</p><p> int j=0;</p><p> for(i=0;i&lt;10;i++)</p><p> {</p><p> displayDigit(i);</p><p> for(j=0;j&lt;10;j++)</p><p> {</p><p> displayDigit1(j);</p><p> delay(1000);</p><p> turnOff();</p><p> }</p><p> turnOff();</p><p> }</p><p>}</p>
<p>wow couldnt beliwvbe it whgewnb i saw i vy is di it!</p>
<p>Doesn't work correctly. could you tell me why.</p>
<p>Confirm if you have exact same components? Have you made right connections? Copied all code?</p>
<p>me 2 bro.. not work correctly.. fix this if u can.</p>
<p>Connections which is in the <strong>circuit diagram</strong> is the correct one. </p><p>Connections which is in the <strong>description</strong> is wrong<br><strong>Correct description<br></strong>Connect the pins described below:</p><ol> <br><li>Arduino Pin 2 to Pin 7.<li>Arduino Pin 3 to Pin 6.<li>Arduino Pin 4 to Pin 4.<li>Arduino Pin 5 to Pin 2.<li>Arduino Pin 6 to Pin 1.<li>Arduino Pin 8 to Pin 9.<li>Arduino Pin 9 to Pin 10.<li>GND to Pin 3 and Pin 8 each connected with 220 ohm resistors.</ol>
<p>thanks very much (y) ...at last it worked ....</p>
<p>Hey! Try to switch from GND to VCC. It worked for me. If you search for a datasheet or a pinout description you will notice that the 3 and 8 pins are connected to VCC not GND. Try this way...maybe it will work.</p>
<p>maby you have a wrong 7 segment display maby it's a common cathode</p>
<p>Connections which is in the <strong>circuit diagram</strong> is the correct one. </p><p>Connections which is in the <strong>description</strong> is wrong<br><strong>Correct description<br></strong>Connect the pins described below:</p><ol> <br><li>Arduino Pin 2 to Pin 7.<li>Arduino Pin 3 to Pin 6.<li>Arduino Pin 4 to Pin 4.<li>Arduino Pin 5 to Pin 2.<li>Arduino Pin 6 to Pin 1.<li>Arduino Pin 8 to Pin 9.<li>Arduino Pin 9 to Pin 10.<li>GND to Pin 3 and Pin 8 each connected with 220 ohm resistors.</ol>
<p>HERE IS THE FIX!!!!!!!!!!!!!!!!!!! the code is defunct now due to newer IDE versions: to fix the code change in the line of Void Loop</p><p>for(int i=0;i&lt;10;i++)</p><p>remove int after for(i=0;i&lt;10;i++) &lt; should look like this</p><p>and in the same Void loop add this line before the if statement</p><p>int 1;</p><p>so it should look like :</p><p>void loop()</p><p>{</p><p>int i;</p><p>for( i = 0; i&lt; 10; i++);</p><p>{</p><p>DONE</p>
<p>Worked fine </p><p>Thank-you for sharing</p>
<p>The reason it does'nt work is because Arduino pin 1 and 7 is not used, correct code :</p><p>{<br> digitalWrite(2,LOW);<br> digitalWrite(3,LOW);<br> digitalWrite(4,LOW);<br> digitalWrite(5,LOW);<br> digitalWrite(6,LOW);<br> digitalWrite(8,LOW);<br> digitalWrite(9,LOW);<br>}</p><p>And yes, I made it but don't have an image :D</p>
<p>doesnt work correctly! could you tell me why? </p><p>code is accepted but there has been an error</p>
<p>The code is written for Common Cathode 7 segment LED so if you are <br>using Common Anode one, just exchange &quot;HIGH' &amp; &quot;LOW&quot; in codes. for <br>example, Common Cathode 7 segment LED pin 3 &amp; 8 are connected to <br>GROUND so we need to make respective pin to go HIGH then the related <br>segment will be on. But Common Anode will be opposite. so 7 segment pin 3 <br> &amp; 8 should be connected to 5V supply then respective pin has to be <br>in &quot;LOW&quot; so that related segment will be on. I believe it is the only <br>thing causing some of yours program not working. </p>
<p>7 Segment working in action.<br><a href="https://instagram.com/p/5tproHyMFj/?taken-by=veggievampire" rel="nofollow">https://instagram.com/p/5tproHyMFj/?taken-by=veggi...</a></p>
<p>Connections which is in the <strong>description</strong> is wrong.</p><p>Connections which is in the <strong>circuit diagram</strong> is the correct one. </p><p><strong>Correct description<br></strong>Connect the pins described below:</p><ol> <br><li>Arduino Pin 2 to Pin 7.<li>Arduino Pin 3 to Pin 6.<li>Arduino Pin 4 to Pin 4.<li>Arduino Pin 5 to Pin 2.<li>Arduino Pin 6 to Pin 1.<li>Arduino Pin 8 to Pin 9.<li>Arduino Pin 9 to Pin 10.<li>GND to Pin 3 and Pin 8 each connected with 220 ohm resistors.</ol>
<p>doesn't work and when i change the code nothing happened and the connections in the picture aren't the same in the writting or the numbering were wrong</p>
<p>Connections which is in the <strong>circuit diagram</strong> is the correct one. </p><p>Connections which is in the <strong>description</strong> is wrong<br><strong>Correct description<br></strong>Connect the pins described below:</p><ol> <br><li>Arduino Pin 2 to Pin 7.<li>Arduino Pin 3 to Pin 6.<li>Arduino Pin 4 to Pin 4.<li>Arduino Pin 5 to Pin 2.<li>Arduino Pin 6 to Pin 1.<li>Arduino Pin 8 to Pin 9.<li>Arduino Pin 9 to Pin 10.<li>GND to Pin 3 and Pin 8 each connected with 220 ohm resistors.</ol>
<p>It doesn't work...the connections done in circuit diagram and those given in description are different...which one is correct? The code works fine with the changes given in the comments.. can u tell me where lies the flaw?</p>
<p>Connections which is in the <strong>circuit diagram</strong> is the correct one. <br>Connections which is in the <strong>description</strong> is wrong<br><strong>Correct description<br></strong>Connect the pins described below:</p><ol> <br><li>Arduino Pin 2 to Pin 7.<li>Arduino Pin 3 to Pin 6.<li>Arduino Pin 4 to Pin 4.<li>Arduino Pin 5 to Pin 2.<li>Arduino Pin 6 to Pin 1.<li>Arduino Pin 8 to Pin 9.<li>Arduino Pin 9 to Pin 10.<li>GND to Pin 3 and Pin 8 each connected with 220 ohm resistors.</ol>
<p>Works</p>
<p>It doesn't work...the connections done in circuit diagram and those given in description are different...which one is correct? The code works fine with the changes given in the comments.. can u tell me where lies the flaw?</p>
<p>It doesn't work...the connections done in circuit diagram and those given in description are different...which one is correct? The code works fine with the changes given in the comments.. can u tell me where lies the flaw?</p>
<p>thank you a lot this works 100% with me :) :)</p>
<p>HERE IS THE FIX!!!!!!!!!!!!!!!!!!! the code is defunct now due to newer IDE versions: to fix the code change in the line of Void Loop</p><p> for(int i=0;i&lt;10;i++)</p><p>remove int after for(i=0;i&lt;10;i++) &lt; should look like this</p><p>and in the same Void loop add this line before the if statement</p><p>int 1;</p><p>so it should look like :</p><p>void loop()</p><p>{</p><p> int i;</p><p> for( i = 0; i&lt; 10; i++);</p><p> {</p><p>DONE</p>
<p>Code is defunct can you fix or identify problems in all if statements compile reports errors with all if&quot;s</p>
I do but when I turned the Arduino on then the 7 segment display was flashing on and off the letters.
<p>Perfect !!! Working properly!! </p>
<p>Looks like it's all there....</p>

About This Instructable

38,279 views

37 favorites

License:

More by SherMarri: 7 Segment Display On Arduino
Add instructable to: