Touchless hand sanitiser dispenser
Hold your hand under it and a metal-gear servo presses the pump for you.
Shop by category
Shop all componentsCount steps to keep track of absolute position, save named positions to EEPROM, and return to them exactly. A stepper has no position sensor, so the sketch must count. Every step command adds or subtracts one from a running total, and that total is the position, which is why the motor must never be turned by hand while powered off, and why the count is meaningless until it is homed. The 28BYJ-48 takes 2048 steps per revolution through its gearbox, so each step is about 0.176 degrees. Saving that count to EEPROM lets the position survive a power cut.
The ESP32 is a 3.3V board: never connect a 5V signal straight to a GPIO pin.
Charge 18650 cells only in a proper Li-ion charger and never short the holder's wires.
Every part for this build comes in the Geekobot Titan Kit box, a Geekobot exclusive, together with the parts for all 120 projects, from a first blinking LED to a smart fan and a reaction game. The wiring below is the kit's own wiring.
Tick anything you already have and the total updates.
ESP32 DevKit V1 (38-pin): the brain of every Titan Kit project, with Wi-Fi and Bluetooth
Male-to-female and female-to-female leads for the modules
28BYJ-48 stepper motor with its ULN2003 driver board
L298N board: its on-board regulator turns the 7.4V pack into 5V for the motor
ESP32 expansion board from the kit: every GPIO has its own S, V, G header
Follow the colours: red is power, dark grey is ground, blue is a signal.
The stepper's 5V comes from the L298N's on-board regulator, fed by the 2 x 18650 pack. The ESP32 only sends the four step signals.
titan_kit_103_stepper_motor_position_mem.inoVerify & upload in Electrolark#include <Stepper.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <EEPROM.h>
#define STEPS_PER_REV 2048
#define SLOTS 3
#define EEPROM_BASE 200
#define MAGIC 77
// Note the pin order for a 28BYJ-48 on a ULN2003 board
Stepper motor(STEPS_PER_REV, 33, 5, 32, 23);
Adafruit_SSD1306 display(128, 64, &Wire, -1);
int leftButton = 12;
int rightButton = 14;
int memoryButton = 27;
long position = 0;
long saved[SLOTS] = {0, 0, 0};
int slot = 0;
void saveToEEPROM()
{
EEPROM.update(EEPROM_BASE, MAGIC);
for (int i = 0; i < SLOTS; i++)
{
// A long needs four bytes
EEPROM.put(EEPROM_BASE + 1 + i * 4, saved[i]);
}
Serial.println("Positions written to EEPROM");
}
void loadFromEEPROM()
{
if (EEPROM.read(EEPROM_BASE) != MAGIC)
{
return;
}
for (int i = 0; i < SLOTS; i++)
{
EEPROM.get(EEPROM_BASE + 1 + i * 4, saved[i]);
}
Serial.println("Positions loaded from EEPROM");
}
void moveTo(long target)
{
long difference = target - position;
Serial.print("Moving ");
Serial.print(difference);
Serial.println(" steps");
motor.step(difference);
position = target;
}
float degrees_()
{
return position * 360.0 / STEPS_PER_REV;
}
void setup()
{
pinMode(leftButton, INPUT_PULLUP);
pinMode(rightButton, INPUT_PULLUP);
pinMode(memoryButton, INPUT_PULLUP);
motor.setSpeed(12); // RPM
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { while (true) { } }
display.setTextColor(SSD1306_WHITE);
display.setTextSize(1);
loadFromEEPROM();
}
void loop()
{
if (digitalRead(leftButton) == LOW)
{
motor.step(-16);
position = position - 16;
}
if (digitalRead(rightButton) == LOW)
{
motor.step(16);
position = position + 16;
}
if (digitalRead(memoryButton) == LOW)
{
unsigned long pressStart = millis();
while (digitalRead(memoryButton) == LOW)
{
delay(10);
}
if (millis() - pressStart > 800)
{
// Long press saves the current position
saved[slot] = position;
saveToEEPROM();
}
else
{
// Short press recalls, then advances the slot
moveTo(saved[slot]);
slot = (slot + 1) % SLOTS;
}
}
display.clearDisplay();
display.setCursor(0, 0);
display.print("POSITION MEMORY");
display.setTextSize(2);
display.setCursor(0, 12);
display.print(degrees_(), 1);
display.setTextSize(1);
display.print((char)247);
display.setCursor(78, 18);
display.print(position);
display.print(" st");
display.drawLine(0, 32, 127, 32, SSD1306_WHITE);
for (int i = 0; i < SLOTS; i++)
{
display.setCursor(0, 36 + i * 9);
display.print(i == slot ? ">" : " ");
display.print(" Slot ");
display.print(i + 1);
display.print(": ");
display.print(saved[i] * 360.0 / STEPS_PER_REV, 1);
display.print((char)247);
}
display.display();
delay(20);
}
Use a micro-USB data cable (some cables only charge), install the CP210x or CH340 driver if no port appears, pick Tools > Board > ESP32 Dev Module and hold the BOOT button on the board until the upload starts.
The sketch uses INPUT_PULLUP, so one leg goes to the GPIO and the other to GND. Use two legs on opposite sides of the button.
Check SDA on GPIO21 and SCL on GPIO22, power from 3V3, and that the sketch uses address 0x3C (some boards are 0x3D).
Check the four IN wires are in order, the white plug is pushed fully in, and the battery holder is switched on.
A stepper has no position sensor, so the sketch must count. Every step command adds or subtracts one from a running total, and that total is the position, which is why the motor must never be turned by hand while powered off, and why the count is meaningless until it is homed. The 28BYJ-48 takes 2048 steps per revolution through its gearbox, so each step is about 0.176 degrees. Saving that count to EEPROM lets the position survive a power cut.
Hold the first button or the second button and the motor jogs, with the angle counting up or down. Hold the third button for a second to save the current position into the highlighted slot. Tap the third button to drive straight back to the saved position.
Yes. It is project 103 of 120 in the Geekobot Titan Kit, in level 15 (Actuators). Every part on the list comes in the kit box, and you can also buy the parts one by one from the list above.
No. Every Titan Kit project is wired on the ESP32 expansion board and the breadboard with jumper wires.
11 parts: ESP32-WROOM-32 38-Pin Development Board, USB Cable, Solderless Breadboard, Dupont Jumper Wires (40 pcs), 3 × Tactile Push Button Switch, 0.96" OLED Display 128x64, 28BYJ-48 Stepper Motor & ULN2003 Driver Kit, L298N Dual H-Bridge Motor Driver Module, ESP32 38-Pin Expansion Board, 18650 Battery Holder, plus 1 more. On this page you can tick the parts you already have and add only the rest to your cart.
It is a advanced project and takes about 1 hour. The build on this page has 7 steps.
No. This page has the complete, tested code (titan_kit_103_stepper_motor_position_mem.ino).
About ₹1,429 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Step counting for absolute position; State saving to EEPROM with put() and get(); Long press and short press from one button; Why an open-loop motor must never be moved by hand.
The ESP32 is a 3.3V board: never connect a 5V signal straight to a GPIO pin. Charge 18650 cells only in a proper Li-ion charger and never short the holder's wires.
Hold your hand under it and a metal-gear servo presses the pump for you.
Wave your hand and the lid lifts by itself, then closes after three seconds.
Your first motion project: turn the knob and the servo follows.
Dial in an exact servo angle, 2° per click, shown on screen.
Lessons are free to read. Maker (₹499/month) and Pro add quizzes, worked problems and certificates, paid with your Geekobot account. See plans
Learning project. Check every circuit and the datasheet of each part before you power it up.