กลับไปหน้ารวมไฟล์
kitty-bank-9eb522-en.md

I had this science fair coming up soon and I needed something killer! That is when this idea struck my mind when I saw my unused RC522 module sitting alone in the darkness collecting dust.

In short and brief words, this "kitty bank" works by first unlocking it with a RFID card. Then, when you place a coin on the hatch, it completes a circuit that triggers a servo motor to open the hatch. As soon as the hatch opens, the coin falls down into the box and the circuit is no longer completed; the hatch closes again.

Codeexplanation:

#include 
#include
#include

Imports of the servo, MFRC22 and SPI libraries

int SS_PIN = 10;
int RST_PIN = 9;
int green = 7;
int red = 6;
bool permission = false;
int reading_pin = A0;
int button_pin = 2;
int button_state = 0;

Global variables, including the pins.

MFRC522 mfrc522 (SS_PIN, RST_PIN);
Servo servo;

External libraries variables

void setup() {
pinMode(green, OUTPUT);
pinMode(red, OUTPUT);
pinMode(reading_pin, INPUT);
pinMode(button_pin, INPUT);
Serial.begin(9600); // Initiate serial monitor
mfrc522.PCD_Init(); // Initiate MFRC522
SPI.begin(); // Initiate SPI bus
servo.attach(8); //servo pin
servo.write(0); //servo start position
}

The setup() function for the Arduino. It includes all the pin modes, the starting position of the servo motor, the serial monitor etc.

void loop() {

Here the loop() function starts!

if (permission == true) {
if (analogRead(reading_pin) >= 1000) {
servo.write(180);
delay(1000);
servo.write(0);
}
}

This part opens the hatch if it detects that the circuit is completed (Note: the permission variable is a boolean that tells the program that the kitty bank is unlocked)

button_state = digitalRead(button_pin);
if (button_state == HIGH) {
permission = false;
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
}

This part is self-explanatory. Basically, when a button is pressed, it sends a voltage signal to the Arduino Uno board; it reacts by locking the kitty bank by changing the permission variable to false.

// Check if new card is present
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}

Normal initializing code for the RC522 module.

//Show UID on serial monitor
Serial.print("UID tag :");
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}

Gets the UID tag of the card that is scanned by the RC22 module.

Serial.println();
Serial.print("Message : ");
content.toUpperCase();
if (content.substring(1) == "THE CORRECT CARD'S UID") {
Serial.println("Authorized access");
Serial.println();
digitalWrite(green, HIGH);
delay(1000);
digitalWrite(green, LOW);
permission = true;
delay(500);
}

This part of the code checks if the UID tag matches the right one; if it matches, it will turn on the green light for 1 second, followed by changing the permission variable to true.

else if (content.substring(1) != "THE CORRECT CARD'S UID") {
Serial.println(" Access denied");
permission = false;
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
delay(500);
}

Similarly, if the card is the wrong one, it will turn on the red LED for 1 second and change the permission variable to false.

EXPANDED TECHNICAL DETAILS

Kinetic Prop Interaction

The Kitty Bank is a charming, coin-operated mechanical bank that uses infrared detection and servo-driven animations.

  • Optical Coin Trigger: A phototransistor or IR proximity sensor is placed in the coin tray. When a coin is laid on the tray, the sensor triggers an "Animation State" in the Arduino.
  • Synchronized Servo Choreography: Manages two SG90 servos; one to slowly lift the "Kitty's Head" from the box and another to sweep the "Paw" to pull the coin inside.

Sound Integration

  • Acoustic Reward: Simultaneously with the animation, the Arduino triggers a piezo speaker or an MP3 module to play a "Meow" or a "Thank You" sound, providing a complete multi-sensory interactive experience.

ข้อมูล Frontmatter ดั้งเดิม

title: "Kitty bank"
description: "A safe bank for all your coins!"
author: "analoger"
category: ""
tags:
  - "rfid"
  - "security"
  - "robots"
views: 316
likes: 1
price: 2450
difficulty: "Intermediate"
components:
  - "1x Resistor 10k ohm"
  - "1x Soldering iron (generic)"
  - "1x SG90 Micro-servo motor"
  - "1x Push button (Generic)"
  - "1x RFID-RC522 module"
  - "1x RGB Diffused Common Cathode"
  - "1x Arduino UNO"
tools: []
apps:
  - "1x Arduino IDE"
downloadableFiles:
  - "https://projects.arduinocontent.cc/6ad36c39-b59f-4a79-a06e-6594a82d4dc9.ino"
  - "https://projects.arduinocontent.cc/6ad36c39-b59f-4a79-a06e-6594a82d4dc9.ino"
documentationLinks: []
passwordHash: "491f9bf8120dcf140bc7d299ab52c94bec8aedf655f38a562a3981af92b8c6b0"
encryptedPayload: "U2FsdGVkX1/mI0OU1crVSm4UEvbzj6367Vno7UMa/zQWl5RFrF8CnmZK7wzHJJ6G5or0mFTnCkCHe8oRlJw/fFs9b3VhRxM+kH3251S8B28="
seoDescription: "Build a DIY Kitty bank using Arduino and Servo to securely store your coins in this fun electronics project."
videoLinks: []
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/kitty-bank-9eb522_cover.jpg"
lang: "en"