rjconcepcion
Published © CC BY

Touchless Washing Hands Timer

Health authorities recommend washing your hand for at least 20 seconds. This device monitors the time while you washing your hands.

IntermediateProtip3 hours8,748
Touchless Washing Hands Timer

Things used in this project

Hardware components

Arduino Uno R3
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Shift Register- Serial to Parallel
Texas Instruments Shift Register- Serial to Parallel
×1
7 Segment Display
×2
2N3904 Transistor
×2
Buzzer
×1
Resistor 1k ohm
Resistor 1k ohm
×2
Resistor 330 ohm
Resistor 330 ohm
×2
Resistor 220 ohm
Resistor 220 ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Breadboard, 400 Pin
Breadboard, 400 Pin

Story

Read more

Schematics

Schematic

Code

Touchless washing hands timer code

Arduino
// Touchless washing hands timer

// Info library NewPing https://playground.arduino.cc/Code/NewPing/

#include <NewPing.h> // Library for sensor HC-SR04


const int trigger = 2;  // D2 trigger Pin
const int echo = 3;     // D3 echo Pin
const int max_dist = 200; // max distance 200 cm
const int led = 13;       // Build-in led
const int sonido = 12;    // Buzzer pin

//D9 to pin 12 latch (RCLK) 74HC595 
const int latchPin = 9;
//D10 to Pin 11 Clock (SRCLK) 74HC595 
const int clockPin = 10;
//D8 to Pin 14 Data (SER) 74HC595
const int dataPin = 8;

const int tdigt1 = 4; // Transistor digit 1
const int tdigt2 = 5; // Transistor digit 2

//7Segment display configuration
const byte CHAR_COUNT = 11;
const byte symbols[CHAR_COUNT] = {
//GFEDCBAd
 B01111110, // 0
 B00001100, // 1
 B10110110, // 2 
 B10011110, // 3
 B11001100, // 4 
 B11011010, // 5
 B11111010, // 6 
 B00001110, // 7
 B11111110, // 8 
 B11011110, // 9
 B10000000,  // -
    
};

int dist = 0;   // Distance variable
int var = 20;  // Time varible. You can change this value.

int digt1 = 0;  // Var digit 1
int digt2 = 0;  // Var digit 2


NewPing sonar(trigger, echo, max_dist); // NewPing constructor 

void setup() {
  Serial.begin(9600);   // Set serial communication speed

  pinMode(led, OUTPUT);       // Led pin as output
  pinMode(sonido, OUTPUT);    // Sound pin as output
  pinMode(latchPin, OUTPUT);  // lachtPin as output
  pinMode(dataPin, OUTPUT);   // dataPin as output
  pinMode(clockPin, OUTPUT);  // clockPin as output
  pinMode(tdigt1, OUTPUT);    // tdigit1 as output
  pinMode(tdigt2, OUTPUT);    // tdigit2 as output
  
}

void loop() {
  delay(50);
  dist = sonar.ping_cm(); // Get the distance. 
  Serial.print(dist);     // Print distance in serial monitor.
  Serial.println("cm");
  delay(500);             


  // Start this cycle if the distance is less than 5 cm
  if ((dist <= 5) & (dist > 0)) {
    digitalWrite(led, HIGH); 
    beep(200);                      // Make a sound

    while (var > 0){                // While cycle for counter 

    digt1 = var % 10;               // Get the remainder
    digt2 = var / 10;              //  Get first digit
      
    for (int i=0; i<50; i++) {      // Show every digit 10 ms.
    digitalWrite(tdigt1, HIGH);
    writeLeds(symbols[digt1]);      // Write symbols in the displays.
    delay(10);
    digitalWrite(tdigt1, LOW);

    digitalWrite(tdigt2, HIGH);
    writeLeds(symbols[digt2]);
    delay(10);
    digitalWrite(tdigt2, LOW);

    }
    
    var--;                        
    
    }
                                  
    var = 20;
    beep(200);
    beep(200);
    beep(200);
  }
                                  //If the sensor is not active.
  else {     
       
    digitalWrite(led, LOW);
    
    digitalWrite(tdigt1, HIGH);
    writeLeds(symbols[10]);
    

    digitalWrite(tdigt2, HIGH);
    writeLeds(symbols[10]);
       
    
  }
  
}

// beep function. 
void beep(unsigned char delayms){
  analogWrite(sonido, 200);      
  delay(delayms);          
  analogWrite(sonido, 0);       
  delay(delayms);             
}  


//writeleds function. Info https://www.arduino.cc/reference/en/language/functions/advanced-io/shiftout/
void writeLeds(byte pattern)
{
  
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, pattern); 
  digitalWrite(latchPin, HIGH);
  
}
  

Credits

rjconcepcion
11 projects • 8 followers
Electronic is my passion. I like to work with programming devices like Arduino, ESP8266, Raspberry Pi. I enjoy design electronic projects.
Contact

Comments

Please log in or sign up to comment.