Introduction
We should wash our hands🖐 with soap for at least 20 seconds. With this Non-Contact Hand Washing Timer, you can wash your hands with colorful LEDs without counting the numbers. Just clap 👏🏼 your hand and the count down⏱ will start.
Video
Watch this video for more info on how to make a non-contact hand washing timer using Maker UNO.
This is the hardware connection and the components needed.
Sample Code
#include <Adafruit_NeoPixel.h> | |
#ifdef __AVR__ | |
#include <avr/power.h> | |
#endif | |
#define LED_RING 5 | |
#define SENSOR 6 | |
#define PIEZO 8 | |
#define NUMPIXELS 12 // NeoPixel ring size | |
Adafruit_NeoPixel pixels(NUMPIXELS, LED_RING, NEO_GRB + NEO_KHZ800); | |
#define NOTE_B5 988 | |
int startNoteDurations[] = {8,4,4}; | |
int stopMelody[] = {NOTE_B5}; | |
int stopNoteDurations[] = {8}; | |
#define playstopMelody() playMelody(stopMelody, stopNoteDurations, 2) | |
char inChar; | |
String inString; | |
void setup() { | |
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) | |
clock_prescale_set(clock_div_1); | |
#endif | |
pinMode(SENSOR, INPUT); | |
pinMode(PIEZO, OUTPUT); | |
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) | |
Serial.begin(9600); | |
} | |
void loop() { | |
pixels.clear(); // Set all pixel colors to 'off' | |
pixels.show(); // Send the updated pixel colors to the hardware. | |
if (digitalRead(SENSOR) == HIGH) { | |
for (int i = NUMPIXELS; i >= 0; i–) { | |
pixels.setPixelColor(i, pixels.Color(100, 5, 5)); | |
pixels.show(); | |
delay(250); // Pause before next pass through loop | |
} | |
for (int i = 0; i < NUMPIXELS; i++) { | |
Serial.print("i = "); | |
Serial.println(i); | |
pixels.setPixelColor(i, pixels.Color(10, 100, 10)); | |
pixels.show(); | |
delay(1700); | |
} | |
blinking(3); | |
} | |
else { | |
pixels.clear(); | |
pixels.show(); | |
} | |
} | |
void blinking(int times) | |
{ | |
for (int i = 0; i < times; i++) { | |
pixels.clear(); | |
pixels.show(); | |
delay(200); | |
for (int i = 0; i < 12; i++) { | |
pixels.setPixelColor(i, pixels.Color(5, 100, 5)); | |
pixels.show(); | |
} | |
delay(200); | |
playstopMelody(); | |
} | |
} | |
void playMelody(int *melody, int *noteDurations, int notesLength) | |
{ | |
for (int thisNote = 0; thisNote < notesLength; thisNote++) { | |
int noteDuration = 1000 / noteDurations[thisNote]; | |
tone(PIEZO, melody[thisNote], noteDuration); | |
int pauseBetweenNotes = noteDuration * 1.30; | |
delay(pauseBetweenNotes); | |
noTone(PIEZO); | |
} | |
} |
Reference
Adafruit No-Touch Hand Washing Timer.
Thank you
Thank you for reading this tutorial and we hope it helps your project development. If you have any technical inquiries, please post at Cytron Technical Forum.
1 thought on “Non-Contact Hand Washing Timer Using Maker UNO”
Hi
Ada sample code yang menggunakan Microbit?