Touchless hand sanitiser dispenser
Hold your hand under it and a metal-gear servo presses the pump for you.
Shop by category
Shop all componentsJump straight to preset angles and compare that with relative moves, so the difference between absolute and relative positioning is obvious. Absolute positioning means go to 180 degrees, wherever you are now; relative means turn 180 degrees from here. Press Go four times on a 90 degree preset and the two modes end up somewhere completely different, absolute stays put after the first move, relative keeps going round. Seeing that side by side is the point of the experiment, because the same distinction governs CNC machines, plotters and robot arms.
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_104_stepper_motor_angle_preset.inoVerify & upload in Electrolark#include <Stepper.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define STEPS_PER_REV 2048
#define PRESETS 5
Stepper motor(STEPS_PER_REV, 33, 5, 32, 23);
Adafruit_SSD1306 display(128, 64, &Wire, -1);
int selectButton = 12;
int goButton = 14;
int modeButton = 27;
int presetAngle[PRESETS] = {0, 45, 90, 180, 270};
int preset = 0;
long position = 0; // In steps
bool absoluteMode = true;
int moves = 0;
long stepsFor(int degrees)
{
return (long)degrees * STEPS_PER_REV / 360;
}
float currentDegrees()
{
float d = position * 360.0 / STEPS_PER_REV;
while (d >= 360) d = d - 360;
while (d < 0) d = d + 360;
return d;
}
void go()
{
long target;
long movement;
if (absoluteMode)
{
// Nearest equivalent of the target angle
long fullTurns = position / STEPS_PER_REV;
target = fullTurns * STEPS_PER_REV + stepsFor(presetAngle[preset]);
movement = target - position;
// Take the shorter way round
if (movement > STEPS_PER_REV / 2) movement = movement - STEPS_PER_REV;
if (movement < -STEPS_PER_REV / 2) movement = movement + STEPS_PER_REV;
}
else
{
movement = stepsFor(presetAngle[preset]);
}
Serial.print(absoluteMode ? "Absolute" : "Relative");
Serial.print(" move of ");
Serial.print(movement);
Serial.println(" steps");
motor.step(movement);
position = position + movement;
moves = moves + 1;
}
void setup()
{
pinMode(selectButton, INPUT_PULLUP);
pinMode(goButton, INPUT_PULLUP);
pinMode(modeButton, INPUT_PULLUP);
motor.setSpeed(12);
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { while (true) { } }
display.setTextColor(SSD1306_WHITE);
display.setTextSize(1);
}
void loop()
{
if (digitalRead(selectButton) == LOW)
{
preset = (preset + 1) % PRESETS;
delay(300);
}
if (digitalRead(modeButton) == LOW)
{
absoluteMode = !absoluteMode;
Serial.println(absoluteMode ? "ABSOLUTE mode" : "RELATIVE mode");
delay(300);
}
if (digitalRead(goButton) == LOW)
{
go();
delay(300);
}
display.clearDisplay();
display.setCursor(0, 0);
display.print("PRESET SELECTOR");
display.setCursor(74, 0);
display.print(absoluteMode ? "ABSOLUTE" : "RELATIVE");
display.setTextSize(2);
display.setCursor(0, 12);
display.print(currentDegrees(), 0);
display.setTextSize(1);
display.print((char)247);
display.print(" now");
display.setCursor(0, 32);
display.print("Preset: ");
display.print(presetAngle[preset]);
display.print((char)247);
display.print(absoluteMode ? " (go to)" : " (turn by)");
// Preset row
for (int i = 0; i < PRESETS; i++)
{
int x = i * 25 + 2;
display.drawRect(x, 42, 22, 11, SSD1306_WHITE);
if (i == preset)
{
display.fillRect(x, 42, 22, 11, SSD1306_WHITE);
display.setTextColor(SSD1306_BLACK);
}
display.setCursor(x + 3, 44);
display.print(presetAngle[i]);
display.setTextColor(SSD1306_WHITE);
}
display.setCursor(0, 56);
display.print("Moves ");
display.print(moves);
display.print(" D4 = go");
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.
Absolute positioning means go to 180 degrees, wherever you are now; relative means turn 180 degrees from here. Press Go four times on a 90 degree preset and the two modes end up somewhere completely different, absolute stays put after the first move, relative keeps going round. Seeing that side by side is the point of the experiment, because the same distinction governs CNC machines, plotters and robot arms.
Select the 90° preset in absolute mode and press Go: the shaft moves to 90°. Press Go again and nothing happens, it is already there. Switch to relative mode and press Go repeatedly: it advances 90° each time.
Yes. It is project 104 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 intermediate project and takes about 1 hour. The build on this page has 7 steps.
No. This page has the complete, tested code (titan_kit_104_stepper_motor_angle_preset.ino).
About ₹1,429 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Absolute versus relative positioning; Choosing the shorter route to a target angle; Wrapping an angle into a 0–360 range; Converting between degrees and motor steps.
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.