Build an Auto Book Finder Robot! 📚
Press a book number on a touchscreen. Watch the whole bookshelf glide sideways. Then — pop! — the correct book slides right out. This DIY robotics project uses a Raspberry Pi touchscreen, an Arduino, a stepper motor, and a servo to build your very own mini automatic library.
Imagine tapping the number "5" on a screen — and instead of you searching the shelf, the whole shelf slides over to you, lines up book #5 with a little door, and pops it right out. That's exactly what we're building in this DIY robotics project. It combines a Raspberry Pi touchscreen for the "brain and face" of the robot with an Arduino for the "muscles" — a stepper motor that slides the shelf, and a servo that pops the book free.
📖 Our Build Plan
Full Parts List (Shopping List)
| Part | Qty | Used For |
|---|---|---|
| Raspberry Pi (3B+ or 4) | 1 | Runs the touchscreen app — the "face" of the robot |
| HDMI touchscreen display (5"–7") | 1 | Lets you tap a book number |
| Arduino Uno | 1 | Controls the motors — the "muscles" |
| NEMA 17 stepper motor | 1 | Slides the whole shelf sideways |
| A4988 (or DRV8825) stepper driver | 1 | Powers and controls the stepper motor |
| GT2 belt + pulleys, or threaded rod | 1 set | Turns motor spin into shelf sliding motion |
| Linear rail or drawer slides | 1 set | Lets the shelf glide smoothly |
| Micro limit switch | 1 | Tells the shelf where "position zero" is |
| SG90 or MG995 servo motor | 1 | Pushes the chosen book out through the window |
| 12V power supply | 1 | Powers the stepper motor driver |
| USB cable (Pi to Arduino) | 1 | Sends commands and can power the Arduino too |
| Cardboard, wood, or 3D-printed shelf frame | 1 | The bookshelf body itself |
The Two Brains: Raspberry Pi + Arduino
This project actually uses two computers working as a team, and that's a really useful robotics idea to learn:
- 🖥️ Raspberry Pi — draws the touchscreen buttons and handles what you tap. It's great at graphics and screens, but not great at precisely timing motors.
- ⚙️ Arduino — is excellent at precisely timing motor steps and reading sensors, but has no screen. It waits for a simple message like
GOTO:5from the Pi, moves the shelf, pops the book, then repliesDONE.
🪑 Build the Sliding Shelf
How it works: The entire shelf (with every book slot) sits on a carriage attached to a drawer slide or linear rail. A belt connects the carriage to the stepper motor, so when the motor turns, the whole shelf slides — not just one book. A fixed "window" cut into the front housing stays in one place; whichever book slot lines up with the window is the one that can pop out.
- Attach your drawer slide (or linear rail) horizontally inside a sturdy frame.
- Build a shelf insert with evenly spaced slots (e.g. 4cm apart) — number them left to right starting at 0.
- Mount the shelf insert onto the sliding carriage.
- Cut a small rectangular "window" opening in the front panel, just big enough for one book to pop through.
- Attach one end of a GT2 belt loop to the carriage, running it around a pulley on the stepper motor shaft and an idler pulley at the far end.
🎯 Homing Switch (Position Zero)
How it works: A small limit switch is placed at one end of the rail. Every time the robot starts up, it slowly slides the shelf toward the switch until it gets pressed — that's "home," or slot 0. From there, the Arduino always knows how many steps to move to reach any other slot.
- Mount the limit switch at the far-left end of the rail, so the carriage presses it when fully retracted.
- Wire one leg to GND, the other to Arduino digital pin 6.
- We'll use
INPUT_PULLUPin code, so no extra resistor is needed.
⚙️ Stepper Motor — The Shelf Mover
How it works: The Arduino sends fast electrical pulses to the stepper driver, and each pulse turns the motor shaft by one tiny "step." By counting pulses, the Arduino always knows exactly how far the shelf has moved — no guessing needed!
- Connect the stepper motor's 4 coil wires to the A4988 driver's motor output pins (1A, 1B, 2A, 2B).
- Wire driver STEP to Arduino pin 3, DIR to pin 4, and ENABLE to pin 5.
- Connect the 12V power supply to the driver's VMOT and GND — never power the motor directly from the Arduino!
- Add a small capacitor (100µF) across VMOT and GND close to the driver, to protect it from voltage spikes.
👉 Servo Pusher — The "Pop-Out"
How it works: The pusher servo sits fixed right behind the window (it does not move with the shelf). Once the shelf stops with the correct book lined up, the servo arm swings forward, taps the spine of the book, and springs back to rest.
- Mount the servo just behind the window opening, with its arm resting flat (not blocking the slot).
- Connect the signal wire to Arduino pin 9, power to 5V, ground to GND.
- If using a heavier MG995 servo, power it from a separate 5V source sharing a common ground with the Arduino.
🖐️ Touchscreen Book Selector
How it works: A simple Python app runs full-screen on the Raspberry Pi, showing one big button per book. When tapped, it sends a short text message to the Arduino over USB and shows a "Finding book..." status until the Arduino replies that it's done.
- Install Python and the
pyseriallibrary on the Raspberry Pi. - Write a small Tkinter app with one button for each book number.
- When a button is tapped, send
GOTO:<number>\nto the Arduino over serial. - Show "Finding book..." until the Arduino replies
DONE, then celebrate!
# touchscreen_app.py — runs on the Raspberry Pi
import tkinter as tk
import serial
import time
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=5)
time.sleep(2) # give Arduino time to reboot after connecting
def find_book(book_number):
status_label.config(text=f"Finding book {book_number}...")
root.update()
ser.write(f"GOTO:{book_number}\n".encode())
while True:
line = ser.readline().decode().strip()
if line == "DONE":
status_label.config(text=f"Here is book {book_number}! 📖")
break
root = tk.Tk()
root.title("Auto Book Finder")
root.attributes('-fullscreen', True)
root.configure(bg="#FBF3E7")
status_label = tk.Label(root, text="Tap a book number!",
font=("Fredoka", 28), bg="#FBF3E7")
status_label.pack(pady=30)
frame = tk.Frame(root, bg="#FBF3E7")
frame.pack()
colors = ["#7B2D3B", "#C9A227", "#4C7A5D"]
for i in range(1, 11):
btn = tk.Button(frame, text=str(i), font=("Fredoka", 22),
width=4, height=2, bg=colors[i % 3], fg="white",
command=lambda n=i: find_book(n))
btn.grid(row=(i - 1) // 5, column=(i - 1) % 5, padx=10, pady=10)
root.mainloop()
🔌 Connecting Pi ↔ Arduino
How it works: A single USB cable does double duty — it powers the Arduino and carries the serial messages back and forth, just like a two-way text chat between the two boards.
- Plug the Arduino into the Raspberry Pi with a standard USB cable.
- Find the Arduino's port name (usually
/dev/ttyACM0) using the Arduino IDE or terminal. - Make sure both the Arduino sketch and Python app use the same baud rate —
9600in our code.
GOTO:5 is called a "serial protocol" — a simple shared language two devices agree to speak so they always understand each other.🧩 See the Full Combined Code (Arduino + Python)
Once each part works on its own, put it all together like this.
Arduino sketch (shelf_control.ino)
// ===== AUTO BOOK FINDER — Arduino side =====
#include <AccelStepper.h>
#include <Servo.h>
#define STEP_PIN 3
#define DIR_PIN 4
#define ENABLE_PIN 5
#define LIMIT_PIN 6
#define SERVO_PIN 9
AccelStepper shelf(AccelStepper::DRIVER, STEP_PIN, DIR_PIN);
Servo pusher;
const long stepsPerSlot = 800; // tune this to your belt/pulley setup
const int restAngle = 0;
const int pushAngle = 90;
void homeShelf() {
shelf.setSpeed(-300);
while (digitalRead(LIMIT_PIN) == HIGH) {
shelf.runSpeed();
}
shelf.setCurrentPosition(0);
}
void popBook() {
pusher.write(pushAngle);
delay(500);
pusher.write(restAngle);
delay(300);
}
void setup() {
Serial.begin(9600);
pinMode(LIMIT_PIN, INPUT_PULLUP);
pinMode(ENABLE_PIN, OUTPUT);
digitalWrite(ENABLE_PIN, LOW); // enable the driver
shelf.setMaxSpeed(1000);
shelf.setAcceleration(500);
pusher.attach(SERVO_PIN);
pusher.write(restAngle);
homeShelf();
}
void loop() {
if (Serial.available()) {
String cmd = Serial.readStringUntil('\n');
if (cmd.startsWith("GOTO:")) {
int bookNumber = cmd.substring(5).toInt();
long target = bookNumber * stepsPerSlot;
shelf.moveTo(target);
while (shelf.distanceToGo() != 0) {
shelf.run();
}
popBook();
Serial.println("DONE");
}
}
}
Python touchscreen app (touchscreen_app.py)
# ===== AUTO BOOK FINDER — Raspberry Pi side =====
import tkinter as tk
import serial
import time
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=5)
time.sleep(2)
def find_book(book_number):
status_label.config(text=f"Finding book {book_number}...")
root.update()
ser.write(f"GOTO:{book_number}\n".encode())
while True:
line = ser.readline().decode().strip()
if line == "DONE":
status_label.config(text=f"Here is book {book_number}! 📖")
break
root = tk.Tk()
root.title("Auto Book Finder")
root.attributes('-fullscreen', True)
root.configure(bg="#FBF3E7")
status_label = tk.Label(root, text="Tap a book number!",
font=("Fredoka", 28), bg="#FBF3E7")
status_label.pack(pady=30)
frame = tk.Frame(root, bg="#FBF3E7")
frame.pack()
colors = ["#7B2D3B", "#C9A227", "#4C7A5D"]
for i in range(1, 11):
btn = tk.Button(frame, text=str(i), font=("Fredoka", 22),
width=4, height=2, bg=colors[i % 3], fg="white",
command=lambda n=i: find_book(n))
btn.grid(row=(i - 1) // 5, column=(i - 1) % 5, padx=10, pady=10)
root.mainloop()
Testing Checklist
- ☐ On power-up, the shelf slides to the limit switch and stops (homing works)
- ☐ Tapping a number on the touchscreen shows "Finding book..." right away
- ☐ The shelf slides the correct distance and stops precisely at the right slot
- ☐ The servo pusher pops the book through the window and returns to rest
- ☐ The screen updates to "Here is book X!" once the Arduino replies DONE
- ☐ Pressing different numbers in a row each works correctly, one after another
Frequently Asked Questions
Do I really need both a Raspberry Pi and an Arduino?
Not strictly — you could run everything on a Raspberry Pi alone with GPIO libraries. But splitting the job (Pi for the screen, Arduino for exact motor timing) makes the project more reliable and is a great way to learn how real robots divide up their work.
Can I use a smaller display instead of a full touchscreen?
Yes — even a small OLED display with a few push buttons can work instead of a touchscreen. You'd swap the Tkinter app for simple button-reading code, but the Arduino side stays exactly the same.
How do I figure out the right "steps per slot" number?
Start by measuring your belt/pulley size to estimate steps per centimeter, then fine-tune by testing: send a small move command, measure how far the shelf actually moved, and adjust the number until it lines up exactly with one book slot.
What if the book doesn't fully pop out?
Try increasing the servo's push angle slightly, or check that the book slot is smooth enough for the book to slide without catching on the frame.
Is this project good for a school science fair?
Yes — it's a favorite for robotics fairs because it's visual, interactive, and demonstrates several real engineering ideas at once: motor control, sensors, and two devices communicating together.

Comments
Post a Comment