The Nightstand Touch Lamp is an innovative and user-friendly bedside lamp designed to replace traditional switches with a touch-sensitive base or body, allowing for seamless control through simple touch interactions. This modern lamp enables users to effortlessly turn the lamp on or off, as well as adjust its brightness levels, all with just a gentle touch, eliminating the hassle of fumbling for physical switches in the dark. At the heart of this project lies a capacitive touch sensor, which detects touch inputs and sends corresponding signals to an Arduino microcontroller, serving as the brain of the system. The Arduino processes these signals and controls a dimmable LED, adjusting its brightness or toggling its state based on the user's touch. By combining these components, the Nightstand Touch Lamp offers a sleek, functional, and intuitive lighting solution that enhances convenience and modernizes the traditional bedside lamp experience.
Components Required
- Arduino Uno
- RFID Reader (RC522)
- RFID Tags/Cards
- 16x2 LCD with I2C Module
- Buzzer
- LED (Green/Red)
- Jumper Wires
- Breadboard
- Power Supply
Circuit Diagram
- Connect the RFID Module (RC522) to Arduino:
- VCC → 3.3V on Arduino
- GND → GND on Arduino
- SDA → D10 on Arduino
- SCK → D13 on Arduino
- MOSI → D11 on Arduino
- MISO → D12 on Arduino
- RST → D9 on Arduino
- Connect the Buzzer and LED Indicators:
- Buzzer (+) → D6 on Arduino
- Buzzer (-) → GND
- Green LED (+) → D7 on Arduino (Attendance success)
- Red LED (+) → D8 on Arduino (Unauthorized access)
- LED (-) → GND
- Connect the LCD (Optional, for Displaying Attendance):
- VCC → 5V on Arduino
- GND → GND on Arduino
- SDA → A4 on Arduino
- SCL → A5 on Arduino
- Power the System:
- ∙ USB Power Bank or 9V Battery to VIN
- Make sure to install the MFRC522 library before uploading the code.
- Library Installation Steps:
- Open Arduino IDE.
- Go to Sketch → Include Library → Manage Libraries.
- Search for MFRC522 and install it.
- Upload the code to Arduino board
CODE
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9
#define SS_PIN 10
#define BUZZER 6
#define GREEN_LED 7
#define RED_LED 8
MFRC522 rfid(SS_PIN, RST_PIN);
MFRC522::Uid uid;
void setup() {
Serial.begin(9600);
SPI.begin();
rfid.PCD_Init();
pinMode(BUZZER, OUTPUT);
pinMode(GREEN_LED, OUTPUT);
pinMode(RED_LED, OUTPUT);
}
void loop() {
if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) return;
Serial.print("RFID Tag UID: ");
String cardID = "";
for (byte i = 0; i < rfid.uid.size; i++) {
cardID += String(rfid.uid.uidByte[i], HEX);
}
Serial.println(cardID);
if (cardID == "a1b2c3d4") { // Replace with your RFID tag UID
digitalWrite(GREEN_LED, HIGH);
digitalWrite(RED_LED, LOW);
digitalWrite(BUZZER, HIGH);
delay(500);
digitalWrite(BUZZER, LOW);
Serial.println("Access Granted!");
}
else {
digitalWrite(GREEN_LED, LOW);
digitalWrite(RED_LED, HIGH);
digitalWrite(BUZZER, HIGH);
delay(500);
digitalWrite(BUZZER, LOW);
Serial.println("Access Denied!");
}
delay(1000);
rfid.PICC_HaltA();
}
CODE EXPLANATION
- Libraries and Pin Definitions
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9
#define SS_PIN 10
#define BUZZER 6
#define GREEN_LED 7
#define RED_LED 8
- SPI.h: Enables communication with the RFID module via the SPI protocol.
- MFRC522.h: Provides functions to interact with the MFRC522 RFID module.
- RST_PIN: Pin connected to the reset pin of the RFID module.
- SS_PIN: Pin connected to the slave select pin of the RFID module.
- BUZZER: Pin connected to a buzzer for audible feedback.
- GREEN_LED: Pin connected to a green LED (indicates access granted).
- RED_LED: Pin connected to a red LED (indicates access denied).
2. Object Initialization
MFRC522 rfid(SS_PIN, RST_PIN);
- rfid: An object of the MFRC522 class to interact with the RFID module.
3. Setup Function
void setup() {
Serial.begin(9600);
SPI.begin();
rfid.PCD_Init();
pinMode(BUZZER, OUTPUT);
pinMode(GREEN_LED, OUTPUT);
pinMode(RED_LED, OUTPUT);
}
- Serial.begin(9600): Initializes serial communication for debugging.
- SPI.begin(): Initializes the SPI bus for communication with the RFID module.
- rfid.PCD_Init(): Initializes the RFID module.
- pinMode(): Configures the buzzer and LED pins as outputs.
4. Loop Function
void loop() {
if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) return;
- rfid.PICC_IsNewCardPresent(): Checks if a new RFID card is present.
- rfid.PICC_ReadCardSerial(): Reads the card’s UID if it is present.
- If no card is detected or the UID cannot be read, the function exits.
5. Reading and Printing the UID
Serial.print("RFID Tag UID: ");
String cardID = "";
for (byte i = 0; i < rfid.uid.size; i++) {
cardID += String(rfid.uid.uidByte[i], HEX);
}
Serial.println(cardID);
- cardID: Stores the UID of the RFID tag as a hexadecimal string.
- The for loop iterates through each byte of the UID, converts it to a hex string, and appends it to cardID.
- The UID is printed to the Serial Monitor for debugging.
6. Access Control Logic
if (cardID == "a1b2c3d4") { // Replace with your RFID tag UID
digitalWrite(GREEN_LED, HIGH);
digitalWrite(RED_LED, LOW);
digitalWrite(BUZZER, HIGH);
delay(500);
digitalWrite(BUZZER, LOW);
Serial.println("Access Granted!");
} else {
digitalWrite(GREEN_LED, LOW);
digitalWrite(RED_LED, HIGH);
digitalWrite(BUZZER, HIGH);
delay(500);
digitalWrite(BUZZER, LOW);
Serial.println("Access Denied!");
}
- Access Granted:
- If the cardID matches the predefined UID ("a1b2c3d4"), the green LED turns on, the red LED turns off, and the buzzer beeps for 500ms.
- A message ("Access Granted!") is printed to the Serial Monitor.
- Access Denied:
- If the cardID does not match, the red LED turns on, the green LED turns off, and the buzzer beeps for 500ms.
- A message ("Access Denied!") is printed to the Serial Monitor.
7. Delay and Halt
delay(1000);
rfid.PICC_HaltA();
}
- delay(1000): Adds a 1-second delay before the next read to prevent rapid repeated readings.
- rfid.PICC_HaltA(): Puts the RFID module into a low-power state after reading.
8. Key Features
- RFID Tag Detection: Reads and processes the UID of an RFID tag.
- Access Control: Grants or denies access based on the UID.
- Visual and Audible Feedback: Uses LEDs and a buzzer to indicate access status.
- Serial Debugging: Prints the UID and access status to the Serial Monitor.
Example Workflow
- Initial State:
- No card is detected; the system waits for an RFID tag.
- Card Detected:
- The RFID module reads the card’s UID and prints it to the Serial Monitor.
- Access Granted:
- If the UID matches, the green LED lights up, and the buzzer beeps once.
- Access Denied:
- If the UID does not match, the red LED lights up, and the buzzer beeps once.
- Reset:
- The system waits for 1 second before detecting the next card.
- The ultrasonic sensor sends out a sound wave and measures how long it takes to bounce back.
- The Arduino calculates the distance to the object (your hand).
- If your hand is within 15 cm, the servo motor opens the lid for 3 seconds and then closes it.
- The process repeats continuously, making the garbage can "smart" and hands-free.
OBSERVING FUNCTIONALITY
- Scan an RFID card.
- If recognised, the green LED lights up and the buzzer beeps once.
- If unrecognised, the red LED lights up and the buzzer beeps twice.
- The Serial Monitor displays attendance records.
COMMON PROBLEMS AND SOLUTIONS
- RFID Not Detecting Cards?
- Ensure the RFID module is connected properly.
- Use 3.3V for the RFID module (NOT 5V).
- UID Not Matching?
- Read and store valid UID values from the Serial Monitor.
- Buzzer or LED not responding?
- Verify connections and correct pin assignments.
Conclusion
The RFID-Based Attendance System provides a fast, contactless, and reliable way to track attendance using RFID cards and an Arduino. By scanning an RFID tag, the system verifies identity and logs attendance, making it ideal for schools, offices, and secured areas. The project can be expanded by storing attendance records in a database, integrating Wi-Fi for real-time monitoring, or adding an LCD for instant feedback.
Comments