AlphaBot: Autonomous Lane Guidance with ArduCam

| Autor: | Bertrand Mungu Cho |
| Art: | Project Work |
| Starttermin: | 05.10.26 |
| Abgabetermin: | 20.01.27 |
| Betreuer: | Prof. Dr.-Ing. Schneider |
| Sprache: | 🇩🇪 🇬🇧 |
Introduction
The AlphaBot is a small, programmable mobile robot used for educational projects in robotics, embedded systems and autonomous navigation. It moves using two independently driven wheels and changes direction by varying their relative speeds. This differential-drive arrangement provides a practical platform for investigating how sensor measurements can be used to control a robot's movement.
This project develops camera-based autonomous lane guidance for the AlphaBot using an ArduCAM Mini 2MP Plus camera. The objective is to enable the robot to observe a marked lane, estimate its position and heading relative to that lane, and adjust its motion to follow the intended path. The project brings together mechanical design, image acquisition, image processing and feedback control.
The work includes designing and 3D printing a camera mount, commissioning the camera with an Arduino, and transferring captured images to a PC running MATLAB. Image processing is used to identify the lane and estimate the lateral and heading errors. These estimates provide the input to the lane guidance controller, while gyroscope measurements are intended to provide feedback on the robot's turning rate. The resulting left and right motor commands are sent to the Arduino, which controls the motors through the motor driver.
Development proceeds from individual component tests to integration and evaluation of the complete system. MATLAB/Simulink supports algorithm and controller development, while practical experiments assess image-transfer reliability, processing time and lane-following performance. This article documents the design decisions, implementation steps and experimental results.
| Table 1: Funktional Requirements | |||||||||||||||||||||||||||||||||||||||||||||
|
| Table 2: Non-Funktional Requirements | ||||||||||||||||||||||||||||||
|
| Table 3: Constraints | ||||||||||||||||||||||||||||||
|
Tasks
- Familiarization with the topics Arduino, Arducam Mini 2MP
- CAD design and 3D printing of the camera mount
- Commissioning of the camera
- Image processing for lane detection
- Autonomous lane following (control)
- Model-based development with MATLAB®/Simulink
- Testing and scientific documentation
- Proof of functionality as a wiki article with animated GIF
Getting Started
- Transponder for the Student Lab from Mr. Ebmeyer
- Security Infomation for the Student Lab (from Mr. Ebmeyer)
- Wiki Access (from Mr. Schröder)
- Plan your task with working packages and dependencies as a gantt chart.
- Get started with programming the ArduCam with Arduino.
- Document your steps in this article: Arducam Mini 2MP
- Design mount for ArduCam. Reuse or optimise the existing design.
- Print the mount an attach it to the AlphaBot.
- Document the new mount in SVN and your Wiki Article.
- Research how to programm the ArduCam via MATLAB/Simlink.
System Design

