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 provided2,790
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
SparkFun Passive Buzzer
×1
Arduino Nano R3
Arduino Nano R3
×1

Software apps and online services

Arduino IDE
Arduino IDE
Ultimaker Cura

Story

Read more

Schematics

Hand Wash Timer Schematic

Code

Hand Wash Timer Code

Arduino
Code to run this project, with as many comments as I thought were necessary.
/*Code written by Danny Pashkow
Updated November 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(13, 12, 5, 4, 3, 2);

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

int speakerPin = 11;

int toneDuration = 100;
int tickDuration = 25;

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

//note of the ticking sound
int tick[] = {
  NOTE_C5
};

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);
  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);

  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(11, doneTone[thisNote], toneDuration);
    delay(100);
  }
  delay(5000);
  lcd.clear();
  digitalWrite(screenPower, LOW);
  timeLeft = 20;
  isHand = false;
  lcd.setCursor(0, 0);
}

void handDetected() {
  digitalWrite(screenPower, HIGH);
  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(speakerPin, tick[thisTick], tickDuration);
  }
  delay(1000);
}

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 • 1 follower

Comments