---
# System prepended metadata

title: Grow flowers like an expert - Smart flower pot

---

# Grow flowers like an expert - Smart flower pot
Panpan Zhang (pz222cd)
A smart flower pot that monitors the environment of the plant, detects data of moisture, temperature and light for the plant.

This tutorial might take approximately 8 hours to complete if no bugs.

## Objective
Almost everybody likes flowers, but not everyone knows how to grow them. Without knowing about plants, it might die in a few days. I want to design a smart flowerpot that makes people grow plants like an expert. It will detect the state of plants, and give different warnings of temperature, humidity and light according to the different types of plants in the flowerpot. This tutorial only related the part of reading datas.

## Material
I use Arduino MKR wifi 1010 in this project.

| Product | Description | price|
| -------- | -------- | -------- |
|[Arduino MKR wifi 1010](https://store.arduino.cc/products/arduino-mkr-wifi-1010?selectedStore=eu)|Microcontroller, which is what we will connect to, program and what controls the sensors.| 330 SEK|
|[BMP180](https://www.electrokit.com/produkt/bmp180-lufttryckssensor-monterad-pa-kort/)|Temperature sensor. Communicates via I2C.|69 SEK|
|[mositure sensor](https://www.electrokit.com/en/product/soil-hygrometer-module/)|Sensor for measuring the moisture level in soil|29 SEK|
|[Photoresistor](https://www.amazon.se/GL5516-ljusberoende-resistor-Photoresistor-LDR/dp/B00NXW9WZ6/ref=asc_df_B00NXW9WZ6/?tag=shpngadsglede-21&linkCode=df0&hvadid=476594957925&hvpos=&hvnetw=g&hvrand=3922105856461421603&hvpone=&hvptwo=&hvqmt=&hvdev=c&hvdvcmdl=&hvlocint=&hvlocphy=9062437&hvtargid=pla-438566214643&psc=1)|30-90K Ohm Light Resistance Sensitive Resistance that measures light |55 SEK|
|[Jumper wires](https://www.amazon.se/dp/B01EV70C78/ref=pd_rhf_d_dp_s_pd_crcd_sccl_2_1/260-6672967-1703234?pd_rd_w=uwbGF&content-id=amzn1.sym.6ed0b2dc-5081-4711-8f72-847f56bafc2a&pf_rd_p=6ed0b2dc-5081-4711-8f72-847f56bafc2a&pf_rd_r=AA4PEQCDXG5BMXADZ8N4&pd_rd_wg=LQ3lx&pd_rd_r=69614737-c0f0-409d-9e1a-cbc6d923b0c7&pd_rd_i=B01EV70C78&psc=1)|Connect the sensors to the microcontroller.|90 SEK|
|[Breadboard](https://www.electrokit.com/produkt/kopplingsdack-400-anslutningar/)|Connection decks for solder-free connections |59 SEK|
|[Micro-USB cable](https://www.kjell.com/se/produkter/dator/kablar-adaptrar/usb/usb-kablar/micro-usb-kabel-1-m-p68687)| To connect and upload code to the microcontroller.|99 SEK|
||In total:|731 SEK|
## Computer and device setup

### Install Arduino IDE
We are going to use the Arduino micro-controller for hardware prototyping. The microcontroller can be programmed using the Arduino IDE, which is based on Java programming language. The IDE also supports C and C++ languages, but there are numerous alternatives to setup an Arduino board, like MATLAB and Python.
DOWNLOAD IDE: https://www.arduino.cc/en/software
Follow the instructions to install Arduino IDE.

### Setup board
#### Step 1. Install Drivers for the MKR WIFI 1010
If you are using windows operating system, you need to install a driver to drive the board.
This simple procedure is done by selecting Tools menu > Boards > Boards Manager, search for Arduino SAMD board then install it. like the following image.
![](https://i.imgur.com/6zwi5mQ.jpg)

it might take a while. With the SAMD core installed, you now proceed with the driver installation.

#### Step 2. Connect the Arduino to USB port
Restart Arduino IDE. Check the name of the board, this model is called Arduino MKR wifi 1010. Connect your board to your laptop, verify the ON LED is switched on.
![](https://i.imgur.com/O66M6lK.jpg)

#### Step 3. Select board on Arduino IDE
Here, we select the board Arduino MKR wifi 1010
![](https://i.imgur.com/AUrPMCF.jpg)

#### Step 4. Select the USB port 
It doesn't have to be port 7, it will be variable according to your laptop. If the USB port does not appear in the menu remove the board and reconnect.
![](https://i.imgur.com/q0wcWd8.jpg)

#### Step 5. Get board info
Verify that the board is connected. If it's properly connected, it will have a pop-up window showing your board info like below.
![](https://i.imgur.com/4S2YnJc.jpg)

A new dialog will appear showing the name of the board, its S/N and so on.

Now the board is settled.

### Text the board and Upload code
#### Step 1. Load the code
To know if the board is working, we can use a simple code to test it.
You can load the example code from the menu File/Examples/01.Basics/Blink.This example shows the simplest thing you can do with an Arduino to see physical output: it blinks the on-board LED.
The code shows like below:
```
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}
```
#### Step 2. Compile code
Press the Verify button, Check that the compilation was successful.The message "Done compiling" should appear at the bottom.
![](https://i.imgur.com/Hrj4gd6.jpg)
![](https://i.imgur.com/aarjLp1.png)
#### Step 3. Upload code to Arduino
Press the Upload button, When finished you will see the message "Done uploading" at the bottom.
![](https://i.imgur.com/Pb66v3D.png)
![](https://i.imgur.com/qcQRmMt.png)

#### Step 4. Blinking!
Now you can see the built-in LED is blinking every 1 second. You can change the delay time in the code to change the blinking frequency.
![](https://i.imgur.com/wkBDo1n.jpg)

## Putting everything together
In this tutorial, we use three sensors. The circuit diagram of all connection can be seen below:
![](https://i.imgur.com/MliIt9w.jpg)

### BMP180 temperature sensor
BMP180 can measure temperature from -40°C to 85°C with ±1.0°C accuracy, also measure barometric pressure from 300 to 1100 hPa (9000m to -500m above sea level).

The BMP180 module has only 4 pins that interface it to the outside world. The connections are as follows:
Connect VIN - VCC 3.3V (The module comes with an on-board LM6206 3.3V regulator, so you can use it with a 5V logic microcontroller without worry.)
Connect GND - Ground
Connect SCL - SCL (pin 12 on the board)
Connect SDA - SDA (pin 11 on the board)
![](https://i.imgur.com/9SdwPD9.png)


### Mositure sensor
The FC-28 soil moisture sensor includes 4-pins. The connection shoud be like bleow:
VCC - VCC for power
GND - GND
D0 don't need to connect to any pin,
A0 - A0 for an analog output (or any analog input pin)
![](https://i.imgur.com/d7beznq.png)


### Light sensor
In this project I use a photoresistors as a light sensor. As the name suggests, photoresistors work similarly as regular resistors, but instead resistance change is dependent on the amount of light it’s exposed to.
The connections of this module are easy.
One pin connects to a 220 ohm resistor then connects to ground, this pin should also connect to an analog input pin on the microcontroller, which is from A0-A6 except the pin that moisture sensor used. We will define which pin we use in the code to read the analog value. Another pin connects to 3.3-5V as supply voltage. 
![](https://i.imgur.com/3rrxlVW.png)



When everything is connected together it will look like this:
![](https://i.imgur.com/KwcjGKR.jpg)

## Platform
The platform I chose to visualize the data is arduino iot cloud. It has very comprehensive documents, and many cases to learn from. On the other hand, the dashboard is easy to set up, and an IDE on the cloud is equipped. Choose a device you want to connect, and Arduino Cloud will take care of all the code necessary for setting things up.

By setup your Arduino iot cloud account, you need to connect your board, and input your wifi ID and password.
![](https://i.imgur.com/Uyo8fxd.jpg)
For the network, SSID is the name of your network, Password is the password of your network.
After those are setteled should likes like below:
![](https://i.imgur.com/ED2H7cR.jpg)
![](https://i.imgur.com/WLlgYMg.jpg)

Then you need to add variables you need, I add four variables to get the data from the sensors.
![](https://i.imgur.com/08dmEUu.jpg)

You can follow [this tutorial](https://docs.arduino.cc/arduino-cloud/getting-started/iot-cloud-getting-started) to set up the account.

## The code

Now alomst the end of this tutorail.
After you set up the iot cloud, it will automatically generate relevant code. Click on "open full editor" button, it will open a new window with the IDE on the cloud. you will find all code that you need for this project. 
It stores your wifi information in the secret file, and define variables in the tingsProperties.h file. So what you need to do is modify the code from the main file and upload the code as below:
```
#include "thingProperties.h"
 
#include <Adafruit_BMP085.h>

Adafruit_BMP085 bmp;

int light_sensorPin = A5;
//int light_sensorValue;

int humidity_sensorPin = A0;
//int tem_sensorValue;
int limit = 600;

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500);

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
  */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
  
  //to print if tempsensor is connected.
 while(!Serial);
 if (!bmp.begin()) {
 Serial.println("Could not find a valid BMP085 sensor, check wiring!");
 //while (1) {}
  }
  
}

void loop() {
  ArduinoCloud.update();
  // Your code here
  //temperature sensor
  temerature_sensorValue = bmp.readTemperature();
  pressure_sensorValue = bmp.readPressure();
  
  Serial.print("Temperature = ");
  Serial.print(bmp.readTemperature());
  Serial.println(" *C");
  
  Serial.print("Pressure = ");
  Serial.print(bmp.readPressure());
  Serial.println(" Pa");
  
  //for light sensor (value between 0 and 1023)
  light_sensorValue = analogRead(light_sensorPin);

  Serial.print("Analog reading: ");
  Serial.print(light_sensorValue);   // the raw analog reading

  // We'll have a few threshholds, qualitatively determined
  if (light_sensorValue < 10) {
    Serial.println(" - Dark");
  } else if (light_sensorValue < 200) {
    Serial.println(" - Dim");
  } else if (light_sensorValue < 500) {
    Serial.println(" - Light");
  } else if (light_sensorValue < 800) {
    Serial.println(" - Bright");
  } else {
    Serial.println(" - Very bright");
  }

  //for moisture sensor (value between 0 and 1023)
  humidity_sensorValue = analogRead(humidity_sensorPin);

  Serial.print("Analog Value : ");
  Serial.println(humidity_sensorValue);

  Serial.println( );
  delay(3000);

}
```
Click the same button as offline IDE editor to upload the code to your board. 

## Transmitting the data

### Wireless Protocol

The board used for this project only has WiFi hence WiFi is being used to transmit the data. WiFi does not have long range and high power consumption, nonetheless, it is very suitable for this project because it is aimed for home use only. 

### Transport Protocol

The device send data every 2 senconds as you defined when you add variables to setup the board. You can change this anytime you want. 
![](https://i.imgur.com/S64Epar.jpg)
All data will be stored in the cloud on arduino platform, no local storage needed. 

## Presenting the data
The data print on the dialog look like below:
![](https://i.imgur.com/u7enreI.jpg)

To visualize the data you get, you need to go to Dashboards and create a board named with your project name. You can create two boards when it's a free version.
![](https://i.imgur.com/yBTBopD.jpg)
Click the board you created and edit your board as you wish. 
Add widgets and link variables.
![](https://i.imgur.com/6eAKCEP.jpg)

Now the data is being presented on Arduino iot cloud dashboard.
![](https://i.imgur.com/GRXBk7z.jpg)

## Finalizing the design
After uploading the code to the board, now you can remove it from your laptop and connect to a battery that can power up your board. Put the soil moisture sensor in a pot by the balcony, and now the project is completed.
![](https://i.imgur.com/ttGMmP2.jpg)

As a student without any circuit and coding background, I am quite satisfied with this outcome. During the project, I encountered so many problems, thanks to the teachers, teaching assistants and enthusiastic netizens on the forum for their help.