Automatic Indoor Garden using the M5Stack modules and the Waylay IO IoT platform.

Related Waylay IO articles

Hardware components

M5Stack Core2 ESP32 IoT Development Kit

M5Stack ENV II Unit with Temperature Humidity Pressure Sensor(SHT30+BMP280)

M5Stack Light Unit with Photo-resistance

M5Stack Watering Unit with Mositure Sensor and Pump
M5Stack Connector Grove to 4 Pin

Software apps and online services


M5Stack M5Burner

Waylay IO



Maintaining the right environmental condition for our green ecosystem colleagues is crucial for their wellbeing. Maintaining adequate soil and air humidity levels, temperature, and light intensity not only boosts the growth rate of plants but also decreases disease pressure and plant stress.

In this tutorial, we’ll show you how to build our own minimalist automatic indoor garden. The system will be self-watering and it will log environment data which we’ll be able to visualize in a neat dashboard.

Alarms can be set up to let you know if certain thresholds are being overrun and the system cannot self-regulate. This being the case for temperature or light.

Automated Indoor Garden Setup
Automated Indoor Garden Setup

Hardware requirements

For this tutorial, we chose the M5Stack Ecosystem because it has all the required modules in an easy-to-work way being modular and having a good open source community always building new use cases and bits of software.

The brain of this project is the M5Core2, an IoT development kit based on the ESP32 microcontroller. This development kit allows you to connect the provided modules through a GROVE port and has a handy touchscreen for running commands and debugging.


For monitoring the environmental conditions, we have picked the ENV II Unit, based on SHT30 and BMP280 sensors to measure atmospheric humidity, temperature, and pressure.

For measuring light intensity we have chosen the Light Sensor Unit with Photo-resistance based on LM393. It has a potentiometer that allows setting the sensibility of the sensor to a certain threshold.

M5Stack Light Sensor Unit and ENV II Unit
M5Stack Light Sensor Unit and ENV II Unit

To achieve automatic soil humidity we have used the Watering Unit with Moisture Sensor and Pump that has a sensor to measure the soil humidity level and automatically water the plant when the moisture drops under a certain threshold.

M5Stack Watering Unit with Moisture Sensor and Water Pump
M5Stack Watering Unit with Moisture Sensor and Water Pump

Wire connections

  • Connect the ENV II Unit to PORT A of the M5Core2 (the red port near the USB-C connector) using the Grove cable.
Port A of the M5Core2
Port A of the M5Core2
  • Take out the CORE2 plate on the back to expose the pins.
  • Connect the Light Sensor Unit using the Grove cable, the Grove to 4 Pin connector and the male to male Dupont wires to the following pins:

RED    - 3.3V
WHITE  - G35

  • Connect the Watering Unit using the Grove cable, the Grove to 4 Pin connector and the male to male Dupont wires to the following pins:

RED    - 5V
WHITE  - G36

Pin connections for the Light Sensor Unit and the Watering Unit
1 / 2 • Pin connections for the Light Sensor Unit and the Watering Unit



  • Install Thonny following the steps on the official website.
Thonny Python IDE
Thonny Python IDE

Setting up the device

  • Connect the M5Stack kit to your PC using the provided USB Type-C cable and launch M5Burner. The port name should appear on the top-left corner of the app (near COM).

On Linux, make sure your user is part of the dialout group by running

sudo adduser $USER dialout

M5Burner interface
M5Burner interface
  • Download the UIFlow(CORE2). Click the Erase button, wait for it to finish, and then press the Burn button to upload the UIFlow(CORE2) firmware on the device. We have used 1.8.1_core2 . You will be prompted for the WiFi details that the device will use to connect to your local network. If the burn fails, change the baud rate to a lower one.
Burning the firmware
Burning the firmware
  • Now click on the Configuration box corresponding to UIFlow(Core2) and select App Mode from the dropdown in the provided screen and add the Wifi details if not present.
  • After it finished rebooting, you will be greeted by an initial screen with the UiFlow version in the top right.

Now let's set go ahead and up the cloud solution!

Setting up the cloud solution

Register on Waylay IO if you have not already and login.

  • Go to Resources and add a resource. Name it something like AutomaticIndoorGarden. This resource is practically your device representation in the cloud where you will send the data.
  • Add a new property with the customer key and the Zalmotek value.
  • Add another property with the tags key and the [ "IndoorGarden" ] value.
