Unwashed Hands Alarm




About: My name is Jason Poel Smith. In my free time, I am an Inventor, Maker, Hacker, Tinker, and all around Mad Genius

You have probably seen signs in public restrooms that remind people to wash their hands. And you have probably wondered just how often this sign gets ignored. Well today we are going to make a simple alarm that will tell you (and everyone else in the room) whenever someone forgets to wash their hands.

Step 1: Watch the Video

Here is a video walkthrough of the project.

Step 2: Materials

These are the materials that you will need for this project

Arduino Microcontroller

3x piezo elements

3x 741 OP AMP integrated circuit

9x 4.7kohm resistors

3x 1Mohm resistor

3x 1kohm resistor

100kohm resistor

jumper wires

printed circuit board

magnetic reed switch

12x LEDs

9V Piezo Buzzer

IRF510 Power MOSFET Transistor


Printer Paper

9 volt battery

9 volt battery clip

hot glue gun and glue sticks

Step 3: How This System Works

Here is how the system works. First a sensor detects when the toilet is used. Then a second sensor detects when the sink is used. A third sensor detects when the restroom door is opened. An Arduino microcontroller monitors all of these sensors. If someone uses the toilet but does not use the sink, an alarm will sound when they open the door to leave. This will alert everyone in the room that they did not wash their hands.

Step 4: The Arduino Code

//Here is the code that I wrote for this project. You should be able to paste it directly into a new Arduino Sketch

// Toilet Sensor
int ToiletSensor = 0; // Toilet Sensor Pin int ToiletValue = 0; int ToiletAverage = 520; int ToiletDifference = 0; int ToiletSensitivity = 20;

// Cold Water Pipe Sensor int SinkOneSensor = 1; // Cold Water Pipe Sensor Pin int SinkOneValue =0; int SinkOneAverage = 520; int SinkOneDifference = 0; int SinkOneSensitivity = 20;

// Hot Water Pipe Sensor int SinkTwoSensor = 2; // Hot Water Pipe Sensor Pin int SinkTwoValue =0; int SinkTwoAverage = 520; int SinkTwoDifference = 0; int SinkTwoSensitivity = 20;

int UnwashedHands = false; // true = hands have not been washed, false = hands have been washed int DoorSensorPin = 7; // Door Sensor Pin int DoorSensor = LOW; // senses when restroom door is opened int AlarmPin = 9; // Alarm Output Pin unsigned long ResetTimer = 0;// Stores time for automatic reset

