Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Bluetooth-Controlled LED Matrix Display with Arduino Nano

View and Edit Project In Cirkit DesignerImage of Bluetooth-Controlled LED Matrix Display with Arduino Nano

Circuit Documentation

Summary

The circuit in question is designed to interface an HC-05 Bluetooth module with an Arduino Nano microcontroller to control an 8x8 LED matrix display. The Arduino Nano receives data via Bluetooth and drives the LED matrix to display characters or animations. The circuit is powered by a 6V battery pack consisting of four AA batteries.

Component List

HC-05 Bluetooth Module

8x8 LED Matrix

Arduino Nano

Battery AAx4 6V

Wiring Details

HC-05 Bluetooth Module

8x8 LED Matrix

Arduino Nano

Battery AAx4 6V

Documented Code

#include <LEDMatrixDriver.hpp>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(6, 7); // RX, TX-ble 7 rx

const uint8_t LEDMATRIX_CS_PIN = 10;

const int LEDMATRIX_SEGMENTS = 4;
const int LEDMATRIX_WIDTH    = LEDMATRIX_SEGMENTS * 10;

LEDMatrixDriver lmd(LEDMATRIX_SEGMENTS, LEDMATRIX_CS_PIN);

String str="hjhjbhj";
int str_len = str.length() + 1; 

// Marquee speed (lower numbers = faster)
const int ANIM_DELAY = 70;

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
  mySerial.println("test");
  // init the display
  lmd.setEnabled(true);
  lmd.setIntensity(9);   // 0 = low, 10 = high
}

int x=0, y=0;   // start top left

byte font[95][8] = { 
  // Font data removed for brevity
};

void loop()
{
   if (mySerial.available()>0) {
     str=mySerial.readStringUntil('\n');
     Serial.println(str);
   }
   str_len = str.length() + 1;
   char char_array[str_len];
   str.toCharArray(char_array, str_len);
   
   // Draw the text to the current position
   int len = strlen(char_array);
   drawString(char_array, len, x, 0);
   // In case you wonder why we don't have to call lmd.clear() in every loop: The font has an opaque (black) background...

   // Toggle display of the new framebuffer
   lmd.display();

   // Wait to let the human read the display
   delay(ANIM_DELAY);

   // Advance to next coordinate
   if( --x < len * -8 ) {
     x = LEDMATRIX_WIDTH;
   }
}

/**
 * This function draws a string of the given length to the given position.
 */
void drawString(char* text, int len, int x, int y )
{
  for( int idx = 0; idx < len; idx ++ )
  {
    int c = text[idx] - 32;

    // stop if char is outside visible area
    if( x + idx * 8  > LEDMATRIX_WIDTH )
      return;

    // only draw if char is visible
    if( 8 + x + idx * 8 > 0 )
      drawSprite( font[c], x + idx * 8, y, 8, 8 );
  }
}

/**
 * This draws a sprite to the given position using the width and height supplied (usually 8x8)
 */
void drawSprite( byte* sprite, int x, int y, int width, int height )
{
  // The mask is used to get the column bit from the sprite row
  byte mask = B10000000;

  for( int iy = 0; iy < height; iy++ )
  {
    for( int ix = 0; ix < width; ix++ )
    {
      lmd.setPixel(x + ix, y + iy, (bool)(sprite[iy] & mask ));

      // shift the mask by one pixel to the right
      mask = mask >> 1;
    }

    // reset column mask
    mask = B10000000;
  }
}

Note: The font data array has been removed for brevity. The code is responsible for initializing the LED matrix and the Bluetooth module, receiving data from the Bluetooth module, and displaying the received text on the LED matrix. The drawString and drawSprite functions are used to render the text on the display.