0% found this document useful (0 votes)
16 views6 pages

Ultrasonic Radar With RaayanMini

The document outlines a project for creating an Ultrasonic Radar using the Raayan Mini Development Board, which involves an ultrasonic sensor for distance measurement, a servo motor for scanning, and a 16x2 LCD for data display. It details the hardware requirements, connections, and software implementation, including code snippets for initializing components and controlling the radar functionality. The project also suggests optional Wi-Fi capabilities for remote data transmission.

Uploaded by

20 SNEHA 5011 M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views6 pages

Ultrasonic Radar With RaayanMini

The document outlines a project for creating an Ultrasonic Radar using the Raayan Mini Development Board, which involves an ultrasonic sensor for distance measurement, a servo motor for scanning, and a 16x2 LCD for data display. It details the hardware requirements, connections, and software implementation, including code snippets for initializing components and controlling the radar functionality. The project also suggests optional Wi-Fi capabilities for remote data transmission.

Uploaded by

20 SNEHA 5011 M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Ultrasonic Radar Using RaayanMini

This project will allow the radar to sweep over a range of angles using the
servo motor, measure distances using the ultrasonic sensor, and display the data on the
16x2 LCD. Let's break the project down into hardware connections and software
development.

Schematic using (Easy EDA)

Project Overview

● Ultrasonic Sensor (HC-SR04) will be used to measure distances.


● A Servo Motor will rotate the sensor to scan different angles, creating a simple
radar effect.
● Raayan Mini Development Board will control the sensor and the servo motor.
● Data will be displayed on the 16x2 LCD.
● Optionally, you can send the data over Wi-Fi using the ESP module.
Hardware Requirements

1. Raayan Mini Development Board (STM32F401RBT6).


2. HC-SR04 Ultrasonic Sensor (for distance measurement).
3. Servo Motor (to rotate the ultrasonic sensor).
4. 16x2 LCD (to display distance readings).
5. Power Supply (5V for the HC-SR04 and Servo motor, 3.3V for the STM32).
6. Wires & Breadboard for connections.

Hardware Connections

1. Ultrasonic Sensor (HC-SR04)

● VCC of HC-SR04 → 5V on Raayan Mini.


● GND of HC-SR04 → GND on Raayan Mini.
● Trigger of HC-SR04 → PA0 (GPIO pin) on Raayan Mini.
● Echo of HC-SR04 → PA1 (GPIO pin, Input Capture) on Raayan Mini.

2. Servo Motor

● VCC of Servo → 5V (external power supply).


● GND of Servo → GND.
● PWM Pin of Servo → PA8 (GPIO pin for PWM output).

3. 16x2 LCD (Using GPIO)

● VCC → 5V on Raayan Mini.


● GND → GND.
● LCD_RS → PB4.
● LCD_RW → PB5.
● LCD_EN → PB8.
● LCD_DATA_4 → PB0.
● LCD_DATA_5 → PB1.
● LCD_DATA_6 → PB2.
● LCD_DATA_7 → PB3.

Software Implementation

We'll use STM32CubeIDE for firmware development. The software needs to handle
several tasks:

1. Triggering the Ultrasonic Sensor.


2. Reading the Echo Pin to measure the time taken for the ultrasonic pulse to
return.
3. Controlling the Servo Motor via PWM.
4. Displaying Distance on the LCD.
5. Sweeping the Servo Motor to simulate radar scanning.

SOURCE CODE:

1. Initializing the LCD

The 16x2 LCD is connected in parallel mode, so you need to initialize the LCD for
8-bit or 4-bit mode (depending on how you connect the data lines). Here’s a basic
initialization for the LCD:

void LCD_Init(void) {
// Set LCD pins as output
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 |
GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

// Initialize LCD in 4-bit mode and clear display


lcd_command(0x28); // 4-bit mode, 2-line display
lcd_command(0x01); // Clear display
lcd_command(0x06); // Auto-increment cursor
lcd_command(0x0C); // Display ON, Cursor OFF
}

2. Triggering the Ultrasonic Sensor

We will use a simple GPIO toggle to trigger the ultrasonic sensor, followed by a
delay.

void trigger_ultrasonic() {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET); // Set Trigger high
HAL_Delay(10); // 10ms pulse
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET); // Set Trigger low
}

3. Measuring the Echo Time Using Timer

We will use Input Capture mode on PA1 to measure the time it takes for the echo
to return. This method is much more accurate than polling.

uint32_t echo_time = 0;

void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) {


if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1) {
echo_time = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1); // Capture time
}
}

float calculate_distance(uint32_t echo_time) {


// Speed of sound = 343 m/s
return (echo_time * 343.0) / 2.0; // Divide by 2 since it's a round trip
}

4. Servo Control (PWM)

To control the servo motor, use PWM. We will use PA8 for PWM output.

void set_servo_angle(uint16_t angle) {


uint16_t pulse_width = (angle * 2000 / 180) + 500; // Convert angle to pulse width (in
microseconds)
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, pulse_width); // Update PWM
duty cycle
}

5. Displaying the Distance on the LCD

Once we calculate the distance, we can display it on the LCD.

void display_distance(float distance) {


char buffer[16];
sprintf(buffer, "Dist: %.2f cm", distance);
lcd_print(buffer); // Display on the LCD
}
6. Main Loop (Sweeping the Sensor)

The servo motor will rotate from 0° to 180° to simulate radar scanning. At each
position, the ultrasonic sensor will take a reading, and the distance will be
displayed on the LCD.

int main(void) {
HAL_Init();
SystemClock_Config();
LCD_Init();
HAL_TIM_Base_Start(&htim1); // Start the timer for PWM and Input Capture

// Set up the servo (PWM on PA8)


TIM_OC_InitTypeDef sConfigOC = {0};
sConfigOC.Pulse = 1000; // Start with 0 degrees
HAL_TIM_PWM_Init(&htim1);
HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);

while (1) {
for (int angle = 0; angle <= 180; angle += 15) {
set_servo_angle(angle); // Sweep the servo
trigger_ultrasonic(); // Trigger ultrasonic sensor
HAL_Delay(50); // Wait for sensor to settle

float distance = calculate_distance(echo_time); // Calculate distance


display_distance(distance); // Display on LCD
HAL_Delay(500); // Delay between scans
}
}
}

7. Debugging and Testing

● Verify connections: Double-check the connections between the Raayan Mini, HC-
SR04, servo, and LCD.
● Check power supply: Ensure you have separate power supplies for the servo and
the STM32F401RBT6.
● PWM signal: Adjust the PWM range for the servo to ensure it rotates within the
desired range (0° to 180°).
● LCD display: If the LCD doesn't display correctly, ensure the wiring is proper,
especially the data pins.

Conclusion

With this setup, you'll have an Ultrasonic Radar that:

● Uses the HC-SR04 ultrasonic sensor to measure distances.


● Uses the servo motor to rotate and scan different angles.
● Displays the distance on a 16x2 LCD.

Optionally, you can add Wi-Fi functionality using the ESP module (via UART), enabling
you to transmit the radar data remotely or visualize it on a web interface. This is a great
project for learning how to interface with sensors, motors, and displays using STM32.

You might also like