Soap Dispenser (NodeMcu)

From my collegue i recieved my first arduino compatible divice , a nodemcu . as i had a bit more time as we are in the midle of the covid-19 coronavirus outbreak i wanted to make something usefull with it.

I installed arduino IDE on my new Rasberry Pi 4 (with Rasbian). and loaded in the libraries

connected the usb en loaded the blink example for node mcu. this was quite easy and worked right away.

i ordered a small cheap pump that would pump the soap.

i also ordered a VL6180X , and connected this with on the (software) i2c pins on the node mcu :

  • SDA=4 => D2.
  • SCL=5 => D1

i created a little test circuit on a breadboard with an transistor and mosfet to switch the pump.

after this worked, i soldered this on a pinholeboard. and made some holes to also attach the node mcu and the sensor.

Final result with rituals soap

Arduino code:

#include <Wire.h>
#include "Adafruit_VL6180X.h"

Adafruit_VL6180X vl = Adafruit_VL6180X();

void setup() {
  pinMode(2, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
  pinMode(0, OUTPUT);     // Initialize the D3 as moter output...


  // wait for serial port to open on native usb devices
  while (!Serial) {
  Serial.println("Adafruit VL6180x test!");
  if (! vl.begin()) {
    Serial.println("Failed to find sensor");
    while (1);
  Serial.println("Sensor found!");

void loop() {
  float lux = vl.readLux(VL6180X_ALS_GAIN_5);

  //Serial.print("Lux: "); Serial.println(lux);
  uint8_t range = vl.readRange();
  uint8_t status = vl.readRangeStatus();

  if (status == VL6180X_ERROR_NONE) {
    Serial.print("Range: "); Serial.println(range);

  if (range <= 100){
    delay(5);//delay to activate to check false positives
    if (range <=100){
  digitalWrite(2, LOW);   // Turn the LED on (Note that LOW is the voltage level
  digitalWrite(0, HIGH);   // Turn the MOTER on
  // but actually the LED is on; this is because
  // it is active low on the ESP-01)
  delay(1100);                      // Wait for a second
  digitalWrite(2, HIGH);  // Turn the LED off by making the voltage HIGH
  digitalWrite(0, LOW);   // Turn the MOTER off
  delay(750);                      // Wait for two seconds (to demonstrate the active low LED)


  // Some error occurred, print it out!
  if  ((status >= VL6180X_ERROR_SYSERR_1) && (status <= VL6180X_ERROR_SYSERR_5)) {
    Serial.println("System error");
  else if (status == VL6180X_ERROR_ECEFAIL) {
    Serial.println("ECE failure");
  else if (status == VL6180X_ERROR_NOCONVERGE) {
    Serial.println("No convergence");
  else if (status == VL6180X_ERROR_RANGEIGNORE) {
    Serial.println("Ignoring range");
  else if (status == VL6180X_ERROR_SNR) {
    Serial.println("Signal/Noise error");
  else if (status == VL6180X_ERROR_RAWUFLOW) {
    Serial.println("Raw reading underflow");
  else if (status == VL6180X_ERROR_RAWOFLOW) {
    Serial.println("Raw reading overflow");
  else if (status == VL6180X_ERROR_RANGEUFLOW) {
    Serial.println("Range reading underflow");
  else if (status == VL6180X_ERROR_RANGEOFLOW) {
    Serial.println("Range reading overflow");

Leave a Reply

Your email address will not be published. Required fields are marked *