Same-day dispatch before 2 PM · Free delivery over ₹999 · GST invoices Get the appPrices incl. GST
Geekobot
Snap & SendNEWGeeko AIWhere's myOrder
Log in
Products
  • Projects
    • Component guidesHow parts work, with code you can run
    • Learning pathsFrom your first LED to your first robot
    • Workshops & eventsOnline sessions for makers and classes
    • ElectrolarkFree guided builds, simulator and certificates
    • Students & teachersStudent discount and classroom help
    • CommunityShare builds and ask other makers
    • CalculatorsOhm's law, LED resistor, 555 and 100+ more
    • Circuit builderWire parts and run the circuit, powered by Electrolark
    • Geeko AIAsk what to buy or how to wire it
    • Snap & SendPhotograph a part or list, we find it
    • Part finderAnswer a few questions, get the right part
    • Compatibility checkWill these two parts work together?
    • Compare partsSpecs side by side
    • Business & bulk ordersGST invoices, credit and volume prices
    • Request a quotationSend your list, get a quote
    • Classroom kitsPer-student kits and lab bundles
    • Gift cardsFor students, teams and events
  • Atal Tinkering Lab
BOM to cart
Geekobot

Components, kits and know-how for makers, students, engineers, labs and businesses across India.

Ask Geeko AIOrders, parts and projects, any timeEmail supportReply within 1 working dayGet the Geekobot appAdd it to your home screen, free

Follow us

Shop

  • Boards & SBCs
  • Sensors & Modules
  • IoT & Wireless
  • Drone & FPV
  • 3D Printing
  • Filaments & Resins
  • Motors & Drivers
  • Power & Batteries
  • Semiconductors
  • Passive
  • Displays & LEDs
  • Switches & Relays
  • Wires & Cables
  • Prototyping
  • Tools & Test
  • Robotics
  • STEM Kits
  • Atal Tinkering Lab
  • Mechanical Parts
  • Audio

Orders

  • Track your order
  • Help & support
  • Shipping and delivery
  • Refunds and cancellation
  • Contact us

Learn

  • Projects
  • Geeko AI project assistant
  • Learning paths
  • Guides
  • Calculators
  • Electrolark: free guided builds

Part tools

  • Part finder
  • Compare parts
  • Will it work with my board?

Institutions

  • Classroom kits
  • Atal Tinkering Lab
  • Students & teachers
  • Workshops & Events

Business

  • Business & education
  • Request a quotation
  • BOM bulk upload
  • Quick order by SKU

Company

  • About Geekobot
  • Community
  • Gift cards
  • Terms & conditions
  • Privacy policy
  • Product directory
  • Sitemap

© 2026 Geekobot, a trade name of OLatus Systems Private Limited. All rights reserved.

20, 1st Floor, Neeladri Complex, 10th Cross, Sampige Rd, 2nd Main, Malleshwaram, Bengaluru, Karnataka 560003 · GSTIN 29AACCO0462F1ZM

+91 91810 15607 · connect@geekobot.in · Monday to Saturday, 10 AM to 2 PM IST

UPI · CARDS · NETBANKING · GST INVOICES

ShopProjectsGeeko AIGuides
Compare 0 parts →
Log in

Shop by category

