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

Arduino UNO-Based Card Counter with IR Sensor and LCD Display

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Card Counter with IR Sensor and LCD Display

Circuit Documentation

Summary

This circuit is designed to control a card counting system using an Arduino UNO microcontroller. The system includes an IR sensor to detect cards, an LCD to display the count, pushbuttons for control, and a motor driver to move the cards. The circuit is powered by a 12V battery.

Component List

  1. Arduino UNO

    • Description: Microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. IR Sensor

    • Description: Infrared sensor for detecting objects.
    • Pins: out, gnd, vcc
  3. 16x2 I2C LCD

    • Description: 16x2 character LCD with I2C interface.
    • Pins: GND, VCC, SDA, SCL
  4. L298N DC Motor Driver

    • Description: Dual H-Bridge motor driver for controlling DC motors.
    • Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB
  5. Motor and Wheels

    • Description: DC motor with attached wheels.
    • Pins: vcc, GND
  6. Pushbutton

    • Description: Momentary pushbutton switch.
    • Pins: Pin 2, Pin 1, Pin 3, Pin 4
  7. Battery 12V

    • Description: 12V battery for powering the circuit.
    • Pins: +, -

Wiring Details

Arduino UNO

IR Sensor

16x2 I2C LCD

L298N DC Motor Driver

Motor and Wheels

Pushbutton

Battery 12V

Code Documentation

#include <Scheduler.h>
#include <HardWire.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

const int onOffButtonPin = 3;
const int startStopButtonPin = 4;
const int resetButtonPin = 5;
const int irSensorPin = 2;

const int motor1Pin1 = 10;
const int motor1Pin2 = 9;
const int motor2Pin1 = 8;
const int motor2Pin2 = 7;

bool isOn = false;
bool isRunning = false;
int cardCount = 0;

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  pinMode(onOffButtonPin, INPUT_PULLUP);
  pinMode(startStopButtonPin, INPUT_PULLUP);
  pinMode(resetButtonPin, INPUT_PULLUP);
  pinMode(irSensorPin, INPUT);

  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
  pinMode(motor2Pin1, OUTPUT);
  pinMode(motor2Pin2, OUTPUT);

  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Card Counter");
  lcd.setCursor(0, 1);
  lcd.print("Count: 0");

  Serial.begin(9600);
}

void loop() {
  if (digitalRead(onOffButtonPin) == LOW) {
    delay(50); // Debounce delay
    if (digitalRead(onOffButtonPin) == LOW) {
      isOn = !isOn;
      Serial.println(isOn ? "System On" : "System Off");
      while (digitalRead(onOffButtonPin) == LOW); // Wait for button release
    }
  }

  if (digitalRead(startStopButtonPin) == LOW) {
    delay(50); // Debounce delay
    if (digitalRead(startStopButtonPin) == LOW) {
      if (isOn) {
        isRunning = !isRunning;
        Serial.println(isRunning ? "System Running" : "System Stopped");
      }
      while (digitalRead(startStopButtonPin) == LOW); // Wait for button release
    }
  }

  if (digitalRead(resetButtonPin) == LOW) {
    delay(50); // Debounce delay
    if (digitalRead(resetButtonPin) == LOW) {
      if (isOn) {
        cardCount = 0;
        lcd.setCursor(0, 1);
        lcd.print("Count: ");
        lcd.print(cardCount);
        Serial.println("System Reset");
      }
      while (digitalRead(resetButtonPin) == LOW); // Wait for button release
    }
  }

  if (isOn && isRunning) {
    moveCard();
    if (digitalRead(irSensorPin) == LOW) {
      cardCount++;
      lcd.setCursor(0, 1);
      lcd.print("Count: ");
      lcd.print(cardCount);
      delay(500); // Debounce delay for IR sensor
    }
  }
}

void moveCard() {
  // Move card with Motor 1
  digitalWrite(motor1Pin1, HIGH);
  digitalWrite(motor1Pin2, LOW);
  delay(500); // Adjust delay as needed to move one card

  // Stop Motor 1
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, LOW);

  // Move card with Motor 2
  digitalWrite(motor2Pin1, HIGH);
  digitalWrite(motor2Pin2, LOW);
  delay(500); // Adjust delay as needed to move one card

  // Stop