Before you start
Read the PIR and detached-servo exercises. Identify your actual board, servo and supply models before building.
You will leave with
A power decision, a connection list and three separate tests instead of one hard-to-debug automatic mechanism.
The difficulty was not coming up with an idea. It was knowing exactly where the wires went, how to power it away from a USB connection, and how to understand the program.
Harry identified the pencil case as his Arduino/PIR/servo project. He needed a clearer wiring image, a power arrangement without a USB cable attached to the Arduino, and code that was easier to follow. Those are the reported learning obstacles behind this guide.
Development notebook: these notes do not claim a completed, load-tested or safe automatic pencil case. The local design calls for an UNO R3, HC-SR501-type module and MG996R-size positional servo; the actual unit and power hardware still need confirmation.
1. Split the project into observable jobs
A complete program can hide three unrelated faults: a sensor that holds HIGH longer than expected, a servo supply that drops under load, and a lid that binds. Give each job a test that does not depend on the other two.
| Stage | Connected hardware | Evidence to keep |
|---|---|---|
| Sense | UNO + PIR only | READY, ACTIVE and QUIET events in the serial log |
| Move manually | UNO + detached servo + separate supply | Repeatable midpoint and a small supported command range |
| Inspect the mechanism | Unpowered hatch and linkage | Free travel, secure joints, finger clearance and access to disconnect power |
Use the PIR indicator and servo exercise as separate sketches. Do not combine them simply because both upload successfully.
2. Choose what “without USB” means
There are two different requirements: no computer attached, or no USB plug in the Arduino at all. A USB power bank can meet the first but not the second. For this project's stated second requirement, the UNO R3 barrel jack is the simplest documented input to investigate.
| Option | What it solves | What remains to check |
|---|---|---|
| Ready-made regulated DC adapter into the UNO barrel jack | No computer or UNO USB cable during operation | It still has a power cable; servo uses a separate matched supply |
| Documented protected battery pack with a compatible barrel lead | Potentially portable UNO operation | Full-to-empty pack voltage, polarity, current, charging and protection; not a universal battery recommendation |
| USB power bank | No computer | USB remains connected; low-current auto-off and servo transients can matter |
Arduino recommends 7–12 V DC for this board's barrel input, using a 5.5 mm plug with 2.1 mm centre hole, centre-positive. Follow the official power-input guidance for your exact board. A 5 V servo supply is not a suitable substitute at that barrel input. A 9 V barrel supply must not be connected directly to a 5 V-class servo.

This UNO R3 SMD reference shows the square USB-B socket and the separate black barrel power jack. The socket choice changes how the board receives power; it does not turn the UNO into a servo power supply. This is SparkFun’s photograph, not Harry’s board.
Photo: SparkFun Electronics · CC BY 2.0. Unmodified. Image credits and scope.3. Keep the two power paths visible
For a first computer-free bench test, use a documented UNO barrel supply and a separate servo supply with both negative references joined. The PIR takes its small supply from the UNO's 5 V rail after compatibility is confirmed. The servo takes its motor current directly from the servo supply. Power off all sources before moving jumpers; disconnect the external supplies while changing the wiring for an upload.
A future single-pack version could use separate, correctly specified power-conversion paths. It requires a real current budget, connector ratings and protection decisions. A drawing of two boxes marked “battery” and “regulator” is not enough to select those parts. Keep the two-supply test as the documented learning setup until the exact portable hardware is known.
4. Decide which connections need soldering
Leaving USB power does not, by itself, require soldering. The UNO already has a barrel socket. A compatible prewired adapter, rated screw-terminal distribution and documented servo breakout can make a temporary bench arrangement without soldering. Choose connectors that match both wire size and current, and arrange strain relief so a tug cannot pull a live wire free.
For an enclosure, loose push-in jumpers are poor permanent wiring. Use suitable locking/crimped connectors or a properly assembled soldered harness. If soldering is new, practise on scrap wire first: make a sound mechanical arrangement, heat the joint rather than building a blob, insulate each conductor with heat-shrink and inspect for bridges before power. Use ventilation and a stable iron stand. Do not solder directly to rechargeable cells or construct a charging circuit as part of this beginner exercise. A ready-made protected pack with its specified charger is a separate selection task.
5. Read the program in three questions
- What did I observe? A digital PIR reading or an analog knob value.
- What should the output request be? An LED state or a bounded servo pulse.
- When may that change? After the settling phase or sampling interval.
Keep setup for one-time configuration and loop for those short repeated decisions. A command sent to a servo is not confirmation that the lid actually moved. Software timing is not a position sensor, and a delay does not make the travel safe.
6. Treat automatic closing as an unresolved design decision
A hand can remain still while a PIR output becomes LOW. Pencils can obstruct a lid without producing the kind of signal a PIR detects. Therefore this notebook does not provide code that closes a hatch automatically because the PIR goes quiet.
Before a powered lid is attached, establish load and travel limits, guarding or finger clearance, an accessible power disconnect and a deliberate control strategy. A manual command with a small, unloaded test is the next learning step. Any obstacle sensing or force limitation must be designed and verified for the mechanism; it is not supplied by these sketches.
7. Turn the next attempt into useful evidence
Download the pencil-case build record. Fill in the actual component labels, a photograph or drawing of every connection, the sketch filename, power measurements if available, and exactly what happened. Record a failure as a failure. For example, “the controller restarted on movement” is useful; “everything works” without the supply model or load is difficult to reproduce.
Send a correction or a project observation through Contact. This notebook will distinguish reported observations from newly proposed steps when updated.
Reference exercise · Read the evidence and checking record.