Shop all components
  • Boards & SBCs1,910 products
    • Alternative Single Board Computers
    • Arduino Ecosystem
    • FPGA & Logic Boards
    • Microcontroller & Wireless Boards
    View all
  • Sensors & Modules4,701 products
    • Biomedical & Heart Rate
    • Current, Voltage & Power
    • Force, Weight & Pressure
    • Gas, Weather & Environmental
    View all
  • IoT & Wireless2,314 products
    • RF Modules
    • RFID & NFC
    • Antennas & RF Accessories
    • Cameras & Smart Vision
    View all
  • Drone & FPV3,558 products
    • Flight Control & Navigation
    • FPV Video & Optics
    • Frames & Structural Parts
    • Motors & Propulsion
    View all
  • 3D Printing2,204 products
    • 3D Printers
    • 3D Scanners & Digitizers
    • Laser Engravers & Cutters
    • Material Management & Upgrades
    View all
  • Filaments & Resins1,472 products
    • Filaments
    • Photopolymer Resins
    View all
  • Motors & Drivers463 products
    • BLDC Motor Drivers
    • DC & Geared Motors
    • DC Motor Drivers
    • Linear Actuators & Solenoids
    View all
  • Power & Batteries557 products
    • Battery Holders & Connectors
    • Breadboard Power
    • Chargers & BMS
    • DC-DC Converters
    View all
  • Semiconductors295 products
    • Diodes & Rectifiers
    • Interface & RF Encoder ICs
    • Logic ICs (74xx)
    • Logic ICs (CD4000)
    View all
  • Passive67 products
    • Capacitors
    • Circuit Protection
    • Crystals & Oscillators
    • Inductors
    View all
  • Displays & LEDs572 products
    • 7-Segment & Dot Matrix
    • Addressable LEDs
    • Character LCDs
    • Graphic LCDs
    View all
  • Switches & Relays184 products
    • Keypads & Touch
    • Push Buttons & Tactile
    • Relay Modules
    • Relays
    View all
  • Wires & Cables233 products
    • Board-to-Wire Connectors
    • Crimp & Splice
    • Headers & Dupont
    • Heat Shrink & Sleeving
    View all
  • Prototyping101 products
    • Breadboards
    • Interface Modules
    • PCBs & Perfboards
    View all
  • Tools & Test717 products
    • Bench Power Supplies
    • Hand Tools
    • Measuring Tools
    • Meters & Testers
    View all
  • Robotics180 products
    • Humanoid & Legged Robots
    • Robot Chassis & Platforms
    • Robotic Arms & Grippers
    • Wheels & Casters
    View all
  • STEM Kits268 products
    • Arduino Learning Kits
    • Coding & IoT Kits
    • Early Coding (Ages 3-8)
    • Invention Kits
    View all
  • Atal Tinkering Lab196 products
    • Package 1: Electronics, Robotics, IoT and Sensors
    • Package 2: Rapid Prototyping Tools
    • Package 3: Mechanical, Electrical and Measurement Tools
    • Package 4: Power Supply, Accessories and Safety Equipment
    View all
  • Mechanical Parts212 products
    • Bearings
    • Brackets & Mounts
    • Couplers
    • Fasteners & Standoffs
    View all
  • Audio109 products
    • Amplifier Modules
    • Buzzers & Sirens
    • Speakers
    View all
  1. Home
  2. ›Projects
  3. ›Conveyor box counter

Sensor projects

Conveyor box counter with an industrial photoelectric sensor

Count boxes on a belt with a 12 V NPN sensor, isolated by an optocoupler, and show the total on a 4-digit display.

By Geekobot Learning Team

Intermediate
Difficulty
2 to 3 hours
Build time
₹13,66,326
Parts cost
17
Parts
Arduino
Platform
Add all parts · ₹13,66,326Start building
  • Workshop & industry
  • Measurement & tools
NANO12:30
Tap a part to see what it does
OverviewPartsWiringBuildCodeTroubleshootFAQIdeas

What you'll build

Factory 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.

What you'll learn

  • Reading NPN industrial sensors through an optocoupler
  • Edge counting with debounce
  • Measuring speed with a slot sensor and slotted disc
Safety

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.

  1. SensePhotoelectric and slot sensors
  2. ThinkNano counts edges and pulses
  3. ActTM1637 shows the count; relay signals a full batch

Parts list

Tick anything you already have and the total updates.

