Introduction: Motion Sensor Water Tap Using Arduino and Solenoid Valve - DIY
In this project, I'll show you how to build a Motion Sensor Water Tap using a Solenoid Valve. This project can help you convert your existing manual water tap into a tap that can be controlled based on motion detection. Using the IR sensor interfaced with the Arduino, the Tap will automatically turn ON each time the hand is detected in proximity to the IR sensor. The tap will remain ON for a fixed time as defined by the user and then turn OFF automatically.
The project uses simple supplies that are easily accessible and also feasible for everybody.
- Arduino Uno.
- Solenoid Valve 12V.
- IR sensor - can be replaced by an Ultrasonic Sensor based on your choice.
- Diode - 1N4007.
- 12V Power Supply.
- 5V Relay.
- Mini Breadboard.
- Connecting wires.
Step 1: Understanding a Solenoid Valve
A solenoid valve is electromagnetically operated. The energizing of the coil makes the valve to open and allow the flow of the fluid. This mechanism helps replace manual valves and makes it a key component for this project.
Test the working of the solenoid valve by directly connecting the 12V Power supply to the Solenoid Valve. Following which you will hear a "Click" sound. This sound indicates the opening and closing of the valve.
In order to control the Solenoid valve, we must connect it to an Arduino Microcontroller. To do so, a 5V Relay will be used. The solenoid valve induces a back EMF which can damage the relay if connected directly. Hence a Diode must be connected as shown in the figure in this step. This helps ensure safe control of the solenoid valve.
Note - Solenoid Valve does not have a positive or negative terminal, any terminal can be considered as +ve or -ve.
Step 2: Connecting Solenoid Valve to 5V Relay
In this step, we shall connect the solenoid valve to the relay. Refer to the circuit diagram provided for the connections.
- Connect the positive (+ve) terminal of the 12V supply to the common terminal (the center one) of the relay.
- Connect the Positive end of the diode to the NO (Normally Open) terminal of the relay.
- Provide 5V supply to the Relay from the arduino 5V pin.
- Connect the input pin (IN) of the Relay to Pin 13 of Arduino.
In the case of a relay, the supply side has 3 pins:
- IN or IN1, IN2 (based on 1 channel or 2 channel relay)
The output side of the relay:
- Normally Closed configuration (NC) :
1. HIGH signal – current is flowing.
2. LOW signal – current is not flowing
- Normally Open configuration (NO) :
1. HIGH signal – current is not flowing.
2. LOW signal – current is flowing.
- Common (CO)
In this circuit we shall use the "Normally Open" pin as we need to supply current to the valve only when the hand is detected.
Step 3: Connect the IR Sensor
We shall connect the IR sensor to the arduino using the Analog pin of the board. By using the AnalogRead() function of the arduino IDE, we can access the sensor value. This can help determine whether the hand is in close proximity of the sensor or not.
- Connect the IR sensor OUT pin to the Analog pin A0.
- Provide 5V supply to the IR sensor from the Arduino.
- Connect GND pin.
Note - The potentiometer on the IR sensor can be adjusted to vary the detection range of the sensor
Step 4: Upload the Sketch/Code
Next, you'll need to upload sketch onto your Arduino using the Arduino IDE.
Download the attached code and then open it in your Arduino IDE.
Plug in your Arduino and make sure that you've got the correct com port and board selected, then upload the code.
Step 5: Attach the Solenoid Valve to the Tap/Pipe
Prior to providing the supply to our setup, connect the solenoid valve to the tap. There are two ways to go about the process of attaching it to the tap.
- Attach to Pipe: Connect the valve to the pipe that supplies the water to your existing tap.
- Attach to Tap: Connect the valve directly to the tap only if the valve size matches with your existing tap, otherwise it will lead to leakage. Following which turn ON the manual tap. Regardless of the manual tap being turned ON, there will be no flow of water as the solenoid valve is OFF.
The figure shows the setup for connection 1.
Step 6: Using the Motion Sensor Water Tap
That's it, your motion sensor water tap is ready to be used. Each time you would like to use the tap, move your hand in close proximity to your IR sensor. Following which, the water will flow for 7 seconds as defined in the code and will turn OFF automatically. Change the duration based on your requirements.
Let me know what you would change or do differently in the comments section.