Ten segment LED bar graph and Arduino

Ten segment led bars are made of 10 individual LEDs, all contained in one plastic body, each with an individual anode and cathode connection.
They come in different colors, have many uses and are easy to hookup.
Ten segment led bar graph can be be used to displaly all sort of information, so I used four of them to display the movement of a analog JoyStick module.

LM3916 – Dotbar display driver

The easiest way to control a Ten segment led bar is using a LM3916 IC that can power all 10 individual leds in two modes: dot or bar.
The LM3914/5/6 has 18 pins, you can set both the current flowing through the LED , and the high voltage end of the voltage divider with two resistors, and it has one analog input that can be connected to a potentiometer or an analog sensor.
We can swap between dot or bar mode by setting the pin 9 to low or high respectively.
You can find the LM3916 pinout and the hookup guide on this page .

Display analog JoyStick module movement with Arduino UNO and ten segment led bar graph


It is very simple to connect analog JoyStick module to Arduino . You can find a hookup guide to this article: Arduino analog JoyStick module.

The Arduino will receive the analog signal from the JoyStick module, ant will forward it to the LM3916 dotbar display driver.
The LM3916 input pin accepts only an analog singal and it is quite difficult to generate a real analog output from Arduino UNO.
If we use PWM, the analogWrite function, will change only the duty cicle but the output voltage will still be 5v, so, as a result, all 10 leds from the “ten segment LED bar”  will be on, and only the brightness will vary.
Only the Arduino Due supports true analog output, because it has two special pins: DAC0 and DAC1 that are Digital to Analog converters.

In order to create a true analog signal on Arduino UNO, it is necessary to modify the PWM signal using a filter. A low pass filter as shown HERE is the correct type to use for this project.
The filter is made from a 4.7 kΩ resistor and a 10uF electrolitic capacitor. After the signal is filtered, one LM358 Dual Operational Amplifier is used in order to amplify the singnal , withch is, then, sent to LM3916 input/signal pin 4.
You can find the filter and the hookup guide in the folowing photo gallery.

After testing on the breadboard with one “ten segmant LED bar” , we take a step further and use 4 led bars witch represent the two axes of the JoyStick module .
I had soldered all the components on the PCB, ledbars are arranged in the shape of a cross and in the middle i attached a led that will be ON when the JoyStick button will be pressed.

Below you can find the Arduino sketch that controls all the four “ten segmant LED bars”  and the 5mm led.

// joystick pins
const int SWITCH = 2; // digital pin connected to switch output of joystick
const int X_AX = A0; // analog pin connected to X output of joystick
const int Y_AX = A1; // analog pin connected to Y output of joystick
//ledbar pins
const int ledbar_X_plus = 5;
const int ledbar_Y_plus = 6;
int val_ledbar_X_plus = 0;         // variable to store the read value
int val_ledbar_Y_plus = 0;         // variable to store the read value
const int ledbar_X_minus = 10;
const int ledbar_Y_minus = 9;
int val_ledbar_X_minus = 0;         // variable to store the read value
int val_ledbar_Y_minus = 0;         // variable to store the read value
const int ledPin = 4;

void setup() {
  pinMode(ledbar_X_plus, OUTPUT);
  pinMode(ledbar_Y_plus, OUTPUT);
  analogWrite(ledbar_X_plus, LOW);
  analogWrite(ledbar_Y_plus, LOW);
  pinMode(ledbar_X_minus, OUTPUT);
  pinMode(ledbar_Y_minus, OUTPUT);
  analogWrite(ledbar_X_minus, LOW);
  analogWrite(ledbar_Y_minus, LOW);
  pinMode(SWITCH, INPUT);
  digitalWrite(SWITCH, HIGH);
  pinMode(ledPin, OUTPUT);

void loop() {
  // led on if we push the joystick
  if (digitalRead(SWITCH) > 0) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  // process joystick moves on X axis
  int output = 0;
  int middle_of_axis = 520;
  int max_of_axis = 1023;
  int val_read = analogRead(X_AX);
  if (val_read >= middle_of_axis) {
    //above zero values on axis
    val_ledbar_X_plus = map( val_read, middle_of_axis, max_of_axis, 0, 255);
    if (val_ledbar_X_plus > 255) {
      val_ledbar_X_plus = 255;
    val_ledbar_X_minus = 0;
  } else {
    val_ledbar_X_minus = map( val_read, middle_of_axis, 0, 0, 255);
    if (val_ledbar_X_minus < 0) { val_ledbar_X_minus = 0; } val_ledbar_X_plus = 0; } analogWrite(ledbar_X_minus, val_ledbar_X_minus); analogWrite(ledbar_X_plus, val_ledbar_X_plus); Serial.print ("x: " ); Serial.print (val_read); Serial.print (" "); Serial.print (val_ledbar_X_plus); Serial.print (" "); Serial.println (val_ledbar_X_minus); // delay(200); output = 0; middle_of_axis = 504; max_of_axis = 1023; val_read = analogRead(Y_AX); if (val_read >= middle_of_axis) {
    //above zero values on axis
    val_ledbar_Y_plus = map( val_read, middle_of_axis, max_of_axis, 0, 255);
    if (val_ledbar_Y_plus > 255) {
      val_ledbar_Y_plus = 255;
    val_ledbar_Y_minus = 0;
  } else {
    val_ledbar_Y_minus = map( val_read, middle_of_axis, 0, 0, 255);
    val_ledbar_Y_plus = 0;
  analogWrite(ledbar_Y_plus, val_ledbar_Y_plus);
  analogWrite(ledbar_Y_minus, val_ledbar_Y_minus);
  Serial.print ("y: " );
  Serial.print (val_read);
  Serial.print (" ");
  Serial.print (val_ledbar_Y_plus);
  Serial.print (" ");
  Serial.println (val_ledbar_Y_minus);


Leave a Reply

Your email address will not be published. Required fields are marked *