Step #2: The Arduino Code
[protected-iframe id="ee60f217fc1662a24ef508718d15084b-30206320-62929444" info="https://gist.github.com/nhurstmake/677eaf0a1c0d06ff0008.js" width="600" height="2600"]
- 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 #5: The Amplfier 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 #7: 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.
- 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, and 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.
- 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. Because 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 the microcontroller sends a HIGH signal to the transistor it turns on the lights and the buzzer.