Thursday 29 January 2015

Arduino 7 Segment

Arduino 7segment

       One of the simple projects with the Arduino is 7 segment project. 7 segment is a display device to show numbers. It includes 7 or 8 LED and this is where its name comes.



       There are two type of 7 segments; common anode, common cathode. When we want to use common cathode(-), we should connect the common pin to ground and other pins to Arduino and we should arrange the output as 5V for which LED's we want to turn on. If we want to use common anode(+), we should connect the common anode(+) pin to another digital pin adn its output voltage must be 5V. Than we should arrange the output as 0V for which LED's we want to turn on. And of course we should use a resistor to protect LED's. Connect the resistor to common pin instead of using resistor for every pin. As a result of this common cathode(-) is more usable. There is a schematic for a common cathode(-) 7 segment.



       There are some borders for Arduino. Current border for Arduino is 40mA for a pin and the total upper border is 200mA. We should compute the current to protect Arduino. I do not suggest you to force theese borders especially for the clon Arduino.
       If we do not know the type of 7 segment, we can learn it with a simple test. Use a cable and 1KΩ resistor. Connect the resistor to cable and the cable to Arduino's 5V pin. Use another cable and connect this cable to ground pin. First of all choose a pin and connect the ground cable to this pin. Then start to check other pins with 5V cable. If you see the light, your 7 segment is common cathode(-) and the ground connected pin is common pin. If you cannot see the light, change the pin for ground. If you still do not see the light, hold the 5V pin and start to check with ground pin. If you see the light, your 5V pin is the common anode(+) pin.



Theese are the pin connection numbers for 7 segment. It makes easier the codding. 













The code should be like this for the common cathode(-) 7 segment

/*First of all we decide the pins for 7 segment and we arrange them as output pin. */ 

void setup() {
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}

void loop() {
  /* We decided the pins in SETUP function.
 Now, we are arranging the values of pins to turn the LED's on*/
  
//for the number 0
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
  delay(1000);
//number 1
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
  delay(1000);

//number 2
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
  delay(1000);

//number 3
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13,LOW);
  delay(1000);
 
//number 4
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
  delay(1000);

  
//number 5
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
  delay(1000);

//number 6
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
  delay(1000);

//number 7
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
  delay(1000);
//number 8
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
  delay(1000);

//number 9
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
  delay(1000);

//for dot
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
delay(1000);
}

       We should see the numbers in an order as a result of this project. Making different projects with 7 segment is possible. You can increase or decrease the numbers with a button. We are here for your suggestions and questions. Keep in touch!


If you liked this post please subscribe it to reach more people! Thank you :)

No comments :

Post a Comment

Thanks for your comments :)