SW420 Raspberry Pi Vibration Monitor and API

README-Fossil.md
Login

README-Fossil.md

File README-Fossil.md from the latest check-in


C# Vibration Monitor for the Raspberry Pi and SW-420 Vibration Sensor

This C# project runs on a Raspberry Pi, records vibration periods from an SW-420, and has a web API for retrieving the data.

The SW-420 Vibration Sensor is an inexpensive package (search SW-420 on Amazon - as of late 2024 prices are under $10 for a pack of 5) that can be powered from a Raspberry Pi (this has been tested on the Pi Zero 2 W, 3 A+ and 3 B+) and outputs its state on a GPIO pin. The sensor has a potentiometer to adjust its sensitivity.

This program uses several settings to record 'Vibration Periods' to a SQLite database and serve that data via a web API:

This is NOT designed to record each individual vibration that the SW-420 records - and is also not designed to record single very short vibrations - rather it is designed to record something like a motor running where the SW-420 may switch between vibrating/not-vibrating multiple times over the motor's run. Once the program receives a vibration (how often it checks is set with the Polling Frequency) it will consider the vibration ongoing as long as it receives another vibration within the Minimum Period (even if every check of the sensor does not register as vibrating).

Vibration Periods (and program errors) are written to the database and can be retrieved via the web api.

Command Line Arguments

Pi Setup

There is a PublishAll.ps1 script in the root directory that will publish both the VibrationMonitor and VibrationMonitorApi projects for the Raspberry Pi to M:VibrationMonitorProject using the FolderProfile.pubxml files in the VibrationMonitorPropertiesPublishProfiles and VibrationMonitorApiPropertiesPublishProfiles. You can either map a directory to M: or edit the script and the FolderProfile.pubxml files to point to another directory.

Setting up and securing a Raspberry Pi is beyond the scope of this readme - suggested below are some basic steps to get the program up and running on a Raspberry Pi.

To setup the SW420 sensor setup:

Web API

** This program assumes that the Web API will be used on an internal network and that there is ZERO need to secure Vibration API data!! **

The easiest way to get started with the api is to visit http://[Your Pi's IP Address/name]:[7171 or the port you specified]/ - this will show the Swagger UI for the API.

API Endpoints:

Background

Our house has an alternative septic system - I had never even heard of an 'alternative' septic system until a few years ago! The system we have includes a control panel with a timer for a pump in the holding tank. Overall this is a durable and elegant system - but it doesn't log information, and if you have a problem or a question (and aren't an expert on the system) this can be frustrating. I wrote this system to monitor the pump in our holding tank. There are two important reasons I used a vibration sensor: attaching the vibration sensor to the output pipe from the tank means the monitor is more likely to measure 'water flowing out of the tank' which is ultimately what matters (vs for example monitoring current to the motor, which would probably be cleaner, but really I only care about water leaving the tank...) and it allows monitoring without any changes to, or extra equipment in, the control panel - a critical detail for a system under warranty!

Packages Used

Even this fairly simple program owes an incredible debt to the amazing open source projects available for .NET and all of the people who have contributed to them!

Tools: