September 5, 2026
I Built an AI System That Can Detect when an Oil Pipeline is about to be Vandalized
Nigeriaβs oil and gas industry depends heavily on pipelines to transport crude oil and petroleum products. But these pipelines face a majorβ¦
By Davidolufemi
8 min read
Nigeria's oil and gas industry depends heavily on pipelines to transport crude oil and petroleum products. But these pipelines face a major problem: vandalism and leakage.
Pipeline vandalism is the deliberate damaging, cutting, drilling, or tampering with a pipeline, often with the aim of stealing crude oil or petroleum products. Tools such as angle grinders, drills, hammers, and hacksaws can be used to damage the pipe.
The problem is that by the time a damaged pipeline is discovered, significant damage may have already occurred.
Between 2017 and 2021, Nigeria recorded about 7,143 cases of pipeline breakages and deliberate vandalism, resulting in the loss of approximately 208.6 million barrels of crude oil valued at about β¦4.325 trillion (Orji, 2023).
So I asked a simple question:
What if a pipeline could detect that someone was trying to damage it before the damage became severe?
That question led to the development of my AI-powered pipeline vandalism and leakage detection system.
The Idea
Instead of waiting for a pipeline to break, my system listens for the sounds produced when vandalism tools come into contact with the metal pipeline.
A vibration sensor is attached directly to the pipeline. When a tool hits, drills, cuts, or grinds the pipe, it creates a vibration. The sensor detects this vibration and wakes up a microphone, which then captures the surrounding sound.
That sound is sent to an AI model running directly on a microcontroller.
The model then determines whether the sound is likely to be caused by a vandalism-related activity or by something normal happening around the pipeline.
And this distinction is important.
A vibration does not always mean someone is attacking the pipeline. Heavy rain, strong wind, a passing train, or other environmental activities can also create vibrations and sounds.
So I trained the AI model to learn the difference.
VIDEO OF HOW THE PROJECT WORKS
YOU CAN DOWNLOAD THE VIDEO BELOW
If the AI identifies the activity as vandalism, the system immediately responds:
Vibration detected β Sound captured β AI analysis β Vandalism detected β Alarm β GPS location β Email alert
The system can make the vandalism detection decision within about 12 seconds, allowing personnel to know that something is happening before the situation goes unnoticed for a long period.
If the sound is classified as normal environmental activity, the alarm is not triggered and the system simply returns to monitoring.
It Also Watches for Leaks
Vandalism isn't the only problem.
A pipeline can also develop a leak, so I added two flow sensors at different points along the pipeline.
Under normal conditions, the amount of fluid entering and leaving the monitored section should be relatively close. If there is a significant difference between the two readings, it can indicate that fluid is being lost somewhere between the sensors.
This gives the system two main jobs:
Listen for vandalism. Monitor for leakage.
And the interesting part is that all of this is handled by a small embedded system rather than a large monitoring station.
How I Built It
The entire AI development process was done using Edge Impulse, Edge Impulse | MLOps for Edge AI and Physical AI a platform for building and deploying machine-learning models on edge devices such as microcontrollers. It provides tools for collecting and preparing sensor data, extracting useful features, training models, testing them, and deploying them to embedded hardware.
1. Teaching the AI What Vandalism Sounds Like
The first step was collecting the sounds I wanted the system to recognize.
I recorded and collected sounds of tools such as angle grinders, drills, hammers, and hacksaws being used on metal. But I didn't want the model to simply learn "loud sound = vandalism."
So I also collected sounds that could happen around a pipeline without anyone trying to damage it, including heavy rain, strong wind, trains, vehicles, speech, and other environmental sounds.
This gave the model two broad categories to learn from:
Vandalism-related sounds Tools being used on metal.
Normal sounds Environmental sounds that should not trigger an alarm.
I then uploaded the recordings to Edge Impulse.
2. Cleaning the Audio
Before training the model, I cleaned the recordings by manually removing sections where there was only silence.
This was important because I wanted the model to learn from the actual sounds rather than spending part of its training on empty audio.
After cleaning the recordings, I created the Impulse in Edge Impulse.
An Impulse defines how the raw audio will be processed before it reaches the AI model. Here, I selected the audio window size, window stride, audio processing method, and the classification block.
For this project, each audio sample was processed using 1-second windows with a 500 ms stride.
3. Turning the Audio Into Something the AI Can Understand
Raw audio is basically a stream of numbers. The AI cannot simply look at the recording the way a person listens to it, so the audio needed to be converted into useful features.
I used Mel-Frequency Energy (MFE) to do this.
Each 1-second audio window was divided into overlapping 32 ms frames, with a 16 ms stride between frames. A 512-point Fast Fourier Transform (FFT) was then applied to each frame to obtain its frequency information.
The frequency information was passed through 40 Mel-scale filters covering 200β6,000 Hz. This helped focus the model on the frequency range most relevant to the mechanical sounds being studied while reducing the influence of very low-frequency background noise.
A β40 dB noise floor was also used to suppress very low-energy background components.
In simple terms:
I took the raw sound β broke it into small pieces β extracted the important frequency information β gave those features to the AI.
4. Training the AI
With the audio prepared, the next step was to teach the model how to distinguish between the two classes.
I trained a Convolutional Neural Network (CNN) on Edge Impulse for 100 epochs, using the Adam optimizer, a learning rate of 0.0003, and a batch size of 32. I also used data augmentation, including low-level noise addition and time/frequency masking, to help the model handle variations in real-world sounds.
The goal was simple:
Give the model enough examples until it could recognize the difference between vandalism-related sounds and normal environmental sounds.
What happened during training?
The training accuracy increased from about 65% at the beginning to about 96% by the end, while validation accuracy increased from approximately 80% to about 95%.
The training and validation curves remained relatively close, which suggested that the model was learning useful patterns without showing major signs of overfitting.
The loss curves also decreased during training, moving from around 0.60 toward 0.10.
5. The Result
After training, the CNN achieved a 98.1% validation accuracy with a validation loss of 0.08.
It correctly classified 98.7% of normal sounds and 97.5% of vandalism sounds, with an F1-score of 0.98 for both classes.
On a separate test evaluation, the unoptimised float32 model achieved an overall accuracy of 92.35%.
Those numbers were encouraging, but I didn't want to stop at a computer screen.
The real question was: could the AI actually work on the physical device?
6. Putting the AI Inside the Microcontroller
The next step was moving the trained model from Edge Impulse onto the ESP32-S3 microcontroller.
This is where the project became more than just an AI model running on a computer.
The ESP32-S3 became the small computer responsible for running the AI and controlling the rest of the system.
I then connected the other components β the vibration sensor, microphone, GPS, buzzer, flow sensors, communication system, and power supply.
The serial monitor was also used during testing to confirm what the system was detecting and when a vandalism event was recognized.
7. Building the Physical Prototype
After integrating the electronics, I implemented the system on a PVC pipeline prototype.
The prototype allowed me to simulate the operation of a real pipeline while testing both vandalism detection and leakage detection.
The vibration sensor was attached to the pipeline, while the microphone was positioned to capture the surrounding sound after vibration was detected.
The two flow sensors were installed at different points so that the system could compare the flow entering and leaving the monitored section.
This allowed me to test the two main functions of the system:
Can it recognize a possible vandalism event?
Can it identify a significant difference in flow that may indicate a leak?
8. Testing It Outside the Computer
This was probably the most important part of the project.
A model can perform well during training and still struggle when exposed to the messy conditions of the real world.
During testing, I found an important limitation.
The microphone used in the prototype had an effective coverage of only about 2 metres. That is reasonable for a small prototype, but it would not be enough to monitor kilometres of pipeline with a single microphone.
This means that for a real large-scale deployment, the system would need multiple distributed monitoring nodes, or a different sensing technology capable of covering much longer distances.
One promising direction would be distributed acoustic sensing (DAS) using fibre-optic cables. Instead of depending on individual microphones placed every few metres, DAS can use an optical fibre installed along the pipeline to detect vibrations at different locations along the fibre. This could make it much more suitable for long pipeline routes.
9. One More Challenge: Construction Noise
I also identified another important limitation.
Imagine there is construction work close to the pipeline and workers are using mechanical equipment. The sound from those tools could potentially be picked up by the microphone.
However, there is an important part of my design that helps reduce this problem:
The microphone is not continuously listening.
The vibration sensor acts as the first trigger.
So the sequence is:
No pipeline vibration β microphone stays inactive
Pipeline vibration detected β microphone wakes up
Sound captured β AI analyses it
This means ordinary mechanical noise occurring somewhere nearby should not automatically cause an alarm unless there is also a relevant vibration detected on the monitored pipeline.
It does not completely eliminate false alarms, but it provides an additional layer of filtering.
For a larger real-world system, I would improve this further by combining the AI audio classification with multiple vibration sensors, better acoustic localization, and additional sensor information before confirming an event.