PartQtyPrice
  • NANO
    Nano CH340 Development Board (Soldered)
    GB-SBCD-0339Guide

    Counts and drives the display

    × 1₹185₹185
  • Generic E3F-DS30C4 Infrared Photoelectric Sensor Switch – NPN NO, DC 6-36V
    GB-SENS-1784Guide

    E3F-DS30C4 diffuse photoelectric sensor, NPN NO, 6-36 V

    × 1₹186₹186
  • Optocoupler IC (Transistor, Triac and High-Speed Output)
    GB-SEMI-0108

    PC817-type optocoupler to isolate the 12 V sensor

    × 1₹4₹4
  • Generic Broken Light Module – Photo Interrupter Sensor, 5V Digital Output
    GB-SENS-3281Guide

    Slot (photo-interrupter) module for the speed disc

    × 1₹33₹33
  • 12:30
    TM1637 4-Digit 7-Segment Display Module
    GB-DISP-0011Guide

    4-digit display for the count

    × 1₹55₹55
  • Miniature Toggle Switch
    GB-SWRL-0011Guide

    Toggle switch: count or reset

    × 1₹15₹15
  • RELAY
    5V Relay Module with Optocoupler
    GB-SWRL-0001Guide

    Relay output for a batch-complete signal

    × 1₹74₹74
  • Resistor Assortment Kit (30 Values)
    GB-PASV-0002Guide

    1k for the opto LED, 10k pull-up

    × 1₹33₹33
  • LJC30A3-H-Z/BX Capacitive Proximity Sensor NPN NO, DC 6–36V, 300mA, Detection Range 1–15 mm
    GB-SENS-1232Guide

    Capacitive proximity sensor: sees grain, liquid or boxes through a plastic wall

    × 1₹529₹529
  • JQC3F-C-S-DC12V 7A SPDT Power Relay
    GB-SWRL-0077

    12 V power relay for a home-made driver (needs a transistor and flyback diode)

    × 1₹28₹28
  • OPT101 Analog Light Sensor Module with Monolithic Photodiode
    GB-SENS-3168

    OPT101 photodiode module to measure how much light a product blocks

    × 1₹1,029₹1,029
  • Senba D57 5mm LDR Light Sensor with Metal Casing
    GB-SENS-1935Guide

    Metal-cased LDR for a very simple light-barrier counter

    × 1₹82₹82
  • Generic AS-10 Optical Sensor Switch 24V 10A – Photoelectric Control Module
    GB-SENS-1917Guide

    AS-10 24 V light-operated switch for dusk-to-dawn lamps

    × 1₹116₹116
  • Sharp Microelectronics GP2S60 Reflective Optical Sensor, 0.5mm Detection Range, Phototransistor Output, Compact SMT
    GB-SENS-1671Guide

    Tiny reflective sensor for reading marks on a rotating shaft

    × 1₹61₹61
  • SICK MICS3-CBAZ90EN1P01 Safety Laser Scanner – 275° Beam Angle, 64m Range, SIL2, IP65
    GB-SENS-2740

    Certified safety laser scanner: the only right choice for guarding people near a moving machine

    × 1₹13,63,829₹13,63,829
  • Solderless Breadboard
    GB-PROT-0001Guide

    Holds the parts without soldering

    × 1₹18₹18
  • Dupont Jumper Wires (40 pcs)
    GB-WIRE-0001Guide

    Connects the parts

    × 1₹49₹49

Complete kit

17 of 17 parts in one tap

₹13,66,326

GST included

3% off these parts while the whole kit stays in your cart

Parts you still need

₹13,66,326

17 of 17 parts. Tick anything you already have.

About ₹4,09,89,780 before bulk pricing for 30 kits.

Request bulk quote

Learn the parts

  • ESP32 vs Arduino Uno
  • E3F-DS30 and E3F1-DS5 Photoelectric Switches
  • Photointerrupters and Slot Sensors
  • TM1637 4-digit display
  • Toggle, Rocker and Slide Switches
  • 5V, 12V and 24V Relay Modules (1 to 16 Channel)
  • I2C Explained
  • Industrial Inductive and Capacitive Proximity Sensors
  • Photocell Street Light Switches and Daylight Sensors
  • Photodiodes, Phototransistors and Photointerrupters
  • Arduino Uno

Calculators for this build

  • Ohm’s law calculator
  • Resistor color code calculator (colour code)
  • Resistor power rating calculator

Wiring

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.

