How to Build a Touch Dispenser for Liquid Soap from Xiaomi: A Detailed Guide to Schemes

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):

ComponentModel/characteristicsApproximate price, β‚½Where to buy
MicrocontrollerESP8266 (NodeMCU or ESP32300–500AliExpress, Chip and Deep
IR sensorTCRT5000 (analogue E18-D80NK (digital)80–200AliExpress, Amperka
PumpDC 3V, consumption 0.3-1 ml / s, food silicone tube250–400AliExpress, Ozon
Power supply5V/2A s USB-plug-in150–300Any electronics store
Corpsfinished container or 3D-model for printing (for example, this version)0–500Thingiverse, 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).

πŸ“Š What type of dispenser do you plan to collect?
Based on original Xiaomi spare parts
Universal Assembly with Arduino
Hybrid variant (Pump Xiaomi) + homemade electronics)
Not yet.

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?
GPIO-The microcontroller port can withstand current up to 20 mA, and the pump consumes 100-300 mA. A direct connection will burn the port or the entire chip, IRLZ44N) or relay as a β€œmediator".

After soldering, check the scheme with a multimeter:

  1. Set the diode (or resistance) check mode.
  2. Call the chain from VCC sensor 3.3V On the board - the resistance should be close to 0.
  3. 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:

  1. Ready-made firmware, such as Soapy Dispenser for ESPHome, supports integration with Home Assistant, soap setup (0.5-2 ml) and sensor timeout.
  2. 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:

  1. Install the Arduino IDE library ESP8266 (via the board manager).
  2. Select the NodeMCU 1.0 board from the Tools menu β†’ Payment.
  3. 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:

  1. Pour water into the tank (not soap!) and place a measuring glass under the pump.
  2. Run the dispenser 10 times, measuring the volume of liquid in one press.
  3. 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:

ModelFeaturesReference
Xiaomi Soap Dispenser CloneClone of the original Viomi case, with mounts under the pumpThingiverse
Modular DispenserRemovable top cover, electronics compartmentsCults3D
Wall-Mounted DispenserWall version with a mount on double-sided scotchPrusaPrinters

⚠️ 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:

  1. Sweep ESP8266/ESP32 supportive MQTT (For example, through ESPHome or Tasmota).
  2. Set up integration with Home Assistant or IoT Mi cloud service.
  3. 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).
What to do if the pump is humming but not pumping?
This is a sign of air in the system or a tube clogging. disconnect the tube from the pump, lower it into the water and turn the pump on for 2-3 seconds to blow the air. If it does not work, rinse the tube and pump with warm water (no soap!).

FAQ: Answers to Frequent Questions

Can I use a shower gel dispenser or shampoo?
Yes, but you have to consider the viscosity of the liquid. For thick gels (like Dove or Nivea), you need a pump with more power (DC 5V, expense β‰₯1.5 You may also need a larger tube diameter (4Γ—6 Before use, test the dispenser in water, then gradually add the gel, diluting it to avoid blockages.
How to make the dispenser wireless (on batteries)?
For power from batteries suitable scheme with ESP32 Deep sleep, sleep consumption, sleep consumption β€” ~5 MCA, which will allow you to work from 3Γ—AA battery-to-battery 6 Example of code for deep sleep: #include <esp_sleep.h> void setup() { // Your initialization code esp_sleep_enable_timer_wakeup(1000000 60 5); // Awakening every time 5 minutes (for the test) esp_deep_sleep_start(); } void loop() {} // Not used to wake up by movement, use an IR sensor interrupt: esp_sleep_enable_ext0_wakeup(GPIO_NUM_XX, LOW);.
Where to buy spare parts for the original dispenser Xiaomi Viomi?
Original parts (pump, sensor, body) can be found: πŸ›’ AliExpress – search for Viomi soap dispenser pump or Xiaomi V-SD01 sensor. πŸ›’ Mercado Libre (for Latin America). πŸ›’ Groups in Telegram, for example, @xiaomi_repair or @mi_fans_rus. The cost of the pump β€” ~500–800 β‚½, sensor β€” ~300 β‚½. When buying, check compatibility with your model (V-SD01 or V-SD02).
How to calibrate the dispenser for baby soap (small portions)?
For servings of 0.3–0.5 ml: Use a pump with a flow rate of 0.2–0.3 ml/sec (e.g, DC 3V Micro pump with AliExpress. Reduce the delay in the code to 100-200 ms. Add a minimum interval check (3-5 seconds) to the code to avoid overflow. Use a 1 ml syringe to test, so it is easier to measure small volumes.
Can I connect the dispenser to a smart home system without Wi-Fi?
Yeah, there are a few options: πŸ“‘ Zigbee - Use the module CC2530 or ESP32 The dispenser will work through the Xiaomi Gateway. πŸ“‘ RF 433 MHz is a cheap solution, but less reliable. XY-MK-5V. πŸ“‘ Bluetooth is firmware ESP32 s BLE This will allow you to control the dispenser from your smartphone (nRF Connect app). For Zigbee, an example of code: Koenkkk repository.