Arduino Project
Finger Count 1.0
Course Introduction
This project controls the LED matrix on an Arduino Uno R4 WiFi board based on finger count data received from a Python script. The script detects the number of fingers shown to a camera and sends this data to the Arduino via serial communication(USB). The Arduino then displays the corresponding number on the LED matrix.
Note
If this is your first time working with an Arduino project, we recommend downloading and reviewing the basic materials first.
1.1 Install Arduino IDE(Important)
1.2 Introduction of Arduino IDE
Required Components
In this project, we need the following components:
SN | COMPONENT INTRODUCTION | QUANTITY | PURCHASE LINK |
1 | Arduino UNO R4 WIFI | 1 | |
2 | USB Type-C cable | 1 | × |
Operating Steps
Copy the following code into Arduino IDE.
Use the Arduino Library Manager and search for ArduinoGraphic and Arduino_LED_Matrix install libraries.
Select the board(Arduino UNO R4 WIFI) and then clicking the Upload button.
Then use the Python code FingerCountSender. You can click here FingerCountSender.zip to download it.
Update the Python script to use the correct serial port(COMx).
Then run the python code to open the camera window.
#include "ArduinoGraphics.h"
#include "Arduino_LED_Matrix.h"
ArduinoLEDMatrix matrix;
char lastChar = '\0'; // Variable to store the last read character
void setup() {
// Start serial communication
Serial.begin(115200);
Serial.setTimeout(1);
matrix.begin();
delay(500);
}
void loop() {
// Check if data is available on the serial port
if (Serial.available() > 0) {
// Read one character from serial input
char c = Serial.read();
// Check if the new character is different from the last character
if (c != lastChar) {
// Update the last character
lastChar = c;
// Clear the matrix before displaying the new character
matrix.clear();
matrix.beginDraw();
matrix.stroke(0xFFFFFFFF); // Set stroke color
matrix.textFont(Font_5x7); // Set font
matrix.beginText(4, 1, 0xFFFFFF); // Position and color for text
matrix.print(c); // Display the character
matrix.endText();
matrix.endDraw();
}
// Delay to prevent too frequent updates (optional)
delay(10);
}
}
}