Step-by-Step Instructions for Wokwi Simulator
Step 1: Set Up Your Wokwi Project
- Go to https://wokwi.com
- Click "New Project"
- Select "Arduino Uno"
Step 2: Add Components
Click the "+" button to add these components:
- 1x Arduino Uno (already added)
- 1x MFRC522 RFID Module
- 1x Green LED
- 1x Red LED
- 2x 220Ω Resistors (for LEDs)
- Breadboard (optional, for cleaner layout)
Step 3: Wire the MFRC522 Module to Arduino
Connect the MFRC522 pins as follows:
Diagram.json:
{
"version": 1,
"author": "Anonymous maker",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-breadboard-mini", "id": "bb1", "top": 142.6, "left": 7.2, "attrs": {} },
{ "type": "wokwi-arduino-uno", "id": "uno", "top": -18.6, "left": 181.8, "attrs": {} },
{ "type": "wokwi-led", "id": "led1", "top": 73.2, "left": -34.6, "attrs": { "color": "red" } },
{
"type": "wokwi-led",
"id": "led2",
"top": -3.6,
"left": -34.6,
"attrs": { "color": "green" }
},
{ "type": "wokwi-servo", "id": "servo1", "top": 170.8, "left": 268.8, "attrs": {} },
{ "type": "board-mfrc522", "id": "rfid1", "top": 150.95, "left": -73.36, "attrs": {} },
{
"type": "wokwi-resistor",
"id": "r1",
"top": 23.15,
"left": 28.8,
"attrs": { "value": "270" }
},
{
"type": "wokwi-resistor",
"id": "r2",
"top": 80.75,
"left": 19.2,
"attrs": { "value": "270" }
}
],
"connections": [
[ "led2:C", "uno:GND.1", "green", [ "v0" ] ],
[ "led1:C", "uno:GND.1", "green", [ "v0" ] ],
[ "servo1:GND", "uno:GND.1", "black", [ "h0" ] ],
[ "servo1:V+", "uno:5V", "green", [ "h0" ] ],
[ "servo1:PWM", "uno:6", "green", [ "h0" ] ],
[ "rfid1:3.3V", "uno:3.3V", "green", [ "h0" ] ],
[ "rfid1:GND", "uno:GND.1", "black", [ "h0" ] ],
[ "rfid1:SDA", "uno:10", "green", [ "h0" ] ],
[ "rfid1:SCK", "uno:13", "green", [ "h0" ] ],
[ "rfid1:MOSI", "uno:11", "green", [ "h0" ] ],
[ "rfid1:MISO", "uno:12", "green", [ "h0" ] ],
[ "rfid1:RST", "uno:9", "green", [ "h0" ] ],
[ "r2:1", "led1:A", "green", [ "v0" ] ],
[ "r1:1", "led2:A", "green", [ "v0" ] ],
[ "r2:2", "uno:5", "green", [ "v0" ] ],
[ "r1:2", "uno:4", "green", [ "v0" ] ]
],
"dependencies": {}
}
| MFRC522 Pin | Arduino Pin |
|---|---|
| SDA (SS) | Pin 10 |
| SCK | Pin 13 |
| MOSI | Pin 11 |
| MISO | Pin 12 |
| IRQ | Not connected |
| GND | GND |
| RST | Pin 9 |
| 3.3V | 3.3V |
Step 4: Wire the LEDs
Green LED (Access Granted):
- Anode (long leg) → 220Ω resistor → Arduino Pin 2
- Cathode (short leg) → GND
Red LED (Access Denied):
- Anode (long leg) → 220Ω resistor → Arduino Pin 3
- Cathode (short leg) → GND
Code:
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#define SS_PIN 10
#define RST_PIN 9
#define GREEN_LED 4
#define RED_LED 5
#define SERVO_PIN 6
MFRC522 mfrc522(SS_PIN, RST_PIN);
Servo gateServo;
// CHANGE THIS TO YOUR CARD UID
byte authorizedUID[] = {0x11, 0x22, 0x33, 0x44};
void setup() {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
pinMode(GREEN_LED, OUTPUT);
pinMode(RED_LED, OUTPUT);
gateServo.attach(SERVO_PIN);
gateServo.write(0); // Gate closed
Serial.println("RFID Gate System Ready");
}
void loop() {
if (!mfrc522.PICC_IsNewCardPresent()) return;
if (!mfrc522.PICC_ReadCardSerial()) return;
Serial.print("UID: ");
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i], HEX);
Serial.print(" ");
}
Serial.println();
if (isAuthorized()) {
accessGranted();
} else {
accessDenied();
}
mfrc522.PICC_HaltA();
}
bool isAuthorized() {
if (mfrc522.uid.size != 4) return false;
for (byte i = 0; i < 4; i++) {
if (mfrc522.uid.uidByte[i] != authorizedUID[i]) {
return false;
}
}
return true;
}
void accessGranted() {
Serial.println("Access Granted");
digitalWrite(GREEN_LED, HIGH);
digitalWrite(RED_LED, LOW);
gateServo.write(90); // Open gate
delay(3000);
gateServo.write(0); // Close gate
delay(500);
digitalWrite(GREEN_LED, LOW);
}
void accessDenied() {
Serial.println("Access Denied");
digitalWrite(RED_LED, HIGH);
delay(2000);
digitalWrite(RED_LED, LOW);
}
Step 6: Configure Libraries
- Click on "Library Manager" (book icon)
- Add MFRC522 library by GithubCommunity
Step 7: Run the Simulation
- Click the Green "Start Simulation" button
- Open the Serial Monitor to see output
- Click on the RFID reader to simulate scanning a card
- In Wokwi, you can edit the card UID in the RFID component properties
Step 8: Test Different Cards
- Click on the MFRC522 module in the simulation
- You'll see RFID card properties on the right
- Change the UID values to test authorized/unauthorized access
- Authorized card: Set UID to
11 22 33 44 - Unauthorized card: Use any other UID like
01 02 03 04
Expected Behavior:
- When authorized card is scanned: Green LED turns on, Serial Monitor shows "Access Granted"
- When unauthorized card is scanned: Red LED turns on, Serial Monitor shows "Access Denied"
- LEDs turn off after 2 seconds
Troubleshooting Tips:
- If RFID module isn't detected, check the SPI connections (pins 10, 11, 12, 13)
- Make sure the MFRC522 is powered from 3.3V (NOT 5V)
- Verify RST pin is connected to pin 9
- Check that the MFRC522 library is properly installed
Comments
Post a Comment