Build it step by step
0 of 7 doneSet up the camera
Run a test picture with picamera2.
Make the codes
Create QR images for a few IDs.
Decode one code
Print the text to the screen.
Add the CSV log
Write the ID and time.
Add the repeat rule
Ignore repeats for 10 minutes.
Add the buzzer
Beep on a new scan.
Mount it
Fix the camera at the door at chest height.
How do you build a QR code attendance scanner?
Students show a QR code to a Pi camera, which logs their attendance with time in a CSV. You need Raspberry Pi 4 Model B (4 GB), SanDisk microSD card 32 GB (A1, Class 10), Raspberry Pi 27 W USB-C power supply, Raspberry Pi Camera Module 3 and Active buzzer 5 V. It takes 7 steps and about 90 minutes.
- Level
- Beginner
- Time
- About 90 min
- Parts
- 5
Wiring
| From | To | Why |
|---|---|---|
| Camera ribbon | Pi camera connector | Image input |
| Buzzer + | Pi pin 12 (GPIO18) | Beep on a scan |
| Buzzer − | Pi pin 14 (GND) | Ground |
| Pi USB-C | Raspberry Pi power supply | Power |
Code
Each student gets a printed QR code that contains only an ID code, not their name, so a lost code reveals nothing. The Pi decodes codes from the camera with OpenCV, beeps once on a new scan and writes the ID and time to a CSV file; the same code is ignored for 10 minutes so a student cannot be counted twice by holding it up. The attendance file holds personal data: store it only on the Pi's card or a school system, tell students what is recorded and why, and follow your institution's rules on student data. A QR code can be photographed and shared, so this suits low-stakes attendance, not security. Good light and holding the code about 15 to 25 cm from the camera give the best reading. Check the Pi's camera is enabled and the ribbon is fitted with the power off.
# QR attendance scanner. Run on the Pi. Install first:
# sudo apt install -y python3-picamera2 python3-opencv python3-gpiozero
# This version decodes QR codes with OpenCV's built-in detector.
import csv, time
from datetime import datetime
import cv2
from picamera2 import Picamera2
from gpiozero import Buzzer
buzzer = Buzzer(18)
cam = Picamera2()
cam.configure(cam.create_preview_configuration(main={"size": (640, 480), "format": "RGB888"}))
cam.start()
detector = cv2.QRCodeDetector()
last_seen = {} # student code -> time of the last scan
REPEAT_SECONDS = 600 # ignore the same code for 10 minutes
LOG = "attendance.csv"
def log(code):
with open(LOG, "a", newline="") as f:
csv.writer(f).writerow([code, datetime.now().strftime("%Y-%m-%d %H:%M:%S")])
while True:
frame = cam.capture_array()
text, points, _ = detector.detectAndDecode(frame)
if text:
now = time.time()
if text not in last_seen or now - last_seen[text] > REPEAT_SECONDS:
last_seen[text] = now
log(text)
buzzer.beep(0.1, 0.1, n=1)
print("Logged", text)
time.sleep(0.05)
# Make the QR codes with the qrcode package on any computer: pip install qrcode[pil]
# import qrcode
# qrcode.make("STUDENT-0001").save("student-0001.png")
# Use an ID code, not the student's name, so a lost printout reveals nothing.Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Show a code | A beep and one line in the CSV |
| Show it again | No new line for 10 minutes |
| Show a different code | New line |
| Dim room | Reads if the code is held steady |
If it does not work
Camera not found
Check the ribbon and that the camera is enabled.
Code not read
Improve the light and the print size.
No beep
Check the buzzer polarity and GPIO18.
Duplicates
Check the repeat time and that the text is identical.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the QR code attendance scanner?
Raspberry Pi 4 Model B (4 GB), SanDisk microSD card 32 GB (A1, Class 10), Raspberry Pi 27 W USB-C power supply, Raspberry Pi Camera Module 3 and Active buzzer 5 V.
How long does the QR code attendance scanner take to build?
About 90 minutes for a beginner maker, in 7 steps.
How do I know the QR code attendance scanner works?
Show a code: A beep and one line in the CSV. Show it again: No new line for 10 minutes. Show a different code: New line.
Camera not found: what should I check?
Check the ribbon and that the camera is enabled.
Code not read: what should I check?
Improve the light and the print size.
No beep: what should I check?
Check the buzzer polarity and GPIO18.
Duplicates: what should I check?
Check the repeat time and that the text is identical.
