LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsDraw-wire, rod and slider position sensors are potentiometers with a long stroke: the wiper voltage follows the position. A 5 V Arduino reads it on an analog pin, and map() turns the reading into millimetres. A slide-pot module is a cheap way to build and test the same code before you wire a long industrial sensor.
Keep fingers clear of moving rods and wires.
Do not exceed the sensor's stroke: it can break the wiper.
Tick anything you already have and the total updates.
Follow the colours: red is power, dark grey is ground, blue is a signal.
A 5 V USB supply is enough for a resistive sensor on 5 V. A 24 V analog sensor needs its own supply and a shared GND with the Nano.
linear_position.inoVerify & upload in Electrolark#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
const float STROKE_MM = 60.0; // length of your sensor's stroke
const int ZERO_BTN = 2;
float zeroMm = 0;
float readMm() {
long sum = 0;
for (int i = 0; i < 16; i++) sum += analogRead(A0); // average 16 readings
return (sum / 16.0) / 1023.0 * STROKE_MM;
}
void setup() {
pinMode(ZERO_BTN, INPUT_PULLUP);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}
void loop() {
float mm = readMm();
if (digitalRead(ZERO_BTN) == LOW) zeroMm = mm;
oled.clearDisplay(); oled.setTextColor(WHITE);
oled.setTextSize(3); oled.setCursor(0, 8); oled.print(mm - zeroMm, 1);
oled.setTextSize(1); oled.setCursor(0, 50); oled.print("mm from zero");
oled.display();
delay(100);
}
Increase the averaging, and add 100 nF from A0 to GND.
The sensor's end resistance is small, so the stroke is a little less than the wiper travel. Calibrate against a ruler.
Swap the 5V and GND wires, or subtract the reading from STROKE_MM.
Yes, with the 4-20 mA reader project instead.
It depends on the sensor and the 10-bit ADC. With a 60 mm stroke, one count is about 0.06 mm.
Yes. Use a 3.3 V supply for a pot sensor and note ESP32's ADC is not very linear near the ends.
7 parts: Generic Nano CH340 Development Board (Soldered), 10kΩ Slide Potentiometer Module, 0.96" OLED Display 128x64, Tactile Push Button Switch, Resistor Assortment Kit (30 Values), Solderless Breadboard and Dupont Jumper Wires (40 pcs). Tools: Digital Multimeter. On this page you can tick the parts you already have and add only the rest to your cart.
It is a beginner project and takes about 1 to 2 hours. The build on this page has 6 steps.
No. This page has the complete, tested code (linear_position.ino).
About ₹541 for the parts at the prices on this page, plus tools if you do not have them. Quantity price breaks lower the cost when you build several.
Reading a potentiometer-type sensor; Calibrating stroke length in code; Dividing a 0-10 V output down for a 5 V input.
Keep fingers clear of moving rods and wires. Do not exceed the sensor's stroke: it can break the wiper.
Ideas that reuse this build: 4-20 mA reader. They are listed under Take it further on this page.
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
See the smoke level live on a crisp screen and get a loud warning when it spikes.
An infrared eye that spots an open flame and raises the alarm.
Walk into the room and it sounds the alarm: the classic first security build.
Learning project. Check every circuit and the datasheet of each part before you power it up.