Skip to main content

7 segment display Arduino

The aim of this article demonstrate how the Arduino can run on 7-segment display. We used a SA56-11GWA which is a single display with common anode, it means that the anode is common to all digits, and to the point.
A display consists of 8 LEDs, 7 form the figure and 1 point decimal.A conversion between decimal and what we intend to show the binary information that you receive is called the BCD (Binary Coded Decimal).

In terms of hardware, each LED work individually, so each of the segments has to lead a limiting resistor, in this case, each digit has an operating voltage of 2.2V and consumes 20mA. If the voltage is 5volts, we need the resistor fall 5-2.2 = 3.8V, by Ohm's Law we can calculate, R = V res / I led R = 3.8 / 0.020 = 190 Ω +/- 20% (let's use a resistor with 220Ω). This applies to this display SA56-11GWA used as an example, other values ​​may be different, it is useful to calculate the required resistance value.
DecimalThe321
00000
10001
20010
30011
40100
50101
60110
70111
81000
91001
The first thing we have to do is convert our decimal number to binary, we will use examples only 0-9 this first phase
 decToBcd byte (byte val)
 {
   return ((val / 10 * 8) + (val% 10));
 }
This makes our decimal value to binary, for example, assuming that have numbers with more than two digits, 27 will be 0010 0111 (2 - 7 BCD). If we have only one figure 2 for example, will have 0010.
This allows us to act on an IC decoder (4511) and the use of only four BCD outputs Arduino, so can convert a result of a count value, or for any input digit.
 / *
 Example of a counter from 0 to 9 that adds each 
 Since there is an entry in A0
  
 author: Arturo Guadalupi 
  * /
 
 // Declaration of pins used in the 4511 entries
 The const int = 2;
 const int b = 3;
 const int c = 4;
 const int D = 5;
 
 void setup () {
   pinMode (A0, INPUT);
   pinMode (A, OUTPUT);  // LSB
   pinMode (B, OUTPUT);
   pinMode (C, OUTPUT);
   pinMode (D, OUTPUT);  // MSB
 
 }
 
 int count = 0;  // Used for the variable number
 
 void loop () {
   if (digitalRead (A0) == LOW) // if the button is pressed on the A0 input
     {
     count ++;
     delay (200);  // The delay prevents multiple counts
     if (count == 10) // 0-9 counter
       count = 0;
     to_BCD ();  // Convert to binary
     }
    
   if (count == 10)
     count = 0;
   
 }
 
 to_BCD void ()
 {
     if (count == 0) // write 0000
     {
       digitalWrite (A, LOW);
       digitalWrite (B, LOW);
       digitalWrite (C, LOW);
       digitalWrite (D, LOW);
     }
     
     if (count == 1) // write 0001
     {
       digitalWrite (A, HIGH);
       digitalWrite (B, LOW);
       digitalWrite (C, LOW);
       digitalWrite (D, LOW);
     }
     
     if (count == 2) // write 0010
     {
       digitalWrite (A, LOW);
       digitalWrite (B, HIGH);
       digitalWrite (C, LOW);
       digitalWrite (D, LOW);
     }
     
     if (count == 3) // write 0011
     {
       digitalWrite (A, HIGH);
       digitalWrite (B, HIGH);
       digitalWrite (C, LOW);
       digitalWrite (D, LOW);
     }
     
     if (count == 4) // write 0100
     {
       digitalWrite (A, LOW);
       digitalWrite (B, LOW);
       digitalWrite (C, HIGH);
       digitalWrite (D, LOW);
     }
     
     if (count == 5) // write 0101
     {
       digitalWrite (A, HIGH);
       digitalWrite (B, LOW);
       digitalWrite (C, HIGH);
       digitalWrite (D, LOW);
     }
     
     if (count == 6) // write 0110
     {
       digitalWrite (A, LOW);
       digitalWrite (B, HIGH);
       digitalWrite (C, HIGH);
       digitalWrite (D, LOW);
     }
     
     if (count == 7) // write 0111
     {
       digitalWrite (A, HIGH);
       digitalWrite (B, HIGH);
       digitalWrite (C, HIGH);
       digitalWrite (D, LOW);
     }
     
     if (count == 8) // write 1000
     {
       digitalWrite (A, LOW);
       digitalWrite (B, LOW);
       digitalWrite (C, LOW);
       digitalWrite (D, HIGH);
     }
     
     if (count == 9) // write 1001
     {
       digitalWrite (A, HIGH);
       digitalWrite (B, LOW);
       digitalWrite (C, LOW);
       digitalWrite (D, HIGH);
     }
 } 

