Skip to content

Commit 59dffe7

Browse files
committed
updated images & code
1 parent ed08a0c commit 59dffe7

File tree

5 files changed

+33
-25
lines changed

5 files changed

+33
-25
lines changed
-22.3 KB
Loading
1.64 MB
Loading
-25.5 KB
Loading
-1.82 KB
Loading

content/hardware/01.mkr/03.carriers/mkr-iot-carrier/tutorials/smart-garden-project/smart-garden-project.md

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "IoT Smart Garden Setup with MKR IoT Carrier"
33
description: "Build a smart garden setup with the MKR IoT Carrier, a pump, and a moisture sensor."
44
tags: [IoT, Pumps, Soil Sensor, Temperature Reading]
55
difficulty: beginner
6-
author: "Jacob Hylén, Hannes Siebeneicher"
6+
author: "Jacob Hylén, Hannes Siebeneicher, Karl Söderby"
77
---
88

99
![Smart garden setup with MKR IoT Carrier.](assets/hero.png)
@@ -28,6 +28,7 @@ We will also connect a soil moisture sensor, and together with the sensors onboa
2828
- [MKR IoT Carrier](https://store.arduino.cc/products/arduino-mkr-iot-carrier)
2929
- 5V submersible pump.
3030
- 1 meter watering pipe.
31+
- Water container.
3132
- USB adapter with at least 2 USB ports.
3233
- Micro-USB cable.
3334
- Open ended USB Cable.
@@ -55,6 +56,8 @@ As seen in the image below, positive ends are connected to the **"NC"** connecto
5556

5657
![Connecting the wires to relay 1.](assets/relay-connection.png)
5758

59+
***Tip: to connect the power, pump & relay, you can use a connector strip. This will make your connections much more reliable & sturdy.***
60+
5861
## IoT Cloud Setup
5962

6063
***If you are new to the Arduino IoT Cloud, please refer to the [Getting Started Guide](https://docs.arduino.cc/cloud/iot-cloud/tutorials/iot-cloud-getting-started) or visit the [full documentation](https://docs.arduino.cc/cloud/iot-cloud) to learn more about the service.***
@@ -65,13 +68,13 @@ Begin by navigating to the [Arduino IoT Cloud](https://create.arduino.cc/iot/thi
6568

6669
**2.** Create variables according to the table below:
6770

68-
| Name | Data Type | Function | Permission |
69-
| ----------- | --------- | --------------------------- | ------------ |
70-
| pump | boolean | Activate / de-activate pump | Read & Write |
71-
| moisture | int | Read moisture | Read Only |
72-
| temperature | float | Read temperature | Read Only |
73-
| humidity | float | Read humidity | Read Only |
74-
| log_message | String | Message Log | Read Only |
71+
| Name | Data Type | Function | Permission |
72+
| ----------- | --------- | -------------------------------------- | ------------ |
73+
| watering | boolean | Activate / de-activate pump | Read & Write |
74+
| waterTime | int | How long the pump should run (seconds) | Read & Write |
75+
| moisture | int | Read moisture | Read Only |
76+
| temperature | float | Read temperature | Read Only |
77+
| humidity | float | Read humidity | Read Only |
7578

7679
**3.** Enter your credentials to your Wi-Fi network in the network section.
7780

@@ -82,7 +85,6 @@ Begin by navigating to the [Arduino IoT Cloud](https://create.arduino.cc/iot/thi
8285
**5.** Go to the sketch tab, and use the following code:
8386

8487
```arduino
85-
8688
/*
8789
MKR IoT Carrier Smart Garden Setup Project
8890
@@ -112,9 +114,7 @@ Begin by navigating to the [Arduino IoT Cloud](https://create.arduino.cc/iot/thi
112114
#include <Arduino_OplaUI.h>
113115
114116
const int moistPin = A6;
115-
const float waterAmount = 2; // liters
116-
const float waterSpeed = 0.045; // liters/sec
117-
const float waterTime = waterAmount / waterSpeed; // seconds
117+
118118
unsigned long startedWatering;
119119
120120
MKRIoTCarrier opla;
@@ -163,11 +163,11 @@ void loop() {
163163
164164
// Read the sensor and convert its value to a percentage
165165
// (0% = dry; 100% = wet)
166-
raw_moisture = analogRead(moistPin);
167-
moisture = map(raw_moisture, 780, 1023, 100, 0);
166+
int raw_moisture = analogRead(moistPin);
167+
moisture = map(raw_moisture, 0, 1023, 0, 100);
168168
169-
temperature = carrier.Env.readTemperature();
170-
humidity = carrier.Env.readHumidity();
169+
temperature = opla.Env.readTemperature();
170+
humidity = opla.Env.readHumidity();
171171
172172
// Set the LED color according to the moisture percentage
173173
if (moisture > 40) {
@@ -184,7 +184,7 @@ void loop() {
184184
stopWatering();
185185
}
186186
187-
delay(200);
187+
delay(100);
188188
}
189189
190190
// This function is triggered whenever the server sends a change event,
@@ -199,17 +199,19 @@ void onWateringChange() {
199199
}
200200
201201
void startWatering () {
202-
if (!watering) log_message = "Start watering";
203202
watering = true;
204203
startedWatering = millis();
205204
opla.Relay2.open();
206205
}
207206
208207
void stopWatering () {
209-
if (watering) log_message = "Stop watering";
210208
watering = false;
211209
opla.Relay2.close();
212210
}
211+
212+
void onWaterTimeChange() {
213+
// Add your code here to act upon WaterTime change
214+
}
213215
```
214216

215217
**6.** Upload the code. When successful, you can navigate over to the **"Dashboards"** section. Create a new dashboard.
@@ -230,9 +232,9 @@ We have now assembled the hardware + configured the Arduino IoT Cloud, and we ar
230232

231233
**2.** Place the moisture sensor into the soil of the plant.
232234

233-
![Make sure it is in at least a couple of centimeters.](assets/soil-sensor.png)
235+
![Moisture sensor in a plant.](assets/soil-sensor.png)
234236

235-
**3.** Place the pump inside a water container. We used some adhesive to make it stick firmly, like tape. Attach the plastic pipe to the pump, and place the other end into the plant pot. Place the MKR IoT Carrier next to the plant.
237+
**3.** Place the pump inside a water container. Attach the plastic pipe to the pump, and place the other end into the plant pot. Place the MKR IoT Carrier next to the plant. Your setup could now look like this:
236238

237239
![Plant setup.](assets/smart-garden-setup.png)
238240

@@ -246,10 +248,16 @@ Let's take a look at what our Smart Garden can do. To control it, we can either
246248

247249
***In this dashboard, we have also added a chart widget for each of the variables we monitor.***
248250

249-
- **Watering:** to activate the pump, click on the switch widget on the dashboard.
250-
- **Moisture:** monitor the moisture of your plant: if it is low, turn on the pump, and watch the moisture levels rise!
251-
- **Temperature:** check temperature levels. Note that this may be inaccurate if placed directly in a sunny window!
252-
- **Humidity:** measure the relative humidity of your room. Some plants like it dry; some doesn't!
251+
**Watering:** to activate the pump, do the following:
252+
- Select number of seconds that you want the pump to run for.
253+
- Click on the switch widget. The pump will now run for `x` amount of seconds, and then it will turn off.
254+
- You can also activate the pump through the MKR IoT Carrier. This is done via the touch buttons.
255+
256+
**Moisture:** monitor the moisture of your plant: if it is low, turn on the pump, and watch the moisture levels rise!
257+
258+
**Temperature:** check temperature levels. Note that this may be inaccurate if placed directly in a sunny window!
259+
260+
**Humidity:** measure the relative humidity of your room. Some plants like it dry; some doesn't!
253261

254262
## Conclusion
255263

0 commit comments

Comments
 (0)