02/04/2015
Welcome to the 'Wheels & Wires' series, where we embark on an exciting journey documenting the process of constructing an Arduino-based self-driving car. This project serves as a deep dive into the fascinating realms of embedded programming and real-time systems, offering a hands-on learning experience as we build, troubleshoot, and discover. Throughout this series, we aim to provide a detailed guide, offering comprehensive insights, practical code examples, and effective solutions to the various challenges encountered along the way.

The primary objective of this ambitious project is to engineer a self-driving car utilising an Arduino as its central brain, complemented by an array of actuators, sensors, and a sophisticated path-finding algorithm. A crucial component will be a camera, tasked with precisely tracking the car's position relative to a designated goal and diligently detecting any obstacles that lie in its path. Leveraging the invaluable data streamed from the camera and other onboard sensors, the Arduino will wirelessly receive instructions, meticulously controlling the car's every movement to ensure smooth and autonomous operation.
In each instalment of this series, you can expect to gain profound insights into the hurdles we face, the innovative solutions we devise, and the tangible progress we achieve. From intricate coding challenges to seamless hardware integrations, we promise to cover every aspect, providing a transparent and educational account of this captivating endeavour.
Understanding the Core: How an Arduino Car Works
At its heart, an Arduino self-driving car functions by emulating the fundamental processes of human perception, decision-making, and action. The Arduino board acts as the central processing unit, continuously gathering data from its surroundings, processing that information, and then issuing commands to the car's various mechanical parts. It's a continuous feedback loop that allows the vehicle to navigate autonomously.
The Role of Sensors: The Car's Senses
Just as humans rely on their senses to perceive the world, an autonomous car depends heavily on its sensors. These devices are the car's 'eyes' and 'ears', providing critical data about its environment:
- Camera: The camera is perhaps one of the most vital sensors for this project. It provides visual data, enabling the car to 'see' its environment. This visual input is processed to determine the car's precise position relative to a pre-defined goal and to identify any obstacles – be they static objects or dynamic elements – in its path. Advanced image processing techniques, executed by the Arduino or an auxiliary processing unit, transform raw pixel data into actionable information for navigation.
- Other Onboard Sensors: While not explicitly detailed, typical self-driving car projects often incorporate other sensors to augment the camera's input. These might include:
- Ultrasonic Sensors: For precise short-range distance measurement, excellent for obstacle avoidance in close quarters.
- Infrared (IR) Sensors: Similar to ultrasonic, but using infrared light, often used for line following or close proximity detection.
- Inertial Measurement Units (IMUs): Comprising accelerometers and gyroscopes, IMUs provide data on the car's orientation, acceleration, and angular velocity, crucial for maintaining stability and tracking movement.
- Wheel Encoders: These sensors measure the rotation of the wheels, providing accurate data on distance travelled and speed, essential for precise locomotion control.
The Role of Actuators: The Car's Muscles
Once the Arduino has processed sensor data and made a decision, it needs to act. This is where actuators come into play. Actuators are the components that translate electrical signals from the Arduino into physical motion:
- DC Motors: These are the primary means of propulsion for the car. They are responsible for driving the wheels, allowing the car to move forwards, backwards, and turn. The speed and direction of these motors need to be precisely controlled by the Arduino.
- Motor Drivers: Directly connecting motors to an Arduino is rarely feasible, as motors often draw more current than the Arduino's pins can safely supply. This is where motor drivers become indispensable. They act as an interface, taking low-current control signals from the Arduino and using them to switch a higher-current power supply to the motors.
Choosing the Right Motor Driver: L298 vs. TB6612FNG
The choice of motor driver significantly impacts the performance and efficiency of your self-driving car. Two common options are the L298 and the TB6612 driver breakout board. Let's compare them:
| Feature | L298 Motor Driver | TB6612FNG Driver Breakout Board |
|---|---|---|
| Voltage Loss | Significant (approx. 2V) | Minimal (negligible) |
| Efficiency | Lower, due to voltage loss | Higher, more power delivered to motors |
| Cost | Generally lower | Slightly higher (around £3-£5) |
| Size | Often larger, requires heatsink | Compact, smaller footprint |
| Heat Dissipation | Can run hot, often needs heatsink | Runs cooler, less heat generated |
| Current Output | Higher peak current (e.g., 2A per channel) | Lower continuous current (e.g., 1.2A per channel) |
| Compatibility | Supported by common motor control libraries | Supported by common motor control libraries |
Given the low supply voltages (e.g., 6V or even 4.8V from NiMH batteries), the TB6612 driver breakout board is often the preferred choice due to its minimal voltage loss. A 2V loss from an L298 driver when starting with only 4.8V means very little power actually reaches the motors, leading to sluggish performance. The TB6612, with virtually no loss, ensures maximum power transfer and better motor performance, resulting in a more satisfying and responsive build.