Creating a resource on Waylay IO
Creating a resource on Waylay IO
  • Go to Webscripts in the left main menu and add a new one. Name it something like SmartGardenDataIngestion and add the following code in the body:
 async function handleRequest (req, res) {
  if (!req.body) {
    // No body found

  // Parse body if needed
  let payload = req.body
  if (typeof payload === 'string' || payload instanceof String)
    payload = JSON.parse(payload)

  You can do some processing of the payload over here.

  // Post values to our resource = ''
  await'replace_with_resource_id', payload, { store: true, forward: true })
    .catch(e => console.error(e.message))


Be sure to replace the replace_with_resource_id placeholder with the actual resource_id from the above step. Navigate to the resource page to get it. Ours is something like 9d086585-eb05-46a2-9367-bf4a45679a0c. Press Save once you have pasted the correct details.

Resource ID on Waylay IO
Resource ID on Waylay IO

Programming the device

  • Go to the GitHub repository of this project (also present in the Code block of this tutorial) and download the zip file containing all necessary code and unpack it in a folder (or use the git command-line interface to do the same thing like a pro).
  • Launch Thonny and from Run -> Select interpreter set up the interpreter to MicroPython (ESP32) and while at it pick the device port.
  • Make sure the M5Stack is connected and displaying the API screen (or with the hello world program open), click on the Shell text field and press CTRL+C or press on the STOP button to connect to the device. Once you see the >> symbol, you can access the files on the device. Go to View and select Files to set up your workspace. Then go to the file provided in this tutorial and edit the URL in the SendPOST() function with the URL of your Webscript. You can find it on, below the name of your Webscript. Click it to copy it to the clipboard (make sure the secret is included).
  • Select all the files from the folder downloaded from GitHub by holding Shift and clicking the files ( , and the 2 folders: custom, res, files provided in this tutorial). Exclude the Readme file, right-click on the menu icon (3 horizontal lines as shown below) and press Upload to /flash, press ok and you are set. Confirm the files being overwritten.
  • At this point be sure to have all the sensors connected as instructed before or else the program will hang on a white screen.
  • Reboot the M5Stack by pressing the down-side button, the one near the sd card slot (the screen will shut down and refresh). The device will connect to the WiFi network and automatically run the file.
  • When the device successfully sends the data to the server you will get a Data sent message on the bottom-left side of the display and the 200 HTTP status code on the bottom-right side of the display (meaning the request was successfully received, understood, and accepted).

Here's a demo of the Watering Unit automatically watering the plant when the soil moisture is low:

And here is a demo of the light sensor, in which you can see the first value on the display updating when the light is turned off, as well as the Data sent message.

Setting up an alarm

Alarms are a useful function through which you can get notified when the monitored values reach unwanted levels.

  • Select the Templates field from your user console and click on the Add Template button.
  • To create a basic alarm flow, we will be adding the necessary blocks from the blocks menu and then configure them.
  • Add a Stream block, uncheck execute on tick and check execute on data and select your Resource of choice.
  • Add a Condition block, uncheck execute on tick and check execute on data and select your Resource of choice. In the condition field write up the condition in the following format:

Ours looks like this:

 ${} > 70 
  • In our example, the metrics you can choose from are the ones defined in the DataMap variable in (lightlvl, status, soilmoisture, temperature, humidity, pressure).
  • Add a Create Alarm block, uncheck execute on tick, check execute on data, and select your Resource of choice. Also fill in your alarm text, your desired alarm type (CRITICAL, MAJOR, MINOR, or WARNING), and create an alarm type.
  • Click on the Save button and choose a name for your template.
  • Now that you have returned to the Templates menu, select the previously created template and click on Create Task.
Creating an alarm on Waylay IO
Creating an alarm on Waylay IO
  • Chose a name for your task, select the Resource choosing Reactive mode and click on Create Task.
  • Now the Task is created and when the condition is met, an alarm will be triggered and it will be displayed in the Alarms field of your console and also in your dashboard linked to the same Resource as the Alarm.
Alarm logs on Waylay IO
Alarm logs on Waylay IO

Creating a dashboard

Now that we managed to consistently send data to our cloud solution, it’s time to set up a dashboard to display it.

  • Head to and log in with your account data.
  • Create an organization by clicking on the + sign. The name of this organization must be identical to the customer name (metadata property) you have used when defining your Resource.
  • Click on Log in as admin.
  • Click on the + sign, click on Query, and in the tag field fill in the value of the tags property you have picked for your Resource.
  • Name your group and finally click on Create group.
  • Click on the + sign next to My dashboard and select the desired representation, select the metric you want to represent and then click Save.
  • For this usecase, we have opted for Gauge widgets to represent the latest value for Humidity, Light Intensity, Pressure, Soil Moisture and Temperature and a Scatterplot widget to represent the evolution of the Temperature in time.
  • After adding all widgets, click on the cogwheel next to the + sign and then click Publish.
  • Click on My dashboard and select your dashboard (notice that the + sign disappears), click on the cogwheel, click on manage and then select public.
  • Now, by clicking on the connectivity button, you can get the link for your public dashboard to share with your friends or to access it from any browser.
Creating a dashboard on Waylay IO
Creating a dashboard on Waylay IO

What’s next?

We have a series of tutorials with other use cases that you could learn from and further sharpen your IoT skills or you could start your very own project.

If you have any further questions, reach out to us via the comments!


Github Repository