If your bookshelf has reached that “is this chaos or a system?” stage, it’s time to get organized. With a Raspberry Pi, a camera, and a bit of Python, you can build your own barcode-powered library catalog — scan a book, auto-fetch its title and author, log it in a database, and manage everything from a clean web interface.

It’s perfect for book lovers, tool hoarders, collectors, and anyone who just really likes spreadsheets that fill themselves in.

What You’ll Need

Here’s the gear list:

  • Raspberry Pi 4 (2GB or more) — 4GB is plenty for this project
  • Raspberry Pi Camera Module 3 (or a USB webcam)
  • MicroSD card (32GB+) with Raspberry Pi OS (64-bit)
  • Official Raspberry Pi power supply
  • Push button + jumper wires + breadboard for a physical scan trigger
  • Small LED (optional) to confirm successful scans
  • Camera mount or stand so you can easily hold books up to it
  • Wi-Fi connection
  • (Optional) USB barcode scanner — faster and more reliable than camera-based scanning

Step 1: Set Up the Raspberry Pi

Flash Raspberry Pi OS (64-bit) with Raspberry Pi Imager, boot up, connect to Wi-Fi, and update:

bash
sudo apt update && sudo apt full-upgrade -y
sudo apt install python3-pip python3-opencv libzbar0 -y
pip3 install pyzbar flask requests picamera2

Enable the camera via sudo raspi-config → Interface Options → Camera, then reboot.

Step 2: Wire Up the Scan Button

Wiring is refreshingly simple:

  • Button pin 1 → GPIO 17
  • Button pin 2 → GND
  • (Optional LED) → GPIO 27 through a 220Ω resistor to GND

Pressing the button will tell the Pi to grab a frame and scan it for barcodes.

Step 3: Build the Barcode Scanner Script

Create a project folder ~/library/ and a file called scanner.py:

python
from picamera2 import Picamera2
from pyzbar.pyzbar import decode
from PIL import Image
import RPi.GPIO as GPIO
import time, requests, sqlite3

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)

cam = Picamera2()
cam.configure(cam.create_still_configuration())
cam.start()

db = sqlite3.connect("library.db", check_same_thread=False)
db.execute("CREATE TABLE IF NOT EXISTS items (isbn TEXT PRIMARY KEY, title TEXT, author TEXT, added TEXT)")

def scan_and_log():
    cam.capture_file("scan.jpg")
    img = Image.open("scan.jpg")
    codes = decode(img)
    if not codes:
        print("No barcode found")
        return
    isbn = codes[0].data.decode()
    print("Scanned:", isbn)
    r = requests.get(f"https://openlibrary.org/api/books?bibkeys=ISBN:{isbn}&format=json&jscmd=data").json()
    info = r.get(f"ISBN:{isbn}", {})
    title = info.get("title", "Unknown")
    author = ", ".join(a["name"] for a in info.get("authors", []))
    db.execute("INSERT OR REPLACE INTO items VALUES (?,?,?,?)",
               (isbn, title, author, time.strftime("%Y-%m-%d %H:%M")))
    db.commit()
    print(f"✅ Logged: {title} by {author}")

while True:
    if GPIO.input(17) == GPIO.LOW:
        scan_and_log()
        time.sleep(1)
    time.sleep(0.1)

This script uses the Open Library API to auto-fetch book metadata from the ISBN — no manual typing required. For tools or non-book items, you can skip the API call and just store a custom name.

Step 4: Build a Simple Web Interface

Create app.py with Flask so you can view, search, and manage your catalog from any device on your network:

python
from flask import Flask, render_template_string, request
import sqlite3

app = Flask(__name__)

TEMPLATE = """
<h1>📚 My Library</h1>
<form><input name="q" placeholder="Search..."><button>Go</button></form>
<table border=1 cellpadding=6>
<tr><th>ISBN</th><th>Title</th><th>Author</th><th>Added</th></tr>
{% for i in items %}<tr><td>{{i[0]}}</td><td>{{i[1]}}</td><td>{{i[2]}}</td><td>{{i[3]}}</td></tr>{% endfor %}
</table>
"""

@app.route("/")
def home():
    q = request.args.get("q", "")
    db = sqlite3.connect("library.db")
    rows = db.execute("SELECT * FROM items WHERE title LIKE ? OR author LIKE ?",
                      (f"%{q}%", f"%{q}%")).fetchall()
    return render_template_string(TEMPLATE, items=rows)

app.run(host="0.0.0.0", port=5000)

Run it with python3 app.py and visit http://<your-pi-ip>:5000 from your laptop or phone. Instant library catalog.

Step 5: Auto-Start Everything

Use systemd to run both the scanner and the web server on boot so your Pi becomes a dedicated catalog station:

bash
sudo nano /etc/systemd/system/library.service

Point it at your scripts, enable the service, and you’re done — power it on and start scanning.

Step 6: Expand the Catalog

Once the basics work, consider adding:

  • Categories and tags (fiction, reference, lent out, etc.)
  • Cover images via the Open Library cover API
  • CSV export for backups
  • “Check out / check in” fields if you lend items to friends
  • QR codes for non-ISBN items like tools, board games, or Lego kits

Tips for Smoother Scanning

  • Good lighting makes a huge difference — add a small LED lamp
  • Hold books 15–25cm from the camera for best focus
  • Use a USB barcode scanner if you plan to log hundreds of items — it’s dramatically faster
  • Back up library.db regularly (a weekly cron job to copy it works great)

Wrapping Up

You’ve just built your own private, ad-free, cloud-free library management system — one that grows with your collection and runs on a $50 computer. Whether it’s a wall of novels, a workshop full of tools, or a shelf of vinyl, your Pi now knows exactly what you own and where.

Organized chaos, finally solved. 📖✨


Loved this project? Follow @raspitips on Instagram for more Raspberry Pi builds, tips, and tutorials.

Leave A Comment

Related Posts