Automatic dispensers of liquid soap from Xiaomi have long become a popular accessory for the bathroom and kitchen, but their factory cost often makes you think about self-assembly. If you want to get a smart device with an infrared sensor, adjustable portion size and integration into the Mi Home ecosystem, it is quite possible to do it yourself. In this article, we will discuss two build options: based on the original parts from Xiaomi Viomi. V-SD01 or V-SD02) and using universal components (e.g., Arduino) + IR sensor).
The main advantage of a homemade dispenser is customization, from sensor sensitivity to body design. But there are pitfalls: improperly connecting the pump can lead to leaks, and firmware errors can lead to unstable work. We will discuss in detail at each step, including the selection of components, soldering circuitry, setting up firmware and even integration with voice assistants (Alice, Google Assistant). For beginners, we will give a simplified scheme without soldering, using ready-made modules.
Important: if you plan to use the dispenser in public places (office, cafe), consider the requirements for hygiene - some parts (for example, silicone tubes) must be food grade and resistant to aggressive detergents. FAQ answers to typical problems (for example, why the dispenser spits with soap or does not respond to the hand).
1. Selection of components: what to buy for assembly
Before buying, determine the type of dispenser:
- πΉ Based on original Xiaomi parts - suitable if you already have a faulty dispenser (for example, a burnt pump) or you found parts on AliExpress. TCRT5000, microcontroller ESP8266 (or ESP32 for Wi-Fi, pump DC 3V 0.5-1 ml/sec.
- πΉ Universal assembly is cheaper, but it requires more skill. E18-D80NK, pump relay, power supply 5V/2A and 3D-sealing of the case (or finished container from the IKEA).
- πΉ The hybrid variant is a combination of the original Xiaomi pump with homemade electronics. Optimal if you want reliability of the factory mechanism, but you want to add features (for example, backlight or display).
Minimum set to start (prices are valid for 2026):
| Component | Model/characteristics | Approximate price, β½ | Where to buy |
|---|---|---|---|
| Microcontroller | ESP8266 (NodeMCU or ESP32 | 300β500 | AliExpress, Chip and Deep |
| IR sensor | TCRT5000 (analogue E18-D80NK (digital) | 80β200 | AliExpress, Amperka |
| Pump | DC 3V, consumption 0.3-1 ml / s, food silicone tube | 250β400 | AliExpress, Ozon |
| Power supply | 5V/2A s USB-plug-in | 150β300 | Any electronics store |
| Corps | finished container or 3D-model for printing (for example, this version) | 0β500 | Thingiverse, IKEA |
β οΈ Warning: If you take a pump from an old Xiaomi dispenser, check it for leakproofness. A common problem is the wear of the membrane after 1-2 years of use. 3V and lower the tube into the water: if the liquid does not enter or is jerking, the membrane must be replaced (article) Viomi-007).
Connection scheme: soldering and testing
Letβs look at the diagram for option C. ESP8266 pump DC 3V. It is suitable for most homemade dispensers and allows you to add Wi-Fi to control over Mi Home.
Basic compounds:
- π IR sensor TCRT5000: VCC β 3.3V on ESP8266 GND β GND OUT β anyone GPIO (for example, D5)
- π Pump DC 3V: + β VIN (transistor IRLZ44N relay) β β GND
- π Nutrition: 5V from USB on VIN ESP8266 (The built-in stabilizer will lower to 3.3V).
To protect against back current, add a diode. 1N4007 The.fzz (Fritzing) circuit is available here.
Why you canβt connect the pump directly to GPIO?
After soldering, check the scheme with a multimeter:
- Set the diode (or resistance) check mode.
- Call the chain from VCC sensor 3.3V On the board - the resistance should be close to 0.
- Check if there is a short circuit between VCC and GND.
Call all connections with a multimeter|Make sure the polarity of the pump is correct|Supply power without a connected pump (smoke test check)|Check the sensor's response to the hand (the LED should light up)
-->
3. Microcontroller firmware: ready-made firmware and setup
For firmware ESP8266/ESP32 There are two options:
- Ready-made firmware, such as Soapy Dispenser for ESPHome, supports integration with Home Assistant, soap setup (0.5-2 ml) and sensor timeout.
- Self-code β if you need unique features (e.g. backlighting) RGB Or a sound alert. Below is a basic sketch for the Arduino. IDE.
Minimum code for testing (responsive to the sensor and switches on the pump for 0.5 seconds):
#include <Arduino.h>
const int sensorPin = D5; // Pin IR sensor
const int pumpPin = D6; // Pin pump (via transistor!)
void setup() {
pinMode(sensorPin, INPUT);
pinMode(pumpPin, OUTPUT);
digitalWrite(pumpPin, LOW); // Pump is switched off at start
}
void loop() {
if (digitalRead(sensorPin) ==LOW) {// The sensor is triggered at LOW (object detected)
digitalWrite(pumpPin, HIGH); // Turn on the pump
delay(500); // Works 0.5 seconds (adjust to your pump!)
digitalWrite(pumpPin, LOW);
delay(2000); // Re-activation protection
}
}To load the code in ESP8266:
- Install the Arduino IDE library ESP8266 (via the board manager).
- Select the NodeMCU 1.0 board from the Tools menu β Payment.
- Connect. ESP computer-to-computer USB And upload the sketch.
π‘
If the dispenser is triggered too often, add a time check between activations to the code. For example, use the variable unsigned long lastTrigger. = 0; and compare with millis() to block re-activations for 3-5 seconds.
Calibration of the sensor and pump: how to avoid leaks
The most common problem with homemade dispensers is the uncontrolled leakage of soap.
- π§ Pump pulse is too long (you need to reduce the delay in the code).
- π§ Wear of the return valve in the pump (replace the membrane or the entire pump).
- π§ Incorrect angle of installation of the IR sensor (should be perpendicular to the palm of the hand).
For calibration:
- Pour water into the tank (not soap!) and place a measuring glass under the pump.
- Run the dispenser 10 times, measuring the volume of liquid in one press.
- Adjust the pump's operating time in the code. Formula: delay(ms) = (desired volume in ml) / (pump consumption in ml/sec) * 1000.
Example: If your pump is giving out 0.8 ml/sec, and you need to 1 If you are a portion, the delay should be 1250 miss (1 / 0.8 * 1000 = 1250).
π‘
For accurate calibration, use distilled water - soap solutions can foam and distort volume measurements.
β οΈ Attention: If the dispenser still spits soap after calibration, check the tightness of the pipe connection to the pump. Often the problem lies in the microcracks of the silicone tube - replace it with a new one (diameter). 3Γ5 mm, food silicone).
5. Assembly of the body: design and sealing
The dispenser body shall be:
- π‘οΈ Wet-resistant, acrylic will do, ABS-plastics (for 3D-seal) or a sealed container from IKEA (for example, 365+).
- π³οΈ With an IR sensor hole - a diameter of 8-10 mm, the height of the installation is 15-20 mm from the bottom (so that the sensor does not react to random movements).
- π With a separate soap filling hatch - this makes maintenance easier.
If you print the case on 3D-printer, use these settings:
- Materials: PETG (more waterproof than PLA).
- Wall thickness: 2-3 mm.
- Filling: 20β30% (for strength).
- Post-treatment: Treat the seams with acetone or Moment Crystal sealant.
Ready. 3D-case-model:
| Model | Features | Reference |
|---|---|---|
| Xiaomi Soap Dispenser Clone | Clone of the original Viomi case, with mounts under the pump | Thingiverse |
| Modular Dispenser | Removable top cover, electronics compartments | Cults3D |
| Wall-Mounted Dispenser | Wall version with a mount on double-sided scotch | PrusaPrinters |
β οΈ Warning: When you install an IR sensor in the body, avoid direct sunlight on the lens, which will cause false positives. Use a light-shielding visor (you can cut out of black plastic).
6.Integration with Mi Home and voice assistants
To control the dispenser through the Mi Home app or voice (Alice, Google Assistant), you need to:
- Sweep ESP8266/ESP32 supportive MQTT (For example, through ESPHome or Tasmota).
- Set up integration with Home Assistant or IoT Mi cloud service.
- Add the device to Mi Home by Manually Add β Others.
Example configuration for ESPHome (Yaml file):
esphome:
name: xiaomi_soap_dispenser
platform: ESP8266
board: nodemcu
wifi:
ssid: "Your WiFi"
password: "password"
mqtt:
broker: "192.168.1.100" # Address of your MQTT- broker (e.g. Home Assistant)
binary_sensor:
- platform: gpio
pin: D5
name: "IR Sensor"
device_class: motion
output:
- platform: gpio
pin: D6
id: pump_relay
switch:
- platform: output
name: "Soap Pump"
output: pump_relay
icon: "mdi:pump"After downloading this configuration in ESP8266 The dispenser will appear in the Home Assistant as two devices:
- π‘ Motion sensor (IR sensor).
- π¦ Switch (pump).
To integrate with Alice, use the Smart Home skill in the Yandex app and add Home Assistant as a bridge.
- "Alice, turn on the soap dispenser," he'll serve a portion.
- "Alice, how much soap is left? β if you add a level sensor (for example, the level sensor, HC-SR04).
Typical problems and their solutions
Even after proper assembly, the dispenser can be unstable.
Problem 1: The dispenser does not respond to the arm.
- π Check the connection of the IR sensor (call the multimeter).
- π Make sure the sensor is being fed 3.3V, not 5V (burnable!).
- π Adjust the sensitivity of the sensor with a adjusting resistor (if it is on the module).
Problem 2: The soap is self-evident.
- π§ Check the pump's return valve - it should block the backflow fluid current.
- π§ Reduce the pump time in the code (start with delay(300)).
- π§ Make sure the tube is not clamped and has no cracks.
Problem 3: The meter is working too often.
- β±οΈ Add a delay between activations (e.g. if (millis() - lastTrigger) to the code. < 3000) return;).
- β±οΈ Check if the sensor is not getting any foreign light (for example, from a lamp).