The Power System: Fueling Your Autonomous Ride
Powering your Arduino and motors correctly is paramount. Misconfigurations can lead to unstable operation or even damage to components.
- Battery Selection: For a mobile robot, rechargeable batteries like NiMH (Nickel-Metal Hydride) AA batteries are common. A pack of four AA NiMH batteries typically provides 4.8V (1.2V per cell) which is suitable for many components.
- Powering the Arduino UNO: The Arduino UNO board is designed to operate optimally at 5V. Directly supplying 6V from four AA batteries to the UNO's power jack (VIN pin via the regulator) is generally safe, as the onboard regulator can handle it. However, if using a lower voltage like 4.8V, or if you want to maximise power efficiency, direct connection methods need careful consideration. The UNO's internal 5V regulator has a voltage drop of approximately 0.9V, meaning if you supply 4.8V, the Arduino might only receive around 3.9V, which could lead to instability or resets, especially when motors draw significant current.
- Powering Motors via Driver: The motor driver (e.g., TB6612) receives power directly from the battery pack. It then regulates and switches this power to the motors based on signals from the Arduino.
Bringing it Together: Wiring and Integration
Careful wiring is essential for the reliability and performance of your self-driving car. Here are some critical wiring considerations, especially for the TB6612 driver and power supply:
Connecting the TB6612 Motor Driver to Arduino UNO
To avoid common mistakes and optimise connections, consider these tips:
- Prepare Pin Headers: Before soldering, you can remove any unused pins from the TB6612's pin headers. This makes the board cleaner and reduces the chance of accidental short circuits.
- Direct Power Connection: To minimise additional power loss, solder the battery's positive (+) and negative (-) cables directly to the VM (Motor Voltage) and GND (Ground) terminals of the TB6612 driver breakout board. This bypasses any potential resistance from intermediate connections.
- Motor Wire Connections: You can solder the motor wires directly to the (A|B)O1 and (A|B)O2 terminals for each motor. While this reduces further voltage losses, it makes separating the motor from the driver difficult after soldering. For more flexibility, solder female pin headers to these terminals, allowing you to easily connect and disconnect motor wires.
- STBY Terminal: Do not forget to connect the STBY (Standby) terminal on the TB6612 driver breakout board to the VCC terminal (5V). This activates the driver. Since we typically don't require the standby functionality for a simple car and want to conserve Arduino output pins, connecting it to VCC is a straightforward solution.
- Optional Battery Voltage Readout: For monitoring your battery level, you can implement a simple voltage divider. Solder a 100 kOhm resistor between VIN (battery positive) and Arduino analog pin A2, and a 10 kOhm resistor between A2 and ground. The Arduino can then read the voltage at A2 and calculate the battery's voltage.
Powering the Arduino UNO
The Arduino UNO board generally prefers a regulated 5V supply. When using batteries, consider the following:
- Sensor Shield Power: If using a Sensor Shield, you might be tempted to use its GND and VCC terminals for power connection instead of the UNO's power jack. Be cautious: the 'V' pins of the digital output row on some Sensor Shields are always connected with VIN (the battery voltage) and not with the UNO's regulated 5V (VCC). While this can improve servo performance (as many servos prefer higher voltage), it can destroy any 5V logic circuits if they draw power from these 'V' pins. Therefore, using the GND and VCC terminals on the Sensor Shield for a 2-Li-ion supply (which can be 7.4V or higher) is NOT recommended; in such cases, you MUST use the UNO's power jack. Otherwise, it will likely destroy components like an SG90 servo, which is typically specified up to 6V.
- SEL Bridge on Arduino: The 'SEL' bridge on some Arduino boards (or Sensor Shields) connects the VCC terminal with the internal 5V rail of the Arduino. If you are supplying power directly to the Arduino's VIN pin from a battery pack (e.g., 4 AA batteries), you might consider removing this SEL bridge. Then, connect the external VCC terminal (from your power source) directly to the Arduino UNO's VIN pin. This ensures the Arduino is supplied directly, with the onboard regulator handling the necessary voltage drop (VIN - 0.9V), allowing it to run down to approximately 3.5V before issues arise.
- NiMH Battery Specifics: If you are using 4 NiMH rechargeable AA batteries, it is often better to keep the SEL bridge in place. This connects VIN directly to the Arduino's 5V rail, bypassing the 0.9V loss of the 5V regulator. This can prevent resets, especially when batteries are weak and the motors start drawing significant current, as it maximises the voltage reaching the Arduino.
The Control Loop: Making it Autonomous
With sensors providing data and actuators ready to execute commands, the final piece is the 'intelligence' – the path-finding algorithm. The Arduino continuously performs the following loop:
- Sense: Gather data from the camera (for position and obstacle detection) and other onboard sensors (e.g., distance, orientation).
- Process: The Arduino processes this raw data. This involves image processing for the camera, filtering sensor noise, and combining information from various sources to create a coherent understanding of the car's surroundings and its current state.
- Decide: Based on the processed data, the path-finding algorithm determines the next optimal action. This involves calculating the necessary adjustments to speed, direction, and trajectory to reach the goal while avoiding obstacles. Wireless instructions might update the goal or provide high-level commands.
- Act: The Arduino sends precise control signals (PWM signals for motor speed, direction signals) to the motor drivers, which then power the motors to execute the decided action.
This loop repeats continuously, allowing the car to adapt to changing environments and navigate towards its destination autonomously. The efficiency of this loop, from sensing to acting, determines the car's responsiveness and navigational accuracy.
Frequently Asked Questions (FAQs)
Why choose Arduino for a self-driving car project?
Arduino is an excellent platform for learning and prototyping. Its simplicity, extensive community support, readily available libraries, and low cost make it ideal for hobbyists and students venturing into robotics and embedded systems. While not as powerful as Raspberry Pi for complex AI tasks, it's perfect for controlling motors, reading sensors, and implementing basic control algorithms.
What is the main difference between the L298 and TB6612 motor drivers?
The primary difference lies in their efficiency and voltage drop. The L298 is an older driver that introduces a significant voltage loss (around 2V), meaning less power reaches your motors, especially with low voltage supplies. The TB6612 is a more modern, efficient driver with negligible voltage loss, ensuring almost all battery power is delivered to the motors, leading to better performance and less heat generation.

