Fareed Mohmed← Project library

Engineering · Raspberry Pi · Project 46 of 47 · Industrial automation · Intermediate

Bottle filling station

A beam sensor sees a bottle under the nozzle. The pump fills it for 3 seconds. A bar of LEDs counts filled bottles for each box of five.

▶ Open in the simulator

Raspberry Pi simulator drawing of the circuit for Bottle filling station: the board, its power supply and the parts wired to the 40-pin header
CAUTION: 230 V single-phase mains. The relay in this project switches a mains load (Live and Neutral, 230 V AC, 50 Hz in India). Mains can kill. Practise with the simulator or a low-voltage lamp. Build the mains side only with a qualified electrician, in a closed insulated box, behind a fuse or MCB and a 30 mA RCCB. Never touch the relay screw terminals while anything is connected.
Machine safety. This project only shows signalling and logic. A real emergency stop must cut power through hard-wired safety-rated contacts and relays and must never depend on software or a Raspberry Pi.

Parts in this circuit

PartType
Bottle sensorBeam sensor
Filling pumpRelay module
Box of 5LED bar
Box full hornBuzzer

Wiring, pin by pin

Red = 5 V, orange = 3.3 V, black = GND, other colours = signals. “Pin” is the position on the 40-pin header; the GPIO number is what the code uses. Power the Pi from a 5.1 V supply and wire with the power off.

#ColourFrom (part and leg)To (header pin)
1RedBottle sensor - VCCPin 2 (5V)
2ColouredBottle sensor - OUTPin 11 (GPIO17)
3BlackBottle sensor - GNDPin 6 (GND)
4ColouredFilling pump - INPin 15 (GPIO22)
5BlackFilling pump - GNDPin 9 (GND)
6RedFilling pump - VCCPin 4 (5V)
7ColouredBox of 5 - SignalPin 29 (GPIO5)
8ColouredBox of 5 - SignalPin 31 (GPIO6)
9ColouredBox of 5 - SignalPin 33 (GPIO13)
10ColouredBox of 5 - SignalPin 35 (GPIO19)
11ColouredBox of 5 - SignalPin 37 (GPIO26)
12BlackBox of 5 - GNDPin 14 (GND)
13ColouredBox full horn - +Pin 12 (GPIO18)
14BlackBox full horn - -Pin 20 (GND)

Python code (gpiozero)

from gpiozero import Button, OutputDevice, LEDBarGraph, Buzzer
from time import sleep

bottle = Button(17)                           # beam broken = bottle in place
pump = OutputDevice(22, active_high=False)
box = LEDBarGraph(5, 6, 13, 19, 26)
horn = Buzzer(18)

FILL_TIME = 3
BOX_SIZE = 5
filled = 0

print("Click the beam sensor to place a bottle")
while True:
    bottle.wait_for_press()
    print("Bottle detected: filling")
    pump.on()
    sleep(FILL_TIME)
    pump.off()
    filled += 1
    in_box = filled % BOX_SIZE
    print("Bottle", filled, "filled")
    if in_box == 0:
        box.value = 1
        horn.beep(0.2, 0.1, n=3)
        print("BOX FULL: replace the box")
        sleep(2)
        box.value = 0
    else:
        box.value = in_box / BOX_SIZE

How the code works

You will learn

  • A timed process step
  • Counting items and batches
  • Using a beam sensor to start a cycle

Try this

  • Click the beam sensor 5 times, 3.5 seconds apart.
  • Click again while the pump is running. What happens?
  • Add a stop button that switches the pump off at once.

On a real Pi

  • A filling pump is a liquid pump. Keep the liquid, the Pi and all mains wiring apart and use a splash-proof box.
  • Real fillers use a flow meter or a load cell, not only a timer. Time-based filling changes with the liquid level and the pump wear.
  • Add a bottle-present check during filling, and stop the pump if the bottle is removed.

Parts to buy

The links open a search on each store, so you see what is in stock today. Check the model, voltage and price before you order.

#ItemQtyBuy / compare
1Raspberry Pi 4 Model B
about 4000 to 9000 INR
1Robu.in Amazon.in ThinkRobotics
2Official 15 W USB-C power supply (5.1 V, 3 A)
Do not use an old phone charger
1Robu.in Amazon.in ThinkRobotics
3microSD card 32 GB, class 10 / A1 (with Raspberry Pi OS)
And a card reader to write it
1Robu.in Amazon.in ThinkRobotics
4330 ohm resistor, 1/4 W
One per LED
5Robu.in Amazon.in ThinkRobotics
5LED bar graph module (5 LEDs)1Robu.in Amazon.in ThinkRobotics
6Active buzzer, 5 V1Robu.in Amazon.in ThinkRobotics
71-channel 5 V relay module with optocoupler
10 A 250 V AC contacts
1Robu.in Amazon.in ThinkRobotics
8230 V AC small water pump
Needs a proper starter and an RCCB
1Robu.in Amazon.in ThinkRobotics
9Closed ABS enclosure (IP54) for the mains side1Robu.in Amazon.in ThinkRobotics
103-way screw terminal block (rated 10 A)1Robu.in Amazon.in ThinkRobotics
11MCB 6 A single pole and RCCB 30 mA (by an electrician)
Mains protection
1Robu.in Amazon.in ThinkRobotics
12IR beam / break-beam sensor pair (3.3 V compatible)1Robu.in Amazon.in ThinkRobotics
13Dupont jumper wires, male-to-female, 20 cm (pack of 40)1Robu.in Amazon.in ThinkRobotics
14Breadboard 830 points
For resistors and shared GND / 5 V
1Robu.in Amazon.in ThinkRobotics
← 45. Two-hand press controlAll projects47. Light-curtain safety interlock →

This is a learning tool. The simulator checks the program logic, not the electrical design. Never put more than 3.3 V on a GPIO pin.