Saturday, March 31, 2018

7 Segment 4 digit display using Arduino MEGA 2560

In this blog we are going to demonstrate how to use 7 segment 4 digit display with a arduino Mega 2560 board.

Parts required:

1. Arduino MEGA 2560 board

2. Bread board















3. 7 Segment 4 digit with 12 pins.






4. Jumper wires.















5. A-Male to B-Male cable















6. 4 220 Ohms resistors (4)
















Step 1: Download the Seven segment display controller library for Arduino : https://github.com/DeanIsMe/SevSeg/archive/master.zip
After downloading place it inside the library folder of your arduino IDE.
Make sure you will see content as follows.


Step2 : Please have a look at the pin diagram of 7 segment display – 4 digit (This is specific to the model i have mentioned above)
  


Really hard to find these details in net.
Now make the circuit as below

Note : Digit Pins
Pin 12 of 7 segment – D1 => pin 13 of arduino
Pin 9 of 7 segment –  D2 => 12 of arduino
Pin 8 of 7 segment -D3 => 11 of arduino
Pin 6 of 7 segment -D4 => 10 of arduino
Pin 11 of 7 segment -a => 2 of arduino
Pin 7 of 7 segment -b=> 3 of arduino
Pin 4 of 7 segment -c=> 4 of arduino
Pin 2 of 7 segment -d=> 5 of arduino
Pin 1 of 7 segment -e  => 6 of arduino
Pin 10 of 7 segment -f => 7 of arduino
Pin 5 of 7 segment -g => 8 of arduino
Pin 3 of 7 segment -p => 9 of arduino
Make sure to add 220 ohms of resistor for D1, d2, d3, d4 pins to regulate the current flow.
open arduino IDE and paste below code. If you need to know how to setup arduino IDE for first time , refer my previous post
/* SevSeg Counter Example
 Edited by Haneef Puttur to match SMA420564 (www.haneefputtur.com)
 Copyright 2014 Dean Reading
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at 
 http://www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 
 
 This example demonstrates a very simple use of the SevSeg library with a 4
 digit display. It displays a counter that counts up, showing 10 deci-seconds.
 */

#include "SevSeg.h"

SevSeg sevseg; //Instantiate a seven segment controller object

 void setup() {
 byte numDigits = 4; 
 byte digitPins[] = {10, 11, 12, 13};
 byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 9};

sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins); 
// If your display is common anode type, please edit comment above line and uncomment below line
// sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins);
sevseg.setBrightness(90);
}

void loop() {
 static unsigned long timer = millis();
 static int deciSeconds = 0;
 
 if (millis() >= timer) {
 deciSeconds++; // 1000 milliSeconds is equal to 10 deciSecond
 timer += 1000; 
 if (deciSeconds == 10000) { // Reset to 0 after counting for 1000 seconds.
 deciSeconds=0;
 }
 sevseg.setNumber(deciSeconds, 1);
 }

 sevseg.refreshDisplay(); // Must run repeatedly
}

/// END ///
Now compile and upload the program to arduino

upload

No comments:

Raspberry Pi with Pi Camera

Raspberry Pi with Pi Camera In this module, I will describe on how to connect and use Pi Camera with Raspberry Pi. Requirements: ...