The proposed system uses the ArduCAM to capture lane images and a gyroscope to measure the AlphaBot’s yaw rate. The Arduino Uno R4 WiFi transfers these data to a PC through a wireless router. MATLAB processes the images to estimate the robot’s position and heading relative to the lane. The guidance and yaw-rate controllers calculate left and right motor commands, which are sent back to the Arduino for execution. This process repeats continuously to maintain lane following.
Mechanical Design and Camera Mount
| Back view of the camera mount. | 8-pin connector for connecting the ArduCAM camera to the Arduino. |
The CAD designs for the camera mount and connector support are available in the SVN repository:
CAD designs – camera mount and connector support
- Strain relief: ???
Camera Commissioning
Camera commissioning was carried out to verify the connection between the ArduCAM Mini 2MP Plus B0067 and the Arduino UNO R4 WiFi, configure the camera library, and confirm successful image capture. Initial testing was performed over USB before integration with the AlphaBot.
Preconditions
- ArduCAM Mini 2MP Plus B0067
- Arduino UNO R4 WiFi
- Connection/Cable Plan? Image?
- Library Link?? Version?
- Source code? Link??
- USE SPI Connector
- Move with versioning to c-files.
Hardware Setup and Pin Assignment
The test setup consisted of the ArduCAM B0067 camera, an Arduino UNO R4 WiFi, a breadboard, jumper wires and a USB connection to a Windows PC. The camera uses I2C for sensor configuration and SPI for capture control and image readout.
The following pin assignment was used:
| ArduCAM pin | Arduino pin | Function |
|---|---|---|
| VCC | 5V | Camera power supply |
| GND | GND | Common ground |
| SDA | SDA | I2C data for sensor configuration |
| SCL | SCL | I2C clock |
| MOSI | D11 | SPI data from Arduino to camera |
| MISO | D12 | SPI data from camera to Arduino |
| SCK | D13 | SPI clock |
| CS | D7 | Camera chip select |
Wiring changes were made with USB power disconnected. Short jumper wires were used to reduce connection problems during SPI communication.
ArduCAM Library Configuration
The ArduCAM library was configured for the Mini 2MP Plus by enabling the following definition in its memorysaver.h file:
#define OV2640_MINI_2MP_PLUS
The other camera-platform selections in the same section were commented out. The additional sensor-selection section for ArduCAM Shield models was left unchanged.
Arduino UNO R4 Compatibility Adaptations
The installed library initially failed to compile because it did not define regtype and regsize for the UNO R4 architecture. A second error occurred because the example's variable name CS conflicted with a definition in the UNO R4 board package.
The sketch's chip-select variable was therefore renamed to CAMERA_CS, while retaining D7 as the physical connection:
const int CAMERA_CS = 7;
ArduCAM myCAM(OV2640, CAMERA_CS);
The corresponding setup instructions were updated:
pinMode(CAMERA_CS, OUTPUT);
digitalWrite(CAMERA_CS, HIGH);
The following architecture-specific definitions were added to ArduCAM.h, before the existing AVR definitions:
#if defined(ARDUINO_ARCH_RENESAS_UNO)
#define regtype volatile uint32_t
#define regsize uint32_t
#define cbi(reg, bitmask) digitalWrite(bitmask, LOW)
#define sbi(reg, bitmask) digitalWrite(bitmask, HIGH)
#endif
In the constructor in ArduCAM.cpp, defined(ARDUINO_ARCH_RENESAS_UNO) was added to the condition selecting the branch that assigns B_CS = CS;. This makes the library store the chip-select pin number and use digitalWrite() instead of direct port-register access.
A further correction was made in the example sketch's resolution-selection code. Under case 4, the camera-selection condition was changed to:
#if defined(OV2640_MINI_2MP_PLUS)
After these changes, the sketch compiled and uploaded successfully. The modified library files were retained with the project source code so that the tested setup could be reproduced.
Communication Test
After uploading the sketch, the Arduino Serial Monitor was opened with a baud-rate setting of 921600. The following startup messages were observed:
ACK CMD ArduCAM Start! END ACK CMD SPI interface OK.END ACK CMD OV2640 detected.END
The SPI test verified that the Arduino could write and read a test register on the camera module. The sensor-identification routine also reported detection of the OV2640. These checks were followed by image capture to verify the complete acquisition path.
Image Capture Test
The ArduCAM Host V2 Windows application was used to request and display images over the USB serial connection. Serial Monitor was closed before opening the host application to avoid simultaneous access to the same port.
The following settings were used:
| Parameter | Setting |
|---|---|
| Serial port | COM5 in the test setup |
| Baud-rate setting | 921600 |
| Camera sensor | OV2640 |
| Image resolution | 320 × 240 pixels |
| Capture mode | Single capture |
| Image format | JPEG; SetToBMP unchecked |
The COM port may differ on another computer and must be checked before connecting. The application sent the capture request, received the image data and displayed a photograph.

