zirjagor
Published

Pet feeder

The RGB LED always green until the MFRC522 RFID module is enabled, and then turn blue for 2 seconds, red for 5 seconds, blue for 2 seconds.

AdvancedFull instructions provided97
Pet feeder

Things used in this project

Hardware components

Jumper wires (generic)
Jumper wires (generic)
×1
MFRC522 RFID Module
×1
Arduino Mega 2560
Arduino Mega 2560
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1
9G Servo
×1
Resistor 220 ohm
Resistor 220 ohm
×3

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Instructions

No photo needed.

Schematics

Instructions

No photo needed.

magnificent_kup-bombul_(9)_dx1Db3sZHJ.stl

Code

Code (enjoy)

Python
Install servo from Library Manager.
Install MFRC522 RFID Module from Library Manager.
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>

#define SS_PIN 53
#define RST_PIN 5

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
Servo servo; // Create servo object

const int redPin = 9; // Red LED pin
const int greenPin = 10; // Green LED pin
const int bluePin = 11; // Blue LED pin

void setup() {
  Serial.begin(9600); // Initialize serial communication
  SPI.begin(); // Initialize SPI communication
  mfrc522.PCD_Init(); // Initialize MFRC522
  servo.attach(6); // Attach servo to pin 6
  pinMode(redPin, OUTPUT); // Set red LED pin as output
  pinMode(greenPin, OUTPUT); // Set green LED pin as output
  pinMode(bluePin, OUTPUT); // Set blue LED pin as output
  // Turn on green LED and turn off red and blue LEDs
  digitalWrite(redPin, LOW);
  digitalWrite(greenPin, HIGH);
  digitalWrite(bluePin, LOW);
}

void loop() {
  // Check for new RFID card
  if (mfrc522.PICC_IsNewCardPresent()) {
    // Select the scanned card
    MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
    if (piccType != MFRC522::PICC_TYPE_UNKNOWN) {
      // LED blue for 2 seconds
      digitalWrite(bluePin, HIGH);
      delay(2000);
      digitalWrite(bluePin, LOW);
      // LED red for 5 seconds
      digitalWrite(redPin, HIGH);
      digitalWrite(greenPin, LOW);
      digitalWrite(bluePin, LOW);
      // Rotate servo 180 degrees and back in the 5 seconds of being red
      for (int i = 0; i <= 180; i++) {
        servo.write(i);
        delay(14);
      }
      for (int i = 180; i >= 0; i--) {
        servo.write(i);
        delay(14);
      }
      digitalWrite(redPin, LOW);
      // LED blue for 2 seconds
      digitalWrite(bluePin, HIGH);
      delay(2000);
      digitalWrite(bluePin, LOW);
      // Turn on green LED
      digitalWrite(greenPin, HIGH);
    }
  }
}

Credits

zirjagor

zirjagor

0 projects • 1 follower

Comments