dlpashkow
Published © CC BY-NC

Arduino Hand Wash Timer

This timer operates completely hands free and provides an accurate amount of time needed to wash your hands.

IntermediateFull instructions provided250
Arduino Hand Wash Timer

Things used in this project

Hardware components

Alphanumeric LCD, 16 x 2
Alphanumeric LCD, 16 x 2
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
170 Point Breadboard
×1
Arduino Pro Micro
×1
SparkFun Passive Buzzer
×1

Software apps and online services

Arduino IDE
Arduino IDE
Ultimaker Cura

Story

Read more

Schematics

Arduino Hand Wash Timer Schematic

My schematic of the hand wash timer.

Code

Hand Wash Timer Code

Arduino
Code to run this hand wash timer, with as many comments as I thought were necessary.
/*Code written by Danny Pashkow
Created May 2020*/

#include <LiquidCrystal.h>
#include "pitches.h"

bool isHand = false;

#define screenPower 7 //define screen power pin (to automatically turn lcd backlight on and off)

// defines HC-SR04 pin numbers
const int trigPin = 9;
const int echoPin = 10;

//variables for HC-SR04
long duration; 
int distance;
 
// Create an LCD object. Parameters: (RS, E, D4, D5, D6, D7):
LiquidCrystal lcd = LiquidCrystal(14, 16, 5, 4, 3, 2);

int timeLeft = 20; //variable for displaying time left

int toneDuration = 100;
int tickDuration = 50;

//array of notes for done tone
int doneTone[] = {
  NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5
};

//this was supposed to be notes for the tick but it makes more of a clicking sound (for some reason) which I thought sounded better
int tick[] = {
  NOTE_E4, NOTE_F4
};

void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  Serial.begin(9600); // Starts the serial communication
  
  //Setup LCD rows and columns:
  pinMode(screenPower, OUTPUT);
  digitalWrite(screenPower, HIGH);
  delay(200);
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("Hand Wash Timer");
  lcd.setCursor(0, 1);
  lcd.print("By:Danny Pashkow");
  delay(3000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Hand Wash Timer");
  lcd.setCursor(0, 1);
  lcd.print("No Hand Detected");
  digitalWrite(screenPower, LOW);
}
void loop() {
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2;
  // Prints the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.println(distance);
  delay(1000);

  if (distance < 35) {
    digitalWrite(screenPower, HIGH); //light up backlight
  }
  else if (isHand != true) {
    digitalWrite(screenPower, LOW); //no backlight
  }

  if (distance < 10) {
    Serial.println("Hand detected");
    isHand = true;
  }

  if (isHand == true) {
    handDetected();
  }

  if (timeLeft < 0) {
    noTimeLeft();
  }
}

void noTimeLeft() {
  lcd.clear();
  lcd.setCursor(6, 0);
  lcd.print("Done!");
  for (int thisNote = 0; thisNote < 8; thisNote++) {
    tone(8, doneTone[thisNote], toneDuration);
    delay(100);
  }
  delay(5000);
  lcd.clear();
  timeLeft = 20;
  isHand = false;
  delay(5000);
  lcd.setCursor(0, 0);
  digitalWrite(screenPower, LOW);
  lcd.print("Hand Wash Timer");
  lcd.setCursor(0, 1);
  lcd.print("No Hand Detected");
}

void handDetected() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Time Remaining: ");
  lcd.setCursor(0, 1);
  lcd.print(timeLeft);
  lcd.print(" seconds");
  timeLeft -= 1;
  for (int thisTick = 0; thisTick < 3; thisTick++) {
    tone(8, tick[thisTick], tickDuration);
  }
}

Pitches.h library

C/C++
Save this code as "pitches.h" without quotations (make sure to change the file extension to .h) and put into a zip file. From there, you can import this library like any other library.
/*************************************************
 * Public Constants
 *************************************************/

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978

Credits

dlpashkow

dlpashkow

0 projects • 0 followers

Comments