Overview
The project demonstrates the implementation of a moisture sensor using the VSDSquadron Mini, a RISC-V based development kit. The core concept revolves around detecting moisture presence using a sensor. When moisture is detected, an LED indicator is activated to signal the presence of moisture, and vice versa, it remains off in the absence of moisture. This project leverages the capabilities of the VSDSquadron Mini, including its GPIO ports and on-board programming features, to create an efficient and compact moisture detection system.
Components Required to Build Moisture Sensor
- VSDSquadron Mini
- LED
- Moisture Sensor
- Breadboard
- Jumper Wires
- PlatformIO
- VS Code for software development
Circuit Connection for Moisture Sensor
1. LED Connection
- Positive end (Anode) connected to GPIO Pin 6 of VSDSquadron Mini.
2. Moisture Sensor Connection
- VCC of the moisture sensor to VCC on VSDSquadron Mini.
- Output to GPIO Pin 0 of VSDSquadron Mini.
- GND to ground.
How to Program
1. Environment Setup
- Install PlatformIO and VS Code for software development and project compilation.
2. Include Necessary Libraries
#include <ch32v00x.h>
#include <debug.h>
3. GPIO Configuration
void GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure = {0};
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
// Configure LED pin as output
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
// Add more configurations as needed
}
4. Main Logic
int main(void) {
uint8_t moistureStatus = 0;
// System initialization code here
GPIO_Config();
while(1) {
moistureStatus = GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_0);
if(moistureStatus == 0) {
GPIO_WriteBit(GPIOD, GPIO_Pin_6, RESET);
} else {
GPIO_WriteBit(GPIOD, GPIO_Pin_6, SET);
}
}
}
Working
The project operates on a simple yet effective mechanism where the moisture sensor continuously monitors the soil or a surface for moisture. Upon detecting moisture, the sensor’s output pin goes high, and the connected GPIO pin on the VSDSquadron Mini reads this change. Depending on the moisture status, the system either activates or deactivates an LED, providing a visual indication of the moisture level detected.
Code
The provided code snippets in the “How to Program” section form the basis of the project’s firmware. These snippets include initialization of the development board’s peripherals, configuration of the GPIO pins, and the main operational loop that continually checks the moisture sensor’s output and controls the LED accordingly.
Detailed Project Report
https://drive.google.com/file/d/1gwNAvKH-pGbndcom8Ff31Zt1fW6il_u4/view
Github Repo
https://github.com/madhavasawa/somaiya-riscv/blob/main/README.md