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.

  • πŸ‘‰ Need faster updates or support? Click [here] join our Facebook community

  • πŸ‘‰ Or join our WhatsApp group: Click [here]

Kit purchase

Looking for parts? Check out our all-in-one kits below β€” packed with components, beginner-friendly guides, and tons of fun.

../_images/elite_explore_kit.png

Name

Includes Arduino board

PURCHASE LINK

Ultimate Sensor Kit

Arduino Uno R4 Minima

BUY

Elite Explorer Kit

Arduino Uno R4 WiFi

BUY

3 in 1 Ultimate Starter Kit

Arduino Uno R4 Minima

BUY

Universal Maker Sensor Kit

Γ—

BUY

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

BUY

2

USB Type-C cable

1

3

Breadboard

1

BUY

4

Wires

Several

BUY

5

1kΞ© resistor

Several

BUY

6

LED

Several

BUY

Wiring

../_images/finger_count_bb.png

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

  1. Copy the following code into Arduino IDE.

  2. Select the board(Arduino UNO R4 Minima) and then clicking the Upload button.

  3. Then use the Python code FingerCountSender (3) . You can click here FingerCountSender (3).zip to download it.

  4. Update the Python script to use the correct serial port(COMx), ensuring it matches the one identified during Arduino setup(COMx).
    ../_images/port1.png
  5. 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);
      }

    }
  }
}