Automatic water pump

While the Water Alarm built a few days ago was still working great, having to remove the accumulated water frequently is still not a pleasurable task. Therefore, I decided to automate the work by automatically pumping the water away form the small container to a bigger bucket.

The Water Pump

Quickly found a 4 12V mini water pump from an online shop, for an extra 0.1 comes with a hose of 1m in length. The original idea is to turn on the pump when the water reached a certain level, and stop when the water is mostly empty. However, a quick test showed that this pump could only operate when the inlet is totally submersed underwater, it will not work once the inlet is above the water level. That means I have to keep the water to a certain depth to assure the pump will work when needed. No problem, we just need to start with the container half filled.

Mini 12V water pump
Mini 12V water pump


The Power Source

To power both the 12V water pump AND the Spark Core, I can use a single 12V power source and a 7805 to get the 5V power needed for the Spark Core. However, I have found a better alternative when I was browsing online for battery packs, there is one manufacturer producing Li-ion battery packs that have both a 12V and a 5V USB output, with capacity of 8800 mAh, enough to operate this setup for days! The cost was about 7. I decided that this is perfect for the set up here, so I immediately went ahead and ordered one. I’ve got the delivery right to my door the next day.

A dual output 12V/5V-USB Li-ion rechargeable Battery Pack
A dual output 12V/5V-USB Li-ion rechargeable Battery Pack

The Sensors

In order to keep the water at a certain minimum level, and start pumping away excess water when it reached a certain maximum level, two sensors were deployed to produce triggers at Low Water Level and High Water Level. Sensors are extremely simple, each sensor is composed of two wires, placed at the same level as where the minimum or maximum depth is.

One of the two wires in the sensors was connected to an Output Pin, and the other was connected to an Analog Input Pin. The sensors were read by turning on the corresponding output pin and take the value of the analog input. A simple experiment shows that a value below 1000 was returned when a sensor is not submersed inside the water, and if it does, a value above 3000 is read. Therefore, a value of 2000~2500 can be used to reliably tell if the sensor is under or above water.

Water Level Sensors
Water Level Sensors

The Core

Same Spark Core is used, a slightly different program was written to turn on and off the water pump when the corresponding water level sensor was triggered. The logic is as below:

Turn on Digital Pin LEVEL_HIGH

Read Analog Input LEVEL_HIGH

Turn off Digital Pin LEVEL_HIGH

If (value > 2000) turn on pump

Turn on Digital Pin LEVEL_LOW

Read Analog Input LEVEL_LOW

Turn off Digital Pin LEVEL_LOW

If (value < 2000) turn off pump

The Core
The Core



Following is the circuit diagram for connecting all the components together. Note that the relay circuit composes of the 5V relay transistor, diode, resistor and LED is a ready made module as you can see from the above picture.

Schematics for connecting the Spark Core with the water pump
Schematics for connecting the Spark Core with the water pump



There are two features built to deal with emergencies. The first one is a function to force the water pump to activate, in case something wrong with the triggering mechanism. The function exposed to the Cloud API is called “pump”. Just invoking this function via the Spark Cloud API will start the water pump for 10s. After 10s, the pump will stop automatically.

Another feature is the Push Alert feature using By sending a Critical Level alert to your devices that are capable to receive push alerts (Phone, Computer, Watch, etc.) when the water level failed to fall below the Low Water Level threshold 15s after the pump is turned on when the High Water Level threshold is reached.


Everything was working smoothly on the first try, the pump will turn itself on when the water reached the maximum allowed depth and triggered the High water level sensor. It will turn itself off automatically when the Low water level sensor did not sense any water.

Overview of the setup
Overview of the setup

Now, when the water level get high enough to trigger the high water level sensor, the pump will start pumping away the water until the low threshold is reached, then it will stop.

Actual deployment of the automatic water pump
Actual deployment


The source code to this project can be found here.



No comments yet. Why don’t you start the discussion?

Leave a Reply