Commissioning Outcome
Successful image display confirmed that camera configuration, capture, buffer readout and USB transfer operated together with the modified UNO R4 library.
Occasional corrupted images and cases where capture completed without image display were also observed during testing. Therefore, successful initial capture was treated as a functional check rather than proof of continuous reliability. Repeated image acquisition was subsequently tested in MATLAB, as described in the following section.
Image Acquisition and Communication
Image Processing and Lane Detection
Control System

The control loop uses camera images to estimate the AlphaBot's position and heading relative to the lane. MATLAB calculates a desired turning rate and compares it with the yaw rate measured by the gyroscope. The resulting steering command is converted into left and right motor commands, which are sent to the Arduino.
1. Lane Position and Heading Errors
The lateral error describes the difference between the desired lateral position and the position estimated from the camera image . When the lane centre is the reference, . An error of zero means that the robot is at the desired lateral position.
The heading error describes the difference between the desired heading and the measured heading . Both headings must use the same reference frame. The wrapping operation expresses the difference between and radians, preventing an unnecessarily large correction when an angle crosses the boundary.
2. Lane Guidance
The lane guidance equation converts the lateral and heading errors into a desired yaw rate . Yaw rate describes how quickly the robot turns around its vertical axis. The gains and determine how strongly the robot responds to each error.
The lateral term guides the robot towards the desired lane position, while the heading term helps align it with the lane direction. With both errors equal to zero, this equation requests zero yaw rate.
3. Yaw-Rate Error
The yaw-rate error compares the desired turning rate with the actual turning rate measured by the gyroscope. The gyroscope reading is corrected for bias and filtered before being used as feedback.
4. Yaw-Rate PI Controller
The proportional-integral (PI) controller calculates the steering command . The proportional term, controlled by , responds to the current yaw-rate error. The integral term, controlled by , accumulates the error over time and helps reduce persistent differences between the desired and measured turning rates.
The steering command is a motor-control correction, rather than a physical steering angle, because the AlphaBot turns by driving its two wheels at different speeds.
5. Motor Mixing and Limits
The motor mixer combines the forward command with the steering correction to obtain the left motor command and right motor command .
When the steering correction is zero, both motors receive the same command. A non-zero correction increases one motor command and decreases the other, causing the robot to turn.
The limiting function keeps each command within the permitted motor-command range:
The command bounds depend on the chosen direction and PWM representation. The Arduino converts the received motor commands into direction signals and PWM outputs for the motor driver.
Closing the Feedback Loop
The motor commands change the AlphaBot's motion. The camera observes the resulting lane position and heading, while the gyroscope measures the resulting yaw rate. MATLAB uses these updated measurements to calculate the next correction.
All position, heading, yaw-rate and motor-direction signs must follow a consistent convention so that the controller reduces the errors. Lateral position may initially be expressed in image pixels; expressing it in metres requires a calibrated image-to-ground mapping. Heading is expressed in radians and yaw rate in radians per second.
Integration and Experimental Results
Conclusion and Future Work
Appendix
A Gantt Project Chart


The Gantt chart outlines the project activities, dependencies and milestones, from camera mount design and commissioning to lane detection, controller development and final testing. It is updated regularly to reflect progress and changes to the schedule.
B Requirements for student skills
The project requires prior knowledge in the following subject areas. If you do not meet these requirements, you must acquire the necessary knowledge independently during the course of the project using literature and online courses.
- CAD design with SolidWorks
- 3D printing
- Image processing
- Optional: Model-based development with MATLAB®/Simulink
- Document versioning with SVN
- Documentation using Word and the HSHL Wiki
C Requirements for the Scientific Work
- Scientific approach (project plan, etc.), useful article: Create a Gantt chart
- Weekly progress reports (informative); update the meeting minutes – live meeting with Prof. Schneider
- Project presentation in the Wiki
- Daily backup of work results in SVN
- Daily documentation of the hours worked
- Student Projects with Prof. Schneider
- Requirements for a Scientific Paper
- The Scientific Method and the Importance of Documenting Results
→ back to the main article: Student Work