LPG gas leak alarm
A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.
Shop by category
Shop all componentsFactory sensors run on 12 or 24 V and switch to 0 V when they see something (NPN output). An optocoupler lets a 5 V Arduino read them safely. This counter uses an E3F-DS30C4 diffuse photoelectric sensor to count boxes, a slot sensor on a slotted disc to show belt speed, and a toggle switch to reset the count. A relay output can stop the belt or ring a bell after a set batch.
This counter must never be used to protect people from moving machinery.
Switching a motor or conveyor on mains must be done by a qualified electrician.
Tick anything you already have and the total updates.
E3F-DS30C4 diffuse photoelectric sensor, NPN NO, 6-36 V
PC817-type optocoupler to isolate the 12 V sensor
Slot (photo-interrupter) module for the speed disc
Capacitive proximity sensor: sees grain, liquid or boxes through a plastic wall
12 V power relay for a home-made driver (needs a transistor and flyback diode)
OPT101 photodiode module to measure how much light a product blocks
Metal-cased LDR for a very simple light-barrier counter
AS-10 24 V light-operated switch for dusk-to-dawn lamps
Tiny reflective sensor for reading marks on a rotating shaft
Certified safety laser scanner: the only right choice for guarding people near a moving machine
Follow the colours: red is power, dark grey is ground, blue is a signal.
The sensor needs 12 V (supply sold separately). The Nano runs from USB or 5 V. Keep the 12 V ground separate: the optocoupler is the only link.
box_counter.inoVerify & upload in Electrolark#include <TM1637Display.h>
TM1637Display disp(5, 6);
const int BOX = 2, SLOT = 3, RESET_SW = 4, RELAY = 7;
const int BATCH = 24, SLOTS_PER_TURN = 1;
volatile unsigned long slotPulses = 0;
void onSlot() { slotPulses++; }
unsigned long count = 0, lastEdge = 0, lastRpm = 0;
bool lastBox = HIGH;
void setup() {
Serial.begin(115200);
pinMode(BOX, INPUT_PULLUP); pinMode(SLOT, INPUT); pinMode(RESET_SW, INPUT_PULLUP);
pinMode(RELAY, OUTPUT);
attachInterrupt(digitalPinToInterrupt(SLOT), onSlot, FALLING);
disp.setBrightness(5);
disp.showNumberDec(0);
}
void loop() {
if (digitalRead(RESET_SW) == LOW) { count = 0; disp.showNumberDec(0); delay(200); return; }
bool box = digitalRead(BOX); // LOW while a box is in front (opto on)
if (box == LOW && lastBox == HIGH && millis() - lastEdge > 150) {
count++; lastEdge = millis();
disp.showNumberDec(count % 10000);
if (count % BATCH == 0) { digitalWrite(RELAY, HIGH); delay(2000); digitalWrite(RELAY, LOW); }
}
lastBox = box;
if (millis() - lastRpm >= 1000) {
noInterrupts(); unsigned long p = slotPulses; slotPulses = 0; interrupts();
Serial.print("count "); Serial.print(count);
Serial.print(" roller rpm "); Serial.println(p * 60.0 / SLOTS_PER_TURN);
lastRpm = millis();
}
}
The sketch above runs here on a simulated Arduino Nano. Move the sliders for the sensors and buttons it reads, and watch the Serial monitor, display and outputs change.
Check the sensor's own LED lights when a box passes. If it does, check the opto wiring and that D2 reads LOW then.
Increase the 150 ms debounce or angle the sensor so it does not see gaps in the box.
The slot module output goes LOW when the beam is blocked; check the disc really passes through the slot.
Yes: connect its output to the opto anode through 1k and the opto cathode to 0 V.
Its supply is 12 V. A wiring mistake would destroy the Nano; the optocoupler prevents that.
No. A counter is not a safety device. Use certified safety sensors and relays for guarding people.
17 parts: Nano CH340 Development Board (Soldered), Generic E3F-DS30C4 Infrared Photoelectric Sensor Switch – NPN NO, DC 6-36V, Optocoupler IC (Transistor, Triac and High-Speed Output), Generic Broken Light Module – Photo Interrupter Sensor, 5V Digital Output, TM1637 4-Digit 7-Segment Display Module, Miniature Toggle Switch, 5V Relay Module with Optocoupler, Resistor Assortment Kit (30 Values), LJC30A3-H-Z/BX Capacitive Proximity Sensor NPN NO, DC 6–36V, 300mA, Detection Range 1–15 mm, JQC3F-C-S-DC12V 7A SPDT Power Relay, plus 7 more. 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 (box_counter.ino).
Yes. The Run it panel under the code runs this exact sketch on a simulated board. Move the sliders or press the buttons for the sensors it reads, and the Serial monitor, display and outputs react as they will on the real build. It is a simulation, so real readings depend on your parts and wiring.
About ₹13,66,326 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Reading NPN industrial sensors through an optocoupler; Edge counting with debounce; Measuring speed with a slot sensor and slotted disc.
Ideas that reuse this build: RF 433 MHz remote relay. 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.
count 0 roller rpm 0.00 count 0 roller rpm 0.00
A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.