# Learning Lab project kit

These source files support the AI + Arduino, AI + Raspberry Pi and robotics project articles. They are educational drafts, not a certified safety controller. Hardware has not been bench-tested during article preparation. Follow each article's parts, wiring and tests before energizing a circuit.

## Computer setup

Use Python 3 in an isolated environment. On macOS/Linux:

```bash
python3 -m venv .venv
source .venv/bin/activate
python -m pip install pyserial opencv-python scikit-learn vosk
```

On Windows, use `py -m venv .venv`, then `.venv\Scripts\Activate.ps1` in PowerShell. If local policy blocks activation, use `.venv\Scripts\python.exe -m pip ...` and that executable to run scripts; do not relax execution policy for this tutorial. Install only packages needed by the article. On Raspberry Pi OS use the distribution's OpenCV package (`sudo apt install python3-opencv python3-venv`) and `python3 -m venv --system-site-packages .venv`; then install pyserial and any article-specific package into the environment. Package wheel availability varies by Python/OS version; use a supported environment, never `sudo pip`.

Save `bridge.py` and `vision.py` alongside the article's Python script. `bridge` is our included module, not a package to find on PyPI. List serial devices with `python -m serial.tools.list_ports`. Replace example port names with the actual port. Close the IDE Serial Monitor before Python opens the port. Upload only the sketch for the specific project; firmware protocols and pins differ.

## LED bridge

Open `led_bridge/led_bridge.ino` with Arduino IDE. Select Arduino Uno and the actual board port, then upload. The board uses its built-in LED; no external LED is needed. USB powers the board. Optional sensor input pins: A0 light divider, A1 TMP36, D2 button to ground using INPUT_PULLUP. Leave unused sensor values unused; floating pins have no meaningful measurements.

At 115200 baud with newline endings: LED_ON lights the LED for up to 600ms; refresh to keep it lit. LED_OFF and STOP extinguish it. READ returns `DATA lightADC temperatureADC buttonState`. The board replies `OK command` for accepted output commands. A command acknowledgement confirms parsing, not the physical state of the LED. Unknown or oversized commands turn the light off.

For an LDR divider: 5V → LDR → A0 → 10kΩ → GND. For a TMP36 in TO-92 package, with flat face toward you and leads downward: left = +5V, middle = A1, right = GND; verify package drawing before power. Add 100nF between sensor supply and ground near the sensor. Temperature ≈ (ADC × measured supply voltage / 1023 − 0.5) × 100 °C. USB's nominal 5V is an approximation, not a calibration.

## Rover bridge reference wiring

Use Arduino Uno R3, Pololu TB6612FNG carrier #713, two Pololu 100:1 LP 6V micro metal gearmotors #992, wheels/chassis/caster, HC-SR04, momentary stop button, insulated leads, 4-AA alkaline switched enclosed motor supply, and suitable USB logic power. Do not substitute high-stall-current motors without redesigning the driver/power system. Do not stall the motors. All supplies off during wiring.

| Connection | Destination |
| --- | --- |
| Uno D5/D7/D8 | Driver PWMA/AIN1/AIN2 |
| Uno D6/D9/D10 | Driver PWMB/BIN1/BIN2 |
| Uno D4 | Driver STBY, with 10kΩ pull-down to GND |
| Uno 5V | Driver VCC and HC-SR04 VCC |
| Motor pack positive through physical switch | Driver VM only |
| Motor pack negative, Uno GND, driver GND, sensor GND | Shared ground |
| Driver AO1/AO2 | Left motor |
| Driver BO1/BO2 | Right motor |
| Uno A0/A1 | Sensor TRIG/ECHO |
| Uno D2 | Button; other contact to GND |

Never connect motor supply positive to Uno 5V or to a Raspberry Pi GPIO. The motor pack powers motors only. Uno uses USB power; a Pi uses its own manufacturer-specified supply. Use a secured regulated USB power bank rated for the Pi if untethered, not loose cells. Keep USB cables away from wheels. The HC-SR04 echo is suitable for this 5V Uno input, not a direct 3.3V Pi input.

Upload `rover_bridge/rover_bridge.ino`. Commands: FORWARD, LEFT, RIGHT, STOP, newline terminated at115200baud. Movement expires after250ms, distance under25cm or invalid echo stops it, and pressing D2 latches a software halt until board reset. The physical motor supply switch is the independent shutdown. Firmware uses low duty-cycle forward-only steering; turning does not protect the sides or detect stairs. Test in a small clear floor enclosure, never near people, pets, steps or traffic. No claim of measured stopping distance is made.

First test with wheels raised. Verify each motor's forward direction; power down and swap that motor's output leads if needed. Send FORWARD once and verify automatic stop. Block the front sensor and confirm no motion; unplug USB and confirm stop; press the halt button and confirm no restart. Measure stopping distance at low speed and enlarge the threshold if needed. Only then test on the floor with an adult supervising younger learners. Stop immediately if a driver or motor gets hot.

## Local vision

`vision.people(frame)` uses OpenCV's built-in trained HOG/SVM pedestrian detector. It is a single-class baseline, not an all-object model and not a dependable human-safety detector. Scores are margins, not calibrated probabilities. `vision.marker(frame)` uses a hand-written green-color rule; it is computer vision but not machine learning. Both expect BGR images from OpenCV. USB UVC cameras work through VideoCapture when supported by the OS. Pi ribbon cameras require Picamera2 rather than assuming camera index zero works.

## Validation record

The accompanying publication reports software checks separately. Local unit checks cannot establish camera accuracy, electrical compatibility of a substituted board, braking distance or physical safety. Record your OS, Python and package versions, board revision, wiring, input samples and observed outputs as you complete each article.
