Arduino MKR WiFi 1010 - Water/Liquid Valve

This comprehensive guide explains how to control the flow of liquids like water, beer, or oil using the Arduino MKR WiFi 1010 and a solenoid valve. Whether you're building an automated watering system, a beverage dispenser, or an industrial control project, learning to use a solenoid valve with Arduino MKR WiFi 1010 opens up countless automation possibilities.

What You'll Learn:

Real-World Applications:

The same method works for controlling gas flow, making Arduino MKR WiFi 1010 and solenoid valve combinations perfect for various fluid control applications.

The valve can be driven by a relay or by a MOSFET module. Both of them only open and close the valve, because a valve has no "half open" state. So why use a MOSFET module? It makes no click, it switches faster, and it has no metal contacts that wear out over time. You will see both ways in this tutorial.

Arduino MKR WiFi 1010 water valve

Hardware Preparation

1×Arduino MKR WiFi 1010
1×Micro USB Cable
1×Relay
1×Alternatively, MOSFET Module (AOD4184, LR7843 or FR120N)
1×Liquid Solenoid Valve
1×12V Power Adapter
1×Optionally, DC Power Jack
1×Breadboard
1×Jumper Wires

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of Water/Liquid Valve

A solenoid valve is an electromechanical device that controls liquid or gas flow using an electromagnetic coil. When powered, the coil creates a magnetic field that moves an internal plunger, opening or closing the valve. These valves are perfect for automated control systems with the Arduino MKR WiFi 1010.

Pinout

Arduino MKR WiFi 1010 Water/Liquid Valve Pinout

A solenoid valve typically has two connection points for power:

  • Red positive pin (+): Connect this pin to the +12V terminal of your DC power supply.
  • Black or other colored negative pin (–): Connect this pin to the ground (GND) terminal of your DC power supply.

How Water/Liquid Valve works

The valve is usually shut. When you add 12V of DC power to its two points, the valve opens so water or liquid can flow.

※ NOTE THAT:

Some valves have a rubber ring inside that needs a minimum pressure to open the valve after you apply 12V DC. This pressure is made by the liquid flowing.

Some valves only let the liquid flow in one direction.

How to Control Water/Liquid Solenoid Valve

If the valve gets power from a 12V supply, it will open. To control the valve, you must use a relay between the Arduino MKR WiFi 1010 and the valve. The Arduino MKR WiFi 1010 sends signals to the solenoid valve through the relay. Find out more about the relay in the Arduino MKR WiFi 1010 - Relay tutorial.

You can also put a MOSFET module where the relay is. New to this module? The Arduino MKR WiFi 1010 - MOSFET Module tutorial shows how it works and how to wire it.

Relay vs MOSFET Module for a Solenoid Valve

Relay MOSFET Module
Valve control open or closed open or closed (no PWM for a valve)
Noise the relay clicks (and the valve too) the module is silent (only the valve itself clicks)
Switching speed slow, milliseconds very fast
Wear contacts wear out with use no moving contacts
Valve power AC or DC valves DC valves only
Supply voltage any the relay is rated for 6V or more (the gate needs it); a 12V valve is fine
Isolation yes, through the coil yes, through a PC817 optocoupler
Choose it for AC valves, simple ON/OFF 12V DC valves that open and close often

The control is the same in both cases: open or closed. Do not try to use PWM to "half open" a solenoid valve. It does not work and it can make the coil hot. Pick the MOSFET module for a quiet, long-lasting 12V DC setup, and the relay for an AC valve.

Wiring Diagram

Follow this wiring diagram carefully to connect your solenoid valve to the Arduino MKR WiFi 1010 through a relay module:

The wiring diagram between Arduino MKR WiFi 1010 water valve

This image is created using Fritzing. Click to enlarge image

Connection Summary:

  • Arduino MKR WiFi 1010 control pin → Relay signal input
  • Relay power terminals → 12V DC power supply and solenoid valve
  • The relay isolates the Arduino MKR WiFi 1010's low-voltage circuit from the high-power valve circuit