PartPinConnect toNote
E3F sensorBrown / Blue12 V + / 12 V −
E3F sensorBlack (NPN output)Optocoupler pin 2 (cathode)Opto pin 1 (anode) to 12 V + through 1k
OptocouplerPin 4 collector / pin 3 emitterD2 / Nano GNDD2 uses INPUT_PULLUP
Slot moduleOUT / VCC / GNDD3 / 5V / GND
TM1637CLK / DIO / VCC / GNDD5 / D6 / 5V / GND
Toggle switchCommon / one sideD4 / GND
Relay moduleIN / VCC / GNDD7 / 5V / GND
  • E3F sensorBrown / Blue → 12 V + / 12 V −
  • E3F sensorBlack (NPN output) → Optocoupler pin 2 (cathode)Opto pin 1 (anode) to 12 V + through 1k
  • OptocouplerPin 4 collector / pin 3 emitter → D2 / Nano GNDD2 uses INPUT_PULLUP
  • Slot moduleOUT / VCC / GND → D3 / 5V / GND
  • TM1637CLK / DIO / VCC / GND → D5 / D6 / 5V / GND
  • Toggle switchCommon / one side → D4 / GND
  • Relay moduleIN / VCC / GND → D7 / 5V / GND
Built it? Check your wiring before you power up.Pick the pin each wire went to and we'll point out swapped pins, power mistakes and pins that clash.

Step-by-step build

0 of 6 done

Code

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();
  }
}

Run it: what this code does

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.

Troubleshooting

Count never changes+

Check the sensor's own LED lights when a box passes. If it does, check the opto wiring and that D2 reads LOW then.

One box counts twice+

Increase the 150 ms debounce or angle the sensor so it does not see gaps in the box.

RPM reads zero+

The slot module output goes LOW when the beam is blocked; check the disc really passes through the slot.

FAQ

Can I use a PNP sensor?+

Yes: connect its output to the opto anode through 1k and the opto cathode to 0 V.

Why not connect the sensor straight to the Nano?+

Its supply is 12 V. A wiring mistake would destroy the Nano; the optocoupler prevents that.

Can this stop the machine for safety?+

No. A counter is not a safety device. Use certified safety sensors and relays for guarding people.

What parts do I need to build the conveyor box counter with an industrial photoelectric sensor?+

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.

How hard is it and how long does it take?+

It is a intermediate project and takes about 2 to 3 hours. The build on this page has 6 steps.

Do I need to write the code myself?+

No. This page has the complete, tested code (box_counter.ino).

Can I see what the code does before I build it?+

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.

How much does the conveyor box counter with an industrial photoelectric sensor cost to build?+

About ₹13,66,326 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.

What will I learn from this project?+

Reading NPN industrial sensors through an optocoupler; Edge counting with debounce; Measuring speed with a slot sensor and slotted disc.

What can I build next with these parts?+

Ideas that reuse this build: RF 433 MHz remote relay. They are listed under Take it further on this page.

Take it further

  • RF 433 MHz remote relay

Related projects

  • UNO
    Sensor
    Beginner· 1 hour

    LPG gas leak alarm

    A kitchen gas sniffer that beeps and flashes the moment LPG levels climb.

    ₹505 · 8 partsArduino
  • NANO
    Sensor
    Beginner· 1–2 hours

    Smoke alarm with OLED readout

    See the smoke level live on a crisp screen and get a loud warning when it spikes.

    ₹539 · 6 partsArduino
  • UNO
    Sensor
    Beginner· 45 minutes

    Flame detector fire alarm

    An infrared eye that spots an open flame and raises the alarm.

    ₹434 · 8 partsArduino
  • UNO
    Sensor
    Beginner· 1 hour

    PIR intruder alarm

    Walk into the room and it sounds the alarm: the classic first security build.

    ₹459 · 8 partsArduino

Learning project. Check every circuit and the datasheet of each part before you power it up.

Run itChange the inputs and watch the output
0
Relay module IN / VCC / GND (D7) OFF
Serial monitor115200 baud
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.

Ask the Community

Ask a question Share your build