Finger Count 2.0ο
Note
π Welcome to the SunFounder Facebook Community! Whether youβre into Raspberry Pi, Arduino, or ESP32, youβll find inspiration, help ideas here.
β Be the first to get free learning resources.
β Stay updated on new products & exclusive giveaways.
β Share your creations and get real feedback.
Kit purchaseο
Looking for parts? Check out our all-in-one kits below β packed with components, beginner-friendly guides, and tons of fun.
Name |
Includes Arduino board |
PURCHASE LINK |
|---|---|---|
Ultimate Sensor Kit |
Arduino Uno R4 Minima |
|
Elite Explorer Kit |
Arduino Uno R4 WiFi |
|
3 in 1 Ultimate Starter Kit |
Arduino Uno R4 Minima |
|
Universal Maker Sensor Kit |
Γ |
Course Introductionο
This code controls a series of LEDs on an Arduino Uno 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. The Arduino then lights up the corresponding number of LEDs.
The LEDs are connected to digital pins 2 through 6, with the number of lit LEDs corresponding to the finger count detected by the Python script.
Note
If this is your first time working with an Arduino project, we recommend downloading and reviewing the basic materials first.
Required Components
In this project, we need the following components:
SN |
COMPONENT INTRODUCTION |
QUANTITY |
PURCHASE LINK |
|---|---|---|---|
1 |
Arduino UNO R4 Minima |
1 |
|
2 |
USB Type-C cable |
1 |
|
3 |
Breadboard |
1 |
|
4 |
Wires |
Several |
|
5 |
1kΞ© resistor |
Several |
|
6 |
LED |
Several |
Wiring
Common Connections:
LED
Connect the LEDs cathode to a 1kΞ© resistor then to the negative power bus on the breadboard, and the LEDs anode to the 2 to 6 on the Arduino.
Operating Steps
Note
Copy the following code into Arduino IDE.
Select the board(Arduino UNO R4 Minima) and then clicking the Upload button.
Then use the Python code
FingerCountSender (3). You can click hereFingerCountSender (3).zipto download it.- Update the Python script to use the correct serial port(COMx), ensuring it matches the one identified during Arduino setup(COMx).
Then run the python code to open the camera window.
// Define the LED pins
const int ledPins[] = {2, 3, 4, 5, 6}; // Pins where the LEDs are connected
const int numLeds = 5; // Number of LEDs
void setup() {
// Initialize the LED pins as outputs
for (int i = 0; i < numLeds; i++) {
pinMode(ledPins[i], OUTPUT);
digitalWrite(ledPins[i], LOW); // Ensure all LEDs are off initially
}
// Start serial communication
Serial.begin(115200);
Serial.setTimeout(1);
}
void loop() {
// Check if data is available on the serial port
if (Serial.available() > 0) {
// Read the incoming data
int value = Serial.readString().toInt();
// Ensure the value is within the range 0-5
if (value >= 0 && value <= numLeds) {
// Turn off all LEDs first
for (int i = 0; i < numLeds; i++) {
digitalWrite(ledPins[i], LOW);
}
// Turn on the appropriate number of LEDs
for (int i = 0; i < value; i++) {
digitalWrite(ledPins[i], HIGH);
}
}
}
}