Assembling a robotic car begins with checking the voltage that supplies L298N on motors, since it is this parameter that determines the speed of rotation of the wheels and the correct operation of the entire system. If you are planning to make a machine using Arduino Uno, then immediately pay attention to the difference between the supply voltage of the microcontroller and the motors, since supplying 12 volts directly to the board will lead to instant failure of the controller. Correct distribution of currents is the foundation without which no circuit will work reliably.
The process of creating an autonomous vehicle requires careful attention to the selection of components and their compatibility. The project is based on a board Arduino Uno, which acts as a brain that processes signals from sensors and controls the motor driver. To implement the movement, two or four DC motors are required, which are mounted on a special chassis. The most important element is the driver, which allows you to control the direction and speed of rotation of the shafts, since the microcontroller ports cannot provide the necessary current.
Mechanical assembly often takes longer than programming, so it pays to prepare tools and hardware in advance. You will need a soldering iron to connect the pins if you are not using a ready-made breadboard, as well as a set of screwdrivers to secure the motors. Robot chassis can be made of acrylic, plastic, or even assembled from scrap materials, the main thing is to ensure even installation of the wheels. Incorrect alignment will result in the machine constantly moving to the side even with the same motor speed.
The electronic content of the project is based on the clear interaction of three main components: a controller, an energy source and actuators. The battery must have sufficient current output so that when the engines start, the voltage does not drop to a level that causes a reboot ATmega328P. Often, beginners use regular AA batteries, which are not capable of delivering the required current, causing the robot to twitch in place. The optimal solution would be lithium polymer batteries or a high-quality 7-9 volt power supply.
Necessary components for assembling a robotic car
Before starting installation work, it is necessary to prepare a complete set of equipment so that the process is not interrupted by searching for missing parts. The basic set includes the board itself Arduino Uno, which is a standard in the world of amateur electronics due to its accessibility and huge number of libraries. Without a reliable motor driver such as the popular module L298N or L293D, it is impossible to control the direction of rotation, since the microcontroller produces too weak a signal.
The choice of wheelbase depends on the desired cross-country ability and speed of the future device. For smooth surfaces, small-diameter plastic wheels are suitable, but for carpets or the street it is better to choose rubber analogues with tread. Motors must match the selected supply voltage, usually in the 3 to 6 volt range for smaller models. Critical check the driver package: on some cheap versions, the cooling radiators are soldered poorly, which leads to overheating under load.
To connect all the elements, you will need a mounting wire, preferably multi-colored, so as not to confuse the polarity during assembly. A development board or a ready-made shield module that expands functionality will also be an indispensable tool. Arduino. If you want to add control from a smartphone, you will need a Bluetooth module HC-05 or HC-06. All components must be in good working order, since one burnt-out transistor in the driver can block the operation of the entire system.
- πΉ Fee Arduino Uno R3 with USB cable for firmware.
- πΉ Engine Driver L298N or similar two-channel module.
- πΉ DC motor gearboxes (2 or 4 pieces) with wheels.
- πΉ Robot chassis (acrylic, plastic or homemade).
- πΉ Power supply (7.4V battery or battery compartment).
Electronics and driver connection diagram
Driver connection L298N to the board Arduino requires strict adherence to pinout to avoid short circuits. The signal pins IN1 and IN2 of the first channel are connected to the digital pins of the microcontroller, which will be responsible for the motion logic. For example, pin 5 can control the direction of the left motor, and pin 6 - the right. The ENABLE pins on the driver are connected to PWM pins (marked with a tilde ~), which will allow you to programmatically adjust the rotation speed.
The entire circuit is powered through the terminal block on the driver, where the plus and minus from the battery are connected. The ground (GND) of all elements must be common, otherwise the control signals will not be correctly read by the controller. Polarity Connecting the motors also plays a role: if the robot goes in the wrong direction, it will be enough to swap the wires at the motor terminals.
For ease of installation, it is recommended to use color markings of the wires: red for positive, black for ground, and make the signal lines yellow or blue. This will make it easier to find errors if the car refuses to move. Driver L298N has two radiators that can get hot during prolonged use, so make sure they have access to air. If you use four motors, they are connected in parallel to each driver channel, which doubles the current draw.
Use a 100uF capacitor in parallel with the driver power terminals to smooth out voltage surges when the motors start and prevent the Arduino from rebooting.
Programming motion logic
The program code is written in the Arduino IDE and consists of two main functions: setup and loop. In the first part, the operating modes of the pins are set as output, and in the second the action algorithm is prescribed. To control motors, it is convenient to use ready-made libraries or write your own functions for moving forward, backward and turning. This will make the main code readable and allow you to easily change the logic of the robotβs behavior.
The PWM signal (Pulse Width Modulation) allows you to change the rotation speed by varying the duty cycle of the pulses on the ENABLE pins. The analog output value can be from 0 to 255, where 255 is the maximum speed. If the car moves too fast and does not have time to turn, the value must be reduced. Delay between commands in milliseconds helps the robot perform movements more smoothly and predictably.
void setup {
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
}
void loop {
// Move forward
analogWrite(5, 200);
analogWrite(6, 0);
analogWrite(9, 200);
analogWrite(10, 0);
delay(1000);
}
It is better to test the code by placing the machine on a weight so that the wheels rotate freely. First, check whether the motors rotate in the right direction when the forward command is given. If one of them turns in the opposite direction, swap the wires on the corresponding driver channel or change the logic in the program. Debugging code takes a significant amount of time, but ensures accurate execution of tasks in the future.
βοΈ Checking the operation of motors
Mechanical and chassis assembly
Mechanical assembly begins with the installation of geared motors on the chassis platform. They are usually attached with screws or double-sided tape if the pull-out load is low. The wheels must sit tightly on the shafts, without play, otherwise there will be energy loss and vibration. Center of gravity the design should be shifted closer to the axis of the drive wheels for better traction with the surface.
Fee Arduino and the motor driver should be secured to the top of the chassis, ensuring insulation from metal parts, if any. Use posts or hot melt adhesive to secure components. It is better to lay the wires in bundles and secure them with ties so that they do not get into the wheel spokes. Careful laying of wires is not only aesthetically pleasing, but also prevents contact breaks during movement.
If you're making a machine from scratch, you can use 3D printing to create a body of any shape. This allows sensor and battery mounts to be integrated directly into the design. For simple models, a laser-cut acrylic base is suitable. The main requirement for the design is rigidity, since vibrations can loosen the contacts.
| Component | Voltage (V) | Current consumption (mA) | Purpose |
|---|---|---|---|
| Arduino Uno | 5-9 | 50 | Management |
| Geared motor | 3-6 | 200-400 | Wheel drive |
| Driver L298N | 5-35 | 2000 | Switching |
| Bluetooth HC-05 | 3.3-5 | 30 | Communication |
Setting up controls and sensors
To implement control via a smartphone, you must connect a Bluetooth module HC-05 to the Arduino serial port. The TX and RX pins of the module are connected to the RX and TX boards, respectively. After downloading the control sketch, the phone is paired with the module, and commands are transmitted over the radio channel. This allows you to control the machine at a distance of up to 10 meters without direct visibility.
If the goal is autonomous movement, for example, avoiding obstacles, an ultrasonic sensor will be required HC-SR04. It is mounted on the front on a servo or statically and measures the distance to objects. The operating algorithm is simple: if the distance is less than a specified threshold, the robot stops and changes its trajectory. Calibration sensors are necessary for correct operation in various lighting conditions and surface reflections.
β οΈ Attention: When using servos to rotate the sensor, make sure that the power supply can withstand peak currents, otherwise the Arduino may reboot when the servo moves.
Additionally, you can install infrared line sensors for track movement. They respond to the contrast between a black line and a white background. The sensitivity of such sensors is adjusted using potentiometers on their board. The combination of different types of sensors makes it possible to create complex robots capable of navigating in space.
Advanced Features
You can add encoders to motor shafts to accurately count revolutions, allowing for odometry and more precise speed control, compensating for motor variations.
Diagnostics and troubleshooting
A common problem is when the engines hum, but the car does not move. This indicates a lack of current or low battery power. Also, the reason may lie in mechanical jamming of the wheels or too high gear ratio. Check the voltage at the battery terminals under load: if it drops below 5 volts, the power source needs to be replaced.
If Arduino reboots when the motors start, which means the voltage in the power circuit drops. The solution would be to use a separate source for the motors or install an additional large capacitor in parallel with the power input. Also check the reliability of the contacts at the soldering points and the connections of the wires in the driver terminals.
Uneven movement, when the robot moves to the side, is treated by software correction of the speed of one of the motors. Since all engines have varying characteristics, it is difficult to achieve perfect speed matching. In the code, you need to reduce the PWM value for a faster motor in order to align the movement path.
β οΈ Attention: Long-term operation of motors in stop mode (when voltage is applied, but the shaft is blocked) will lead to overheating and burnout of the motor or driver winding.
High-quality assembly and reliable power solve 90% of problems with unstable robot operation, so donβt skimp on batteries and wires.
Detailed assembly questions
Is it possible to use toy motors without gearboxes?
You can use regular motors without gearboxes, but they will develop very high speeds with low torque. The car will instantly accelerate and stop just as quickly, which will make it difficult to control. For training purposes, it is better to use motors with plastic gearboxes that provide a balance between speed and traction.
Which battery is better to choose for power supply?
The optimal choice is considered to be Li-Ion batteries of the 18650 format, connected in series (2 pieces give about 7.4V). They have high current output and capacity. Nickel metal hydride (Ni-MH) batteries are also suitable, but they are heavier and have a lower capacity for the same dimensions.
Why does the L298N driver get hot?
The driver heats up due to the passage of current through the internal resistance of the transistors. At currents above 1A, heating becomes significant. If the radiator is hot to the touch, but does not burn you, this is normal. If the temperature is critical, reduce the supply voltage or load, or install additional cooling.
How to increase Bluetooth control range?
The standard HC-05 module operates at a distance of up to 10 meters. To increase the range, you can use modules with an external antenna or switch to the Wi-Fi protocol (ESP8266), which allows you to control the robot via the Internet from anywhere in the world where there is a network.
Do I need to solder the contacts or can I use twists?
For temporary tests, twists or a breadboard are acceptable, but for a working robot it is better to solder the contacts. Vibration during movement quickly breaks the contact in the twists, which will lead to chaotic behavior of the machine or stop.