How to control your water consumption (Part 1/2).

0. Introduction

This easy tutorial helps you to control the water used in your garden watering. To do this, we use Arduino and Raspberry Pi to get the best of both.

In this project you will learn how to:

  • Communicate Arduino with Raspberry Pi
  • Read a flowmeter pulses
  • Connect a Raspberry Pi to Altair SmartCore to send data streams using Altair SmartCore HTTP REST API



  • 1 x Arduino Uno
  • 1 x Raspberry Pi
  • 1 x Flowmeter (see note below)
  • 1 x Tiny Breadboard
  • 1 x Resitance. Range between 200KΩ and 10KΩ
  • A handful of wires
  • 1 x Case. Optional. Not needed during experiment

Note: The flowmeter used in this tutorial is Swissflow SF800 - Low Pressure Flow Meter

Music to listen: Apollo 440-Liquid cool


1. Project Schema

This project is a quick way to know the water you use in your garden watering and understand the basics of Altair SmartCore communications.

Here is overall diagram of the project:

  • Schema

This prototype is programmed to send a data stream to Altair SmartCore when you close the garden watering.

All the data streams sent by this prototype are collected and stored in Altair SmartCore. Altair SmartCore is a huge database that collects all the information that your sensors send.

In addition to storing data, you can check the water consumption and generate graphs to see the evolution.

With Altair SmartCore you can build very complex Apps to support all the logic of your product on the cloud and integrate it with other devices and IT systems. But for now let’s keep it simple.


2. Arduino and Raspberry Pi. Connections description

In this example we will use the best of Raspberry Pi and best of Arduino, in our opinion the two devices have different capabilities and complement each other quite well when combined.

Arduino will control the hardware (in this case our flowmeter) and Raspberry will be responsible to communicate with Altair SmartCore.
The use of Arduino in this particular case for sensor reading was a pragmatic choice. The flowmeter send pulses that must be read by the electronic device of your choice. It could have been Raspberry Pi but our first tests showed that internal processes tend to escalate process priority and serial pulse readings from RPis GPIO wasnt accurate enough. Arduino made this task perfectly and this was a good opportunity to show how the connection between them can be made.
To communicate Arduino and Raspberry Pi, we will use easier way, the USB connection.

The connections in this prototype are extremely simple. You can see it in the diagram below.

  • Diagram

This is a picture of our prototype reading data from our offices garden.

  • Flowmeter & Arduino & Raspberry Pi


3. Code implemented on Arduino

Arduino will be responsible for collecting the flow measurement (in our case the flowmeter pulses number) and send this data through USB port.

This is the Arduino sketch. Note that some values should be replaced by your own values.

IMPORTANT NOTE: This Arduino sketch will send pulses when the water flow stops more than 1 second (delay time). If you open the water tap, the measure will be sent when you turn it off. If this solution doesn't fit your needs you can use another approach detailed below: 9. Another approach where there is a continuous reading and the measure is sent when the pulses reach the litre count.


4. Altair SmartCore Project and Device Registration


If you are registered in Altair SmartCore, you have a default device already created for you.
Check your control panel and see what it looks like.
Basically you need the device id_developer that might be something like defaultDevice@myusername.
But if you want, you can create a new device and use it in this example.


Now, go to your control panel “My account menu” and check your Apikey.
Its a big alphanumeric token like:
You need this number to complete the example.


5. Data Transferred from Raspberry Pi to Altair SmartCore

From Raspberry Pi you have to build a HTTP request and send the data.

  • HTTP request
    POST /streams HTTP/1.1
    Accept: application/json
    User-Agent: RaspberryPi-SmartCore
    Content-Type: application/json
    Connection: close
  • Data
    "at":CURRENT DATE,
    "data":{"consumption":"YOUR DATA HERE"}


6. Code implemented on Raspberry Pi

Raspberry Pi will be responsible for receive the pulses number, calculate the equivalent in liters (in our example 1 liter = 5600 pulses) and send this data to Altair SmartCore.

This is the Raspberry Pi Pythons code. Note that some values should be replaced by your own values.


7. Checking Data is collected in Altair SmartCore

If you get here, your flowmeter must be sending streams when you finish to water your garden.

Its time to test our control panel and check if we have new streams.
Go to “Data management” → “Data streams” and you will see your data.

  • menu option


8. From here on: Enhancing the project

In the second part of this tutorial, you will learn how to get some nice graphs to analyze this information


9. Another approach

This tutorial is built with an Arduino sketch that sends pulses when the water flow stops more than 1 second (delay time). If you open the water tap, the measure will be sent when you turn it off. If this solution doesn't fit your needs you can use another approach detailed here.

This one was proposed by RM Hayes ( and performs continuous pulse reading. The measure is converted to litres and is sent when the pulses reach the litre count. Here is the Arduino sketch:

As mentioned above, this Arduino sketch send litres not pulses, so the Raspberry Pi code must be slightly different, since litre conversion is not necessary. Here is the RPi code: