Hello and welcome back with yet another tutorial. This time, its the most widely and commonly used 7-segment display. A 7-segment display is used to display digits or even alphabets. They are commonly used for timers but today we will use it to display voltage output of a light dependent resistor (LDR) or simply a photo-resistor. This practical application will provide us with a better understanding of how a 7-segment works. So, lets get started.
Brief about 7-segment display:The 7-segment display, also written as “seven segment display”, consists of seven LEDs (hence its name) arranged in a rectangular fashion as shown. Each of the seven LEDs is called a segment because when illuminated the segment forms part of a numerical digit (both Decimal and Hex) to be displayed. An additional 8th LED () is sometimes used within the same package thus allowing the indication of a decimal point, (DP) when two or more 7-segment displays are connected together to display numbers greater than ten.
STEP 1: Setup Arduino IDE for SurilliMake sure you have selected the right port, board and processor for the Surilli as shown in the picture below and it is programmable (compile and upload “Blink” from File>Examples>Digital>Blink onto your Surilli to check if everything is working fine).
STEP 2: The circuitryThe circuitry is a little tricky so we will go through it first. Complete your circuit connections and then move on to the next step.
NOTE: LDRs are sold by different manufacturers so their pin-outs often vary. Consult the datasheet of your specific part to find out correct pin-outs.
STEP 3: Upload & Burn Code Onto Surilli- If you do not have the AnalogInput library, download it from the source given below. Unzip the downloaded .rar file and paste in into: This PC > Documents > Arduino > libraries.
- Now you have completed setting up your hardware and Arduino IDE. Copy and paste the Arduino sketch given below into your Arduino IDE and hit upload.
- After it is uploaded, the 7-segment will start to show output voltage of the LDR sensor as shown in the GIF below.
Change the lightning around the LDR by placing your hand over it or flashing it with a torch light. You will see how voltage varies on the 7-segment display as you do so.
#include <AnalogInput.h>
int num_array[10][7] = {
{ 1, 1, 1, 1, 1, 1, 0 }, // 0
{ 0, 1, 1, 0, 0, 0, 0 }, // 1
{ 1, 1, 0, 1, 1, 0, 1 }, // 2
{ 1, 1, 1, 1, 0, 0, 1 }, // 3
{ 0, 1, 1, 0, 0, 1, 1 }, // 4
{ 1, 0, 1, 1, 0, 1, 1 }, // 5
{ 1, 0, 1, 1, 1, 1, 1 }, // 6
{ 1, 1, 1, 0, 0, 0, 0 }, // 7
{ 1, 1, 1, 1, 1, 1, 1 }, // 8
{ 1, 1, 1, 0, 0, 1, 1 }
}; // 9
void setup()
{
// define pin modes
pinMode(13, INPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
pinMode(A4, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
}
AnalogInput analoginput (9, 13);//AnalogInput analoginput (InputPin, OutputPin):
char pin [] = {A1, A2, A3, A4, 10, 11, 12};
void loop()
{
//counter loop
int s = analoginput.exec();
int v = (s*5)/123;
Num_Write(v);
Serial.println(s);
Serial.println(v);
delay(1000);
}
// this functions writes values to the sev seg pins
void Num_Write(int number)
{
for (int j = 0; j < 7; j++) {
digitalWrite(pin[j], num_array[number][j]);
}
}
That’s all for now. If you have any queries, visit our website surilli.io or contact our support. Stay connected with Surilli family for more amazing stuff :)



















Comments