Overview
The Object Detector project integrates an ultrasonic sensor with the CH32V003 RISC-V processor to detect nearby objects. By utilizing the ultrasonic sensor, the system can detect objects within its range and alert the user by switching on an LED. This project is designed for various applications, including obstacle detection, proximity sensing, and as a component in larger automated systems.
Components Required
1. Hardware
- CH32V003 RISC-V processor
- Ultrasonic sensor (HC-SR04)
- LED
- Power Supply
- Breadboard
- Jumper Wires
2. Software
- VSCode
- PlatformIO
Hardware Connections
The ultrasonic sensor is connected to the VSDSquadron Mini as follows:
- TRIG PIN to PD2 on VSDSquadron Mini
- ECHO PIN to PD4 on VSDSquadron Mini
- GND to GND on VSDSquadron Mini
- VCC to 3.3V on VSDSquadron Mini
How to Program
- Install PlatformIO Core : Ensure PlatformIO Core is installed on your system. Follow the installation guide provided by PlatformIO.
- Build and Upload Commands :
- Build the project: $ pio run
- Upload the firmware: $ pio run –target upload
- Clean build files: $ pio run –target clean
API Reference
- USART_Printf_Init() : Initializes the USART peripheral for debugging and output.
- Delay_Ms() : Generates a millisecond delay, useful for timing and sensor control.
- GPIO_ReadInputDataBit() : Reads the state of an input pin.
- GPIO_WriteBit() : Sets or clears a specific output pin, used for controlling the LED and the ultrasonic sensor’s trigger.
Code Snippet
#include <ch32v00x.h>
#include <debug.h>
void GPIO_Config(void) {
GPIO_InitTypeDef GPIO_InitStructure = {0};
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
// Configure echo and trigger pins
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOD, &GPIO_InitStructure);
// Configure trigger and LED pins
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
int main(void) {
uint8_t echo_status = 0;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
SystemCoreClockUpdate();
Delay_Init();
GPIO_Config();
while(1) {
// Trigger ultrasonic sensor
GPIO_WriteBit(GPIOD, GPIO_Pin_2, SET);
Delay_Ms(10); // Trigger pulse width
GPIO_WriteBit(GPIOD, GPIO_Pin_2, RESET);
echo_status = GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_4);
if (echo_status == 1) {
// Object detected, blink LED
GPIO_WriteBit(GPIOD, GPIO_Pin_3, SET);
Delay_Ms(2000); // LED on duration
GPIO_WriteBit(GPIOD, GPIO_Pin_3, RESET);
Delay_Ms(2000); // LED off duration
}
}
}
Working Principle
The system operates by sending a short ultrasonic pulse (triggered by PD2) and listening for an echo (received on PD4). The presence of an object within the sensor’s range reflects the pulse back to the sensor, detected as a high signal on the ECHO pin. Upon detection, the processor activates an LED to alert the user of the detected object.
Applications
- Object Detection : Useful in parking assistance systems, robot obstacle avoidance, and proximity detection for home automation.
- Security Systems : Employing ultrasonic sensors for motion detection in restricted areas.
- Distance Measurement : Accurate distance measurements for assembly line spacing, liquid level monitoring, and height measurement of objects.
- Liquid Level Detection : Using ultrasonic sensors to monitor the liquid level inside tanks, preventing unstable readings caused by wavy surfaces or bubbles.
Detailed Project Report
https://drive.google.com/file/d/1cq8VzAWV3-8p111bpxCW_VXBy3182G0E/view?usp=sharing
Github Repo
https://github.com/Amanb17/somaiya-riscv/
Application Video
Related Posts:
- Secure Saiyan
- Advanced Easy to use Burgler Alarm
- The Future of Chip Design: The Next Generation is…
- RISC-V Mini Game Console
- Water level monitoring and control in water tank
- COLORIMETER
- Shape Tomorrow’s Technology Today: ELCIA Hackathon…
- LiFi Lock - An authentication system using LiFi…
- Bluetooth automated smart access
- Smart Plant Care using the VSD_Squadron-MINI-BOARD