How do I power both the Arduino and the motors from the same battery pack?
You typically power the motor driver directly from the battery pack's main positive and negative terminals. The Arduino can then be powered either from the same battery pack (via its VIN pin and internal regulator) or, for better stability, from a separate voltage regulator that steps down the battery voltage to a steady 5V for the Arduino. Careful wiring and understanding voltage requirements are crucial to avoid damaging components.
Can I use any battery type for this project?
While various battery types can be used, their voltage and current capabilities must match your components. NiMH AA batteries are common for their reusability and appropriate voltage for many hobby projects. Lithium-ion (Li-ion) batteries offer higher energy density but require more careful charging and discharge management. Always check the voltage requirements of your Arduino, motor driver, and motors before selecting a battery.
What is the camera's role in a self-driving car project?
The camera acts as the car's primary visual sensor. It captures images of the environment, which are then processed to identify the car's position relative to a target, detect obstacles in its path, and potentially recognise lanes or other navigational cues. This visual data is crucial for implementing path-finding algorithms and ensuring safe navigation.
What's Next
Stay tuned for the next instalment of 'Wheels & Wires', where we'll delve into the foundational details of setting up the project environment. This will include preparing your workspace, installing necessary software, and getting started with the initial hardware integrations, laying the groundwork for your very own autonomous vehicle. We are incredibly excited about this project and can't wait to watch our car go zooooom!
If you want to read more articles similar to Arduino & Autonomous Cars: A DIY Guide, you can visit the Automotive category.
