LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsAn inductive proximity sensor sees metal without touching it, a few millimetres from its face, and it keeps working in oil, dust and vibration. The common LJ12A3-4-Z/BX runs on 6 to 36 V and its NPN output pulls to 0 V while metal is in front. An optocoupler passes that signal to a 5 V Arduino Nano, which counts each pass and works out RPM from the time between pulses. Point it at one bolt head on a pulley for speed, or at parts on a chute for a count.
Keep fingers and loose wires away from turning shafts; mount the sensor with the machine stopped.
The 12 V side and the Nano side must only meet through the optocoupler.
Tick anything you already have and the total updates.
Counts the pulses and drives the display
LJ12A3-4-Z/BX inductive sensor: NPN, normally open, 6-36 V, 4 mm range on steel
PC817-type optocoupler between the 12 V sensor and the 5 V Nano
LJ18A3-8-Z/BX M18 sensor with 8 mm range, for targets that wobble
Capacitive proximity sensor: also sees plastic, grain or liquid through a tank wall
Ready PC817 optocoupler board, if you prefer screw terminals to a bare chip
Follow the colours: red is power, dark grey is ground, blue is a signal.
The sensor needs 6 to 36 V; a 12 V adapter is fine (sold separately). The Nano runs from USB or 5 V. Keep the 12 V ground separate from the Nano: the optocoupler is the only link between them.
prox_rpm_counter.inoVerify & upload in Electrolark#include <TM1637Display.h>
TM1637Display disp(5, 6);
const int SENSOR = 2, BUTTON = 4;
const int TARGETS_PER_TURN = 1; // bolt heads or teeth the sensor sees per revolution
volatile unsigned long pulses = 0, lastPulseUs = 0, periodUs = 0;
void onPulse() {
unsigned long now = micros();
if (now - lastPulseUs < 2000) return; // ignore bounces shorter than 2 ms
periodUs = now - lastPulseUs;
lastPulseUs = now;
pulses++;
}
bool showRpm = false;
void setup() {
pinMode(SENSOR, INPUT_PULLUP);
pinMode(BUTTON, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(SENSOR), onPulse, FALLING); // LOW while metal is in front
disp.setBrightness(5);
Serial.begin(115200);
}
void loop() {
if (digitalRead(BUTTON) == LOW) {
unsigned long t = millis();
while (digitalRead(BUTTON) == LOW) ;
if (millis() - t > 1500) { noInterrupts(); pulses = 0; interrupts(); } // long press: reset
else showRpm = !showRpm; // short press: switch view
}
noInterrupts();
unsigned long n = pulses, p = periodUs, last = lastPulseUs;
interrupts();
float rpm = 0;
if (p > 0 && micros() - last < 3000000UL) rpm = 60000000.0 / (p * (float)TARGETS_PER_TURN);
disp.showNumberDec(showRpm ? (int)rpm : (int)(n % 10000));
Serial.print("count "); Serial.print(n); Serial.print(" rpm "); Serial.println(rpm, 0);
delay(200);
}
Check the sensor LED lights when metal is near. If it does, swap the optocoupler pins 1 and 2: the LED inside only works one way round.
The target is at the edge of the sensing range and flickers. Move the sensor 1 mm closer, or raise the 2 ms bounce filter in the sketch.
With one target the reading updates once a turn. Add more evenly spaced bolts and set TARGETS_PER_TURN to match.
Yes, but at a shorter distance: roughly half the steel range for aluminium. Check the correction factors in the sensor's datasheet.
Not safely. Many NPN sensors pull their output up to the supply voltage inside, so 12 V could reach the Nano pin.
Yes. With 24 V use a 2.2k resistor for the optocoupler LED instead of 1k.
A normally open (NO) sensor switches on when metal arrives; a normally closed (NC) one switches off. The sketch counts the change either way if you swap FALLING for RISING.
11 parts: Generic Nano CH340 Development Board (Soldered), LJ12A3-4-Z/BX Inductive Proximity Sensor NPN NO DC6-36V 4mm Range, Optocoupler IC (Transistor, Triac and High-Speed Output), TM1637 4-Digit 7-Segment Display Module, Tactile Push Button Switch, Resistor Assortment Kit (30 Values), LJ18A3-8-Z/BX Inductive Proximity Sensor NPN NO, DC 6–36V, 8mm Range, IP54, LJC30A3-H-Z/BX Capacitive Proximity Sensor NPN NO, DC 6–36V, 300mA, Detection Range 1–15 mm, PC817 4-Channel Optocoupler Isolation Module, Solderless Breadboard, plus 1 more. 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 intermediate project and takes about 2 to 3 hours. The build on this page has 6 steps.
No. This page has the complete, tested code (prox_rpm_counter.ino).
About ₹1,544 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.
How NPN and PNP sensor outputs differ; Isolating a 12-24 V signal with an optocoupler; Turning pulse timing into RPM with an interrupt.
Keep fingers and loose wires away from turning shafts; mount the sensor with the machine stopped. The 12 V side and the Nano side must only meet through the optocoupler.
Ideas that reuse this build: Conveyor box counter. 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.