Arduino MKR WiFi 1010 Code

This Arduino MKR WiFi 1010 code demonstrates automatic solenoid valve control. The program repeatedly opens the valve for five seconds to allow liquid flow, then closes it for five seconds. This cycling pattern is useful for timed watering systems, periodic dispensing, or testing your valve setup.

/* * This Arduino MKR WiFi 1010 code was developed by newbiely.com * * This Arduino MKR WiFi 1010 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-mkr/arduino-mkr-wifi-1010-water-liquid-valve */ #define RELAY_PIN 3 // The Arduino UNO R4 pin connected to the IN pin of relay // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin as an output. pinMode(RELAY_PIN, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(RELAY_PIN, HIGH); // open valve 5 seconds delay(5000); digitalWrite(RELAY_PIN, LOW); // close valve 5 seconds delay(5000); }

Detailed Instructions

New to Arduino MKR WiFi 1010? Complete our Getting Started with Arduino MKR WiFi 1010 tutorial first to set up your development environment.

  • Carefully connect the components to your Arduino MKR WiFi 1010 board following the wiring diagram shown above - proper connections are essential for safe operation!
  • Connect your Arduino MKR WiFi 1010 to your computer using a USB cable
  • Launch the Arduino IDE on your computer
  • Select the Arduino MKR WiFi 1010 board and its correct COM port
  • Copy the code above and paste it into the Arduino IDE
  • Click the Upload button to compile and upload the code to your Arduino MKR WiFi 1010 board
  • Ensure your 12V power supply is connected to the relay and solenoid valve
  • Place the valve's output in a container or connect it to your liquid system
  • Observe the solenoid valve opening and closing in 5-second intervals
  • You should hear a clicking sound from both the relay and the valve as they operate
  • Check to see if the water or liquid is flowing during the open periods

Code Explanation

Let's break down how the Arduino MKR WiFi 1010 code controls the solenoid valve:

Setup Phase:

  • The code defines the relay control pin and initializes it as an OUTPUT
  • This pin will send HIGH (on) or LOW (off) signals to the relay module

Main Loop:

  • digitalWrite(relayPin, HIGH) - Activates the relay, which connects 12V power to the solenoid valve, opening it
  • delay(5000) - Keeps the valve open for 5 seconds (5000 milliseconds)
  • digitalWrite(relayPin, LOW) - Deactivates the relay, cutting power to the valve and closing it
  • delay(5000) - Keeps the valve closed for 5 seconds before repeating the cycle

The code comments provide additional details for each line - review them to understand the complete operation.

Troubleshooting Tips

If your solenoid valve isn't working with Arduino MKR WiFi 1010, try these solutions:

Valve Doesn't Open:

  • Verify the 12V power supply is connected and working - use a multimeter to check voltage
  • Confirm the relay is clicking when activated - if not, check the Arduino MKR WiFi 1010 signal pin connection
  • Test if the valve needs minimum pressure - try raising the liquid source higher
  • Check that liquid flow direction matches the arrow on the valve body
  • Ensure the relay is rated for the valve's current draw (usually 300-500mA)

Valve Opens But No Flow:

  • Check for blockages in the valve or connected tubing
  • Verify sufficient liquid pressure in the supply line
  • Some valves require 0.02-0.8 MPa minimum pressure to operate properly
  • Inspect the valve for debris or damage to the internal seal

Relay Doesn't Click:

  • Verify the Arduino MKR WiFi 1010 pin is set as OUTPUT in the code
  • Check connections between Arduino MKR WiFi 1010 and relay signal pin
  • Test the relay with a different pin to rule out relay failure
  • Ensure the relay module has proper power supply (VCC and GND)

Inconsistent Operation:

  • Check all wire connections are secure and not loose
  • Verify the 12V power supply can provide enough current
  • Look for voltage drops in long wire runs - use thicker wires if needed

