Professional Documents
Culture Documents
Car
Components Used:
- H-Bridge: An H-Bridge is a circuit that allows the motors to be controlled in both directions. In this
project, we have used an H-Bridge to control the motors of the car.
- STM32 blue pill: This is a microcontroller board based on the STM32F103C8T6 microcontroller. It
is used to control the H-Bridge and receive input from the sensors.
- IR Sensors: These sensors are used to detect the line on the ground. In this project, we have used
three IR sensors.
- Battery packs: Two battery packs are used in this project. One is connected to the H-Bridge to power
up the motors, and the other is connected to the STM32 blue pill to power it up.
Chassis:
The chassis used in this project is a 4-wheel chassis. The left two motors are connected to one output
of the H-Bridge, and the same goes for the right two motors. This setup allows the car to move in both
directions.
Code:
The code for this project is written in C language. It uses the HAL library for controlling the GPIO
pins of the STM32 blue pill. The code reads the input from the three IR sensors and determines the
position of the line. Based on the position of the line, it controls the motors using the H-Bridge. The
code runs in an infinite loop and continuously reads the input from the sensors and controls the
motors accordingly.
REPORT TITLE 2
#include "main.h"
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
while (1)
{
int sensor1 = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0);
int sensor2 = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1);
int sensor3 = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_2);
if (sensor1 == 0 && sensor2 == 1 && sensor3 == 0) // All sensors are on the line
{
REPORT TITLE 3
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, 0);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, 1);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, 0);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, 1);
}
else // No line detected
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, 0);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, 0);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, 0);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, 0);
}
// HAL_Delay(250);
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
REPORT TITLE 4
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
}
REPORT TITLE 5
void Error_Handler(void)
{
__disable_irq();
while (1)
{
}
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t *file, uint32_t line)
{
}
#endif
Conclusion:
The line tracking car is an interesting project that involves several components and programming
concepts. The use of the H-Bridge and the STM32 blue pill microcontroller makes this project more
advanced and versatile. This project can be further expanded by adding more sensors and
implementing more complex algorithms for line detection and motor control.
REPORT TITLE 6