Convert decimal to binary (8bit)


7 segment display Arduino
It is possible to directly transfer the binary value for the exits, here is an example of cyclic counter zero to nine
 ledpins int [] = {4,5,6,7,8,9,10,11};
 byte digits [] = {B11111100, B01100000, B11011010, B11110010, B01100110, B10110110,
 B10111110, B11100000, B11111110, B11110110};

 void setup ()
 {
   for (int i = 0; i <8; i ++)
   {
     pinMode (ledpins [i] OUTPUT);
     digitalWrite (ledpins [i], HIGH);
   } 
 }


 void loop ()
 {
   for (int i = 0; i <10; i ++)
   {
     displayDigit (i);
     delay (1000);
     AllOff ();
     delay (500);
   }   
 }

 displayDigit void (int digit)
 {
   for (int i = 0; i <8; i ++)
   {
     digitalWrite (ledpins [i] ,! bitRead (digits [Scan], 7-i));
   } 
 }

 void AllOff ()
 {
   for (int i = 0; i <8; i ++)
   {
     digitalWrite (ledpins [i], HIGH);
   }  
 }
In this case not used the BCD outputs but a direct binary code in 8 bits (one for each connected LED)
We used a level 1 (HIGH) when the segment lights and 0 (LOW) when deleted. The last digit is always a 0 represents the decimal point that is not being used.

The AllOff () procedure off all digits reversing the common pin.

displayDigit () connects the right thread for each digit. The function bitread reads the bits of the binary number, starting with the rightmost bit.That's why the 7-i is used. When using the digitalWrite () statement, we can write 1 when we want to HIGH and LOW 0 when we want. This is the opposite of how our binary numbers are working. The operator! inverts the value. via electronica-pt.com

Comments

Popular posts from this blog

One Chip AM/FM Radio with Audio Power Amplifier

Description: The integrated circuit TDA1083 includes, with exception  of the FM front end, a complete AM-/FM-radio-circuit  with audio power amplifier. An internal Z-diode  stabilizes the supply voltage at VS 13 V, which allows  with the aid of a resistor and a rectifier, the circuit to be  driven by a higher external supply voltage. Features: Large supply voltage range VS = 3 to 12 V High AM-Sensitivity Limiting threshold voltage Vi = 50 V Audio output power P0 = 0.7 W AFC-connection for VHF-tuner AM-FM switching without high frequency voltages Applications: AM-/FM- and audio-amplifier Circuit Diagram: Circuit diagram for One Chip AM/FM Radio with Audio Power Amplifier Datasheet for TDA1083:   Download

2 x 15 W stereo Bridge Tied Load (BTL) audio amplifier

General description: The TDA8946J is a dual-channel audio power amplifier with an output power of 2 × 15 W at an 8 Ω load and a 18 V supply. The circuit contains two Bridge Tied Load (BTL) amplifiers with an all-NPN output stage and standby/mute logic. The TDA8946J comes in a 17-pin DIL-bent-SIL (DBS) power package. The TDA8946J is printed-circuit board (PCB) compatible with all other types in the TDA894x family. One PCB footprint accommodates both the mono and the stereo products. Features: Few external components Fixed gain Standby and mute mode No on/off switching plops Low standby current High supply voltage ripple rejection Outputs short-circuit protected to ground, supply and across the load Thermally protected Printed-circuit board compatible Circuit Diagram: Circuit Diagram for 2 x 15 W stereo Bridge Tied Load (BTL) audio amplifier PCB layout: PCB layout TDA8946 Datasheet for TDA8946J:   Download

200W Hybrid Audio Amplifier Circuit

200W Hybrid Audio Amplifier Circuit - c onnecting two TDA2030 thru cheap power transistors we can create a amplifier wich can deliver a higher power. With the components value from the schematic the total amplifier gain is 32 dB. The speaker can be 2 ohm instead of 4 ohm if we use the TIP transistors. TDA 2030 is produced by SGS Ates and is a complete audio amplifier. AB class of the final amplifier cand deliver up to 14W on 4 ohm at a +-14V power supply. With a proper designed power supply this audio amplifier can output 200W. Active components: IC1, Ic2 TDA 2030 T1, T3 = BD 250, TIP 36 T2,T4 = BD 249, TIP 35 D1 … D4 = 1N4001 200W Hybrid Audio Amplifier Circuit