void setup() { Serial.begin(9600); pinMode(DoorSensorPin, INPUT); pinMode(AlarmPin, OUTPUT);

// Output pins for indicator LEDs during testing pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT); pinMode(12, OUTPUT); pinMode(13, OUTPUT); }

void loop() {

//Read each sensor and automatically adjust the average value for each sensor ToiletValue = analogRead(ToiletSensor); ToiletDifference = ToiletValue - ToiletAverage; ToiletAverage = ToiletAverage + (ToiletDifference / 10);

SinkOneValue = analogRead(SinkOneSensor); SinkOneDifference = SinkOneValue - SinkOneAverage; SinkOneAverage = SinkOneAverage + (SinkOneDifference / 10);

SinkTwoValue = analogRead(SinkTwoSensor); SinkTwoDifference = SinkTwoValue - SinkTwoAverage; SinkTwoAverage = SinkTwoAverage + (SinkTwoDifference / 10);

DoorSensor = digitalRead(DoorSensorPin);

if (abs(ToiletDifference) > ToiletSensitivity && millis() > 20000) //waits 20 seconds to establish averages { digitalWrite(10, HIGH); //turns on indicator LED Serial.println("Toilet"); //This Sensor Exceeded the Sensitivity Threshold Serial.println(ToiletDifference); //Difference between current sensor value and sensor average if((millis()-ResetTimer) > 30000) //waits 30 seconds for tank to refill before the toilet sensor can be activated again { UnwashedHands = true; //sets hand wash status ResetTimer = millis(); //Stores current time for automatic reset } } else { digitalWrite(10, LOW); }

if (abs(SinkOneDifference) > SinkOneSensitivity && millis() > 20000) //waits 20 seconds to establish averages { digitalWrite(11, HIGH); //turns on indicator LED Serial.println("Sink One"); //This Sensor Exceeded the Sensitivity Threshold Serial.println(SinkOneDifference); //Difference between current sensor value and sensor average UnwashedHands = false; } else { digitalWrite(11, LOW); }

if (abs(SinkTwoDifference) > SinkTwoSensitivity && millis() > 20000) //waits 20 seconds to establish averages { digitalWrite(12, HIGH); //turns on indicator LED Serial.println("Sink Two"); //This Sensor Exceeded the Sensitivity Threshold Serial.println(SinkTwoDifference); //Difference between current sensor value and sensor average UnwashedHands = false; } else { digitalWrite(12, LOW); }

if (DoorSensor == HIGH) { Serial.println("Door"); digitalWrite(13, HIGH); //turns on indicator LED

if(UnwashedHands == true) { for (int i=0; i <= 5; i++) //sound alarm for 5 seconds { digitalWrite(AlarmPin, HIGH); //Activates Alarm delay(500); digitalWrite(AlarmPin, LOW); delay(500); } }

} else { digitalWrite(13, LOW); } if((millis()- ResetTimer) > 300000) //resets sensors after 5 minutes of inactivity { UnwashedHands = false; } }

Step 5: The Sensors

There are several different kinds of sensors that you can use for this project. To detect when the door is opened, I chose a magnetic reed switch. To detect when the toilet and the sink are used, I chose to use a piezo sensor.

The piezo sensor mounts to the pipes of the toilet and the sink. When water moves through the pipes, the piezo element turns the vibrations into a small electrical signal. This signal is amplified by a simple OP AMP circuit and sent to the microcontroller.

Step 6: Prepare the Piezo Element

Just about any piezo element can work for this project. You can find these in most electronics that beep (watches, timers, etc.) However, if your piezo element is mounted inside a plastic housing, you may need to remove it. Also you should be aware that many piezo buzzers have built in circuitry that also needs to be removed. Here is a simple example.

I purchases a small piezo buzzer from Radio Shack. First I removed the housing by prying it open with a small screw driver. Inside was the piezo element and a small driver circuit. Then I cut the wires that where connecting it to the driver circuit board. This left the piezo element and three attached wires. You want to connect to the outer ring and large white circle (not the center tab). So I also cut the wire that was connected to the small center tab. The remaining two wires will connect to the amplifier circuit.

Step 7: The Amplier Circuit

The amplifier circuit that I chose to use for this project is a basic 741 OP AMP amplifier. I based it on a circuit that was used by Instructables user staceyk in her instructable "Low Cost Water Flow Sensor and Ambient Display." It is powered by the 5V pin on the Arduino. The two 4.7k resistors create a voltage divider that set the base signal at 2.5V. By keeping the signal voltage at the mid-range of the supply voltage, you can monitor voltage changes in both directions.

Three of these sensors are constructed for the toilet pipe, the sink's cold pipe and the sink's hot pipe. The output of each amplifier circuit is sent to the analog input pins on the Arduino.

Step 8: Prototype the Sensors on a Breadboard

First, I prototyped the amplifier circuits on a breadboard for testing. I started by testing the code using an array of switches in place of the piezo sensors. Once that was working, I attached the piezo sensors and the amplifier on a second breadboard.

I hot glued one of the piezo elements to the cold water pipe of my sink. Then I used alligator clip jumper wires it to connect the piezo element to the amplifier.

Try turning the water on and off. If the sensor does not detect the water, try adjusting the sensitivity in the code. If you are still having problems, you may try changing some of the resistor values to adjust the amplification. You can also try moving the sensor to a different location on the pipes.

Once your circuit is working, you can solder the amplifier circuit onto to a circuit board.

Step 9: Solder the Parts Onto a Circuit Board

Next you need to solder all the circuit components onto a circuit board. When attaching the power and output wires, be sure that they are long enough to be able to reach from the sensor to where the Arduino will be mounted.

Step 10: Alternate Sensor Design

In some cases, these sensors will not be able to detect the water moving through the pipes. Sometimes the pipes just won't vibrate very much when used. Other times the building will experience significant vibration from other sources and cause false triggering of the sensors. If this happens you need to use some alternate sensor to detect when the toilet and the sink are used. Here is one example.

You can use a simple pair of wires to detect the presence of water. Water conducts electricity well enough that it can be used as a low power switch. To do this, connect one wire to ground and a second wire to an input pin on the microcontroller. Then connect a high value resistor (100kohm or higher) between the input pin and the positive supply voltage. This resistor acts as a pull-up resistor and will cause the input pin to normally read HIGH. But when the ends of the two wires are submerged in water, they will connect the input pin to ground and it will read LOW. This works as long as the resistance of the water is less than the resistance of the pull-up resistor.

To sense when a toilet is used, you can mount a pair of wires inside the tank of the toilet. (Do not mount the wires inside the bowl). Mount the wires so that the ends are just below the water level in the tank. With the ends of the wires submerged the input pin will read LOW. When the toilet is flushed, the water level drops and the wires will no longer be connected through the water. This makes the signal at the input pin HIGH until the tank refills.

To sense when the sink is used, you can mount two wires underneath the faucet. Place the wires so that they will both be hit by the stream of water when it is turned on.

Step 11: The Door Sensor

To sense when the door is opened I used a magnetic reed switch. These are commonly used in security systems to detect when doors and windows are opened. A magnet mounts to the door. Then the reed switch mounts to the wall next to it. When the door is closed the magnet pulls the contacts on the switch together. When the door opens it breaks the circuit.

To use this, connect one wire on the reed switch to ground and the other wire to an input pin. Then connect the input pin to the positive supply voltage with a high value resistor (100 kohm works well). When the door is closed the input pin will register a LOW signal. When the door opens the input pin will register a HIGH signal.

Step 12: The Alarm

The alarm can be anything that you can dream up. I decided to use both a buzzer and lights around a sign.

First I printed out a "Didn't Wash Hands" label on my printer. Then I cut several pieces of cardboard so that they were a little smaller than the paper. I attached the cardboard and paper with glue and folded the paper around the sides.

Next I decided where to mount the LEDs. At each location I poked holes for the leads of the LEDs. Then I inserted the LEDs and bent the leads down so that they were flush with the back of the board.

The LEDs are powered by the same 9 volt battery that powers the microcontroller. Since the LEDs run on 3 volts I wired them together in groups of three LEDs in series. This lets me leave off the series resistor that you would normally need for an LED.

The buzzer is connected in parallel to the LEDs. It can be mounted anywhere that is convenient. You can attach it to the back of the sign or next to the sign or wherever.

The alarm is activated by a single power transistor. The negative terminals of the battery pack is connected to the GND pin on the microcontroller. Then the output pin on the microcontroller is connected to the base of the transistor. When microcontroller sends a HIGH signal to the transistor it turns on the lights and the buzzer.

Step 13: The Finished System

Once all the parts are in place you can test it out. Flush the toilet, then open the door. The alarm should sound for five seconds. Then wait one minute for the system to reset. This time, flush the toilet and then turn on the sink. Now when you open the door, the alarm shouldn't go off. This will be a big surprise for the first person that doesn't wash their hands at the restaurant.

The code for this project is written for private restrooms with a single toilet and sink. But you could potentially modify it to accommodate more sensors.

As a final note, I need to give some credit to Gary Larson who made a Far Side comic that inspired this project. If you are not already a fan of Gary Larson, I highly recommend checking it out. There is a lot of inspiration to be found in his work.

Home Technology Contest

First Prize in the
Home Technology Contest

squeeze more awesome out of summer contest

Participated in the
squeeze more awesome out of summer contest

Epilog Challenge VI

Participated in the
Epilog Challenge VI



    • 1 Hour Challenge

      1 Hour Challenge
    • Backyard Contest

      Backyard Contest
    • Colors of the Rainbow Contest

      Colors of the Rainbow Contest

    47 Discussions


    1 year ago

    !!! I am definitely going to try this!


    3 years ago

    I am trying to create this project, but I am running into some issues. The code is not correct, I do not know how it all connects, and the order of the steps are confusing. Any help would be appreciated.

    6 replies

    If you could ask specific questions it would be much easier for me to help you solve your problem.


    First, when I run the code it says it is incorrect. Also, I need a full picture showing the system put together. I do not know how it all connects. I would love to make this project, thank you for your help!


    Ok. I see what went wrong. I tried to copy and paste the code into the text box. But apparently doing that automatically combined groups of lines into a single line of code. So the compiler wasn't reading it right. I have attached a copy of the code file to the step so that you can just download that and use it. Sorry for the trouble.


    Okay. Thanks for your help, but I am still a little confused on how the whole system connects. If you can send a full picture of everything together, that would be highly appreciated. Sorry, I am new to instructables. I just need a little help getting started. Thanks again!


    Sorry. But I have already disassembled the system. So I can't get any more pictures of it. But if you closely follow the instructions you should be able to piece it together. If not, feel free to ask questions and I will help you out.


    2 years ago

    please make this everywhere ?


    3 years ago

    Where did you get your materials from specifily the micro controllr

    1 reply

    3 years ago

    Where did you get your materials from specifily the micro controllr


    3 years ago

    Is there a specific microcontroller that I need or just any type?

    1 reply

    4 years ago

    How does the code handle "double flushers"? Sadly this is probably not effective if someone fails to flush at all. You may need a second and much higher degree of shame for that.

    2 replies

    Reply 3 years ago on Introduction

    i was wondering about non-flushers to, but they will still be humiliated if the sign went off ( code dependency )

    the opposite end of the question would be what about people who just went in to wash their hands?

    Once a flush is detected, the system switches to monitoring the sink. If nothing happens for 5 minutes, the system resets.