Using a MOSFET Module Instead of the Relay

Want the valve to switch without the relay click? Replace the relay with a MOSFET module. The valve still only opens and closes, but the switching part is now silent and has no contacts that wear out.

Note that the relay and the MOSFET module use different pins on this page. The relay uses pin 3, and the MOSFET module uses pin D6. So each wiring has its own code.

Wiring Diagram

The wiring diagram between Arduino MKR WiFi 1010 solenoid valve MOSFET module

This image is created using Fritzing. Click to enlarge image

Connection Summary:

  • Arduino MKR WiFi 1010 pin D6 → module PWM pin
  • Arduino MKR WiFi 1010 GND → module GND pin
  • 12V adapter + → module + terminal, shared with the valve red wire (+)
  • Valve black wire (−) → module LOAD terminal
  • 12V adapter − → module − terminal
  • The valve is a coil, so put a 1N4007 or 1N5819 diode across its two wires. The stripe (cathode) goes to the valve + wire.

Code

The code works the same way as the relay code: HIGH turns the valve ON (open), and LOW turns it OFF (closed). The valve opens for 5 seconds and closes for 5 seconds, again and again.

A solenoid valve must only get full ON or full OFF. Never send it a PWM signal. That is why this page does not use the fade code from the MOSFET module tutorial.

/* * This Arduino MKR WiFi 1010 code was developed by newbiely.com * * This Arduino MKR WiFi 1010 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-mkr/arduino-mkr-wifi-1010-water-liquid-valve */ #define MOSFET_PIN 6 // The Arduino MKR WiFi 1010 pin D6 connected to the PWM pin of the MOSFET module // The setup function runs once on reset or power-up void setup() { pinMode(MOSFET_PIN, OUTPUT); // set the pin as an output } // The loop function repeats indefinitely void loop() { digitalWrite(MOSFET_PIN, HIGH); // open the valve for 5 seconds delay(5000); digitalWrite(MOSFET_PIN, LOW); // close the valve for 5 seconds delay(5000); }

Detailed Instructions

  • Wire the Arduino MKR WiFi 1010, the MOSFET module and the valve as shown in the diagram above
  • Connect the Arduino MKR WiFi 1010 to your computer with a USB cable
  • Open the Arduino IDE and select the board and COM port, as in the relay Quick Steps above
  • Copy the code above, paste it into the Arduino IDE and click Upload
  • Watch the valve open for 5 seconds and close for 5 seconds. This time you will hear only the valve, not a relay

Tip: The MOSFET module works only with DC, and its supply must be about 6V or more. If your valve runs on AC, keep using the relay.

Challenge Yourself - Creative Customizations

Once you have the basic solenoid valve control working with Arduino MKR WiFi 1010, try these enhancements:

Sensor-Triggered Valve Control:

// Add soil moisture sensor to trigger valve int moistureLevel = analogRead(A0); if (moistureLevel < 300) { // Soil is dry digitalWrite(relayPin, HIGH); // Open valve delay(10000); // Water for 10 seconds digitalWrite(relayPin, LOW); // Close valve }

Multiple Valve Control:

  • Connect several solenoid valves to different Arduino MKR WiFi 1010 pins
  • Create a watering sequence that operates each valve independently
  • Build a multi-zone irrigation system with scheduled watering

WiFi Control Integration:

  • Use the Arduino MKR WiFi 1010's built-in WiFi to create a web interface
  • Control your solenoid valve remotely from your smartphone
  • Add scheduling features for automatic daily watering
  • Send notifications when watering begins and ends

Advanced Features:

  • Add a flow sensor to measure the amount of liquid dispensed
  • Implement safety timers to prevent valve from staying open too long
  • Create a rain sensor integration that skips watering when it's raining
  • Add a water level sensor to prevent empty reservoir operation

Video

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!