Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit de29f86

Browse filesBrowse files
committed
Update example projects
1 parent 0420f4b commit de29f86
Copy full SHA for de29f86

File tree

Expand file treeCollapse file tree

12 files changed

+304
-37
lines changed
Filter options
Expand file treeCollapse file tree

12 files changed

+304
-37
lines changed
Loading
Loading
Binary file not shown.

‎examples/Example projects/Automatic_planter/project.md

Copy file name to clipboardExpand all lines: examples/Example projects/Automatic_planter/project.md
+154-7Lines changed: 154 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,27 @@
33
## 1. Introduction
44
At the Athom office we have a very nice planter that adds some greenery to our place of work. However each week one of us needed to manually water the plants. Unacceptable of course, so we set out to automate the process.
55

6-
## 2. Required hardware
6+
## 2. Parts
77
This project is based around an [Arduino Uno](https://store.arduino.cc/genuino-uno-rev3) combined with an [Arduino Ethernet Shield](https://store.arduino.cc/arduino-ethernet-shield-2).
88

9-
Full parts list
9+
Required parts
1010
* An [Arduino Uno](https://store.arduino.cc/genuino-uno-rev3)
1111
* An [Arduino Ethernet Shield](https://store.arduino.cc/arduino-ethernet-shield-2)
1212
* A breadboard
1313
* A 12v DC wall-plug adapter
1414
* A small 12v water pump (We've used a [DC-1020 pump from Aliexpress](https://www.aliexpress.com/w/wholesale-dc.html?site=glo&SearchText=dc-1020))
1515
* A piece of tubing
16+
* A N-type mosfet (We've used a HUF75545P3 mosfet)
17+
* A 1KOhm resistor for use with the pump MOSFET
18+
19+
Optional parts
1620
* A [moisture sensor](https://www.aliexpress.com/wholesale?SearchText=moisture+sensor)
1721
* A [float sensor](https://www.aliexpress.com/wholesale?SearchText=float+sensor)
18-
* A N-type mosfet (We've used a HUF75545P3 mosfet)
19-
* Two 1KOhm resistors
22+
* A 1KOhm resistor per moisture sensor (only needed for the sensors without built-in transistor)
23+
* A 1KOhm resistor for the float sensor (the internal pull-up feature that most Arduino boards have can be used as well)
24+
25+
26+
![required-parts](pump_parts.jpg)
2027

2128
## 3. Getting a base to work with
2229
To begin we attached our breadboard and our Arduino Uno to a piece of wood using adhesive.
@@ -25,7 +32,7 @@ during the prototyping phase.
2532

2633
We placed the ethernet shield on top of the Arduino Uno.
2734

28-
## 4. Controlling a pump using the Arduino
35+
## 4. Controlling a pump using an Arduino
2936
The 12v pump can not be connected to the Arduino pin because the pump requires a lot more power than the Arduino can deliver. To amplify the signal from the Arduino pin we will use a N-type mosfet.
3037

3138
Since this project mainly focusses on connecting our planter to Homey we will just give a short description on how we connected everything. For more information on using transistors and mosfets with Arduino we suggest looking for tutorials like the Sparkfun tutorial on using transistors found [here](https://learn.sparkfun.com/tutorials/transistors).
@@ -61,6 +68,10 @@ void loop() {
6168
}
6269
```
6370

71+
This is what our prototype looks like:
72+
73+
![pump-prototype](pump_proto.jpg)
74+
6475
## 5. Connecting to Homey
6576

6677
To connect our pump to Homey a bit of code needs to be added to the sketch for the ethernet shield to work:
@@ -156,7 +167,6 @@ void loop() {
156167

157168
if (currentMillis-previousMillis >= 1000) { //Code in this if statement is run once every second
158169
previousMillis = currentMillis;
159-
Serial.println("Hello");
160170

161171
if (pumpTimer>0) { //If the pump is active
162172
pumpTimer = pumpTimer - 1; //Decrease the pump timer
@@ -179,8 +189,145 @@ After pairing the device you can control the pump by adding the device to the ac
179189

180190
The "stop" action can be used without an argument, it will stop the pump instantly.
181191

192+
## 7. Adding a float sensor
193+
Now that we connected our water pump to Homey we can automatically water our plants, but what about times when the tank becomes empty without us noticing?
194+
195+
To make sure that we are notified of an empty tank and to prevent the pump from running without water (to avoid damage to the pump) we added a float sensor to our setup. The float sensor we bought works as a switch. We suspended the float sensor in our water tank at the correct height by connecting it to a piece of coated iron wire which we cut to length and stuck to the top of the jerrycan with some tape.
196+
197+
![float-sensor](float.jpg)
198+
199+
Adding the float sensor to our Arduino project is suprisingly simple. The Arduino Uno on which we based this project has an internal pull-up resistor for all it's pins. This means that a resistor in the Arduino can pulls the input to the supply voltage, while the external sensor (which acts like a switch) just pulls the pin down by connecting it to ground.
200+
201+
So the only connections needed to make the float work are as follows:
202+
203+
| Float pin | Arduino pin |
204+
|-------------|------------------|
205+
| Wire 1 | Pin 3 |
206+
| Wire 2 | Ground |
207+
208+
To read the float sensor the pin has to be configured as an input with pull-up enabled.
209+
210+
```cpp
211+
pinMode(3, INPUT_PULLUP);
212+
```
213+
214+
Reading the sensor can then be done using ```digitalRead(3);```, just like any other input.
182215
216+
Our sensor, which acts like a switch, closes when it is not floating and opens when it is floating. The pull-up pulls the pin high whenever the switch is open, resulting in the following relation:
217+
218+
| Pin state | Meaning |
219+
|-----------|---------------------------------------------------|
220+
| HIGH | The switch is open, so there is water in the tank |
221+
| LOW | The switch is closed, so the tank is empty |
222+
223+
Your sensor could act differently, so you might have to change the sketch a bit to accommodate that instead.
224+
225+
For reading the sensor using Homey we added the following code to our sketch:
226+
227+
```cpp
228+
...
229+
bool previousFloatState = false;
230+
...
231+
232+
void setup() {
233+
...
234+
pinMode(3, INPUT_PULLUP);
235+
...
236+
Homey.addCondition("float", onFloatCondition);
237+
}
238+
239+
void onPump() {
240+
...
241+
if (!previousFloatState) return Homey.returnError("Tank empty!");
242+
...
243+
}
244+
245+
void loop() {
246+
...
247+
<in the interval>
248+
bool currentFloatState = digitalRead(PIN_FLOAT);
249+
250+
if (previousFloatState != currentFloatState) {
251+
previousFloatState = currentFloatState;
252+
Homey.trigger("float", currentFloatState);
253+
if (!currentFloatState) { //Tank empty
254+
onStop();
255+
}
256+
}
257+
...
258+
}
259+
260+
void onFloatCondition() {
261+
return Homey.returnResult(digitalRead(3));
262+
}
263+
```
264+
265+
This exposes the float sensor both as a trigger and as a condition. Additionally it prevents the pump from running when the tank is empty.
266+
267+
268+
### And on a board that does not have internal pull-up resistors?
269+
270+
Should you want to replicate this on a platform that does not have internal pull-up support then you could replace the functionality using a resistor.
271+
272+
In that case you would still connect the sensor like described earlier, however you would need to add a resistor (with a value of for example 1KOhm) between the input pin on the Arduino and the 5v (or 3.3v, depening on the I/O voltage of your board) supply pin. For most Arduino boards the I/O voltage is 5 volt and for most ESP8266 and ESP32 boards the I/O voltage is 3.3v. Check the I/O voltage before connecting the resistor, for connecting the resistor to the wrong supply voltage could cause damage to your board.
273+
274+
When using an external pull-up resistor the pinMode statement would become like this:
275+
276+
```cpp
277+
pinMode(3, INPUT);
278+
```
183279
184280
## 6. Adding moisture sensors
185281
186-
## 7. Adding a float sensor
282+
When soil becomes moist it's resistance drops. A moisture sensor measures the resistance of the soil between two electrodes at a set distance.
283+
284+
### Types of moisture sensors
285+
Some moisture sensors that you buy from stores like [Sparkfun](https://www.sparkfun.com/products/13322) include a small circuit that consists of a resistor divider with a transistor that amplifies the current flowing through the soil.
286+
287+
Most cheap Chinese sensors however do not include this circuit and consist of two wires at a certain distance from each other. For those sensors we suggest creating a simple voltage divider by connecting the analog input of the Arduino to ground through a resistor and to the supply voltage pin (5v or 3.3v) through the sensor.
288+
289+
![moisture-sensor](moisture_sensor.jpg)
290+
291+
### Adding the moisture sensor to the sketch
292+
293+
We connected the moisture sensor to pin A0 on the Arduino.
294+
295+
```cpp
296+
...
297+
int previousMoistureSensorValue = 0;
298+
...
299+
300+
void setup() {
301+
...
302+
pinMode(A0, INPUT);
303+
...
304+
Homey.addCondition("moisture", onMoistureCondition);
305+
}
306+
307+
void onPump() {
308+
...
309+
if (!previousFloatState) return Homey.returnError("Tank empty!");
310+
...
311+
}
312+
313+
void loop() {
314+
...
315+
<in the interval>
316+
bool currentFloatState = digitalRead(PIN_FLOAT);
317+
318+
if (previousFloatState != currentFloatState) {
319+
previousFloatState = currentFloatState;
320+
Homey.trigger("float", currentFloatState);
321+
if (!currentFloatState) { //Tank empty
322+
onStop();
323+
}
324+
}
325+
...
326+
}
327+
328+
void onFloatCondition() {
329+
return Homey.returnResult(digitalRead(3));
330+
}
331+
```
332+
333+
By adding the moisture sensor as a trigger a flow is triggered every time the moisture level changes. This can be used to implement a flow that checks if the moisture level changed below a threshold, allowing Homey to start the pump when necessary. Another approach might be checking of the moisture level as a condition by a flow that is triggered by a time interval, allowing you to make sure the pump isn't started too often.
Loading
Loading
-155 KB
Binary file not shown.

‎examples/Example projects/DHT11/dht11.ino renamed to ‎examples/Example projects/dht11/dht11-esp8266/dht11-esp8266.ino

Copy file name to clipboardExpand all lines: examples/Example projects/dht11/dht11-esp8266/dht11-esp8266.ino
+27-21Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,50 @@
11
/*
22
* Example project:
3-
* Arduino with ethernet 2 shield connected to a DHT11 temperature and humidity sensor
4-
*
3+
* NodeMCU board connected to a DHT11 temperature and humidity sensor
4+
*
55
*/
66

7-
#include <SPI.h>
8-
#include <Ethernet2.h>
9-
#include <EthernetUdp2.h>
7+
#include <ESP8266WiFi.h>
8+
#include <WiFiClient.h>
109
#include <Homey.h>
1110
#include <SimpleDHT.h>
1211

13-
#define PIN_DHT A3
12+
#define PIN_DHT D5
1413

1514
SimpleDHT11 dht11;
1615

17-
byte mac[] = { 0x48, 0x6F, 0x6D, 0x65, 0x79, 0x00 };
18-
19-
unsigned long previousMillis = 0;
16+
unsigned long previousMillis = 0;
2017
const unsigned long interval = 10000; //Interval in milliseconds
2118

19+
void wifi() {
20+
if (WiFi.status() != WL_CONNECTED) {
21+
WiFi.begin("<SSID>", "<PASSWORD>");
22+
uint8_t timeout = 30;
23+
while (WiFi.status() != WL_CONNECTED) {
24+
delay(500);
25+
Serial.print(".");
26+
if (timeout<1) break;
27+
}
28+
if (WiFi.status() == WL_CONNECTED) {
29+
//Print IP address
30+
Serial.print("Connected to WiFi! (");
31+
Serial.print(WiFi.localIP());
32+
Serial.println(")");
33+
}
34+
}
35+
}
36+
2237
void setup() {
2338
Serial.begin(115200);
24-
while (!Serial);
25-
Serial.println("Starting ethernet...");
26-
Ethernet.begin(mac);
27-
Serial.print("IP address: ");
28-
Serial.println(Ethernet.localIP());
29-
3039
Homey.begin("DHT11 sensor");
3140
Homey.setClass("sensor");
3241
Homey.addCapability("measure_humidity");
33-
Homey.addCapability("measure_temperature");
34-
Serial.println("Started.");
42+
Homey.addCapability("measure_temperature");
3543
}
3644

3745
void loop() {
46+
wifi();
3847
Homey.loop();
39-
40-
//This is the 'blink without delay' code
4148
unsigned long currentMillis = millis();
4249
if(currentMillis - previousMillis > interval) {
4350
previousMillis = currentMillis;
@@ -54,10 +61,9 @@ void updateSensor() {
5461
return;
5562
}
5663

57-
Serial.print((int)temperature); Serial.print(" *C, ");
64+
Serial.print((int)temperature); Serial.print(" *C, ");
5865
Serial.print((int)humidity); Serial.println(" H");
5966

6067
Homey.setCapabilityValue("measure_temperature", (int) temperature);
6168
Homey.setCapabilityValue("measure_humidity", (int) humidity);
6269
}
63-

‎examples/Example projects/DHT11/DHT11.ino renamed to ‎examples/Example projects/dht11/dht11-ethernet2/dht11-ethernet2.ino

Copy file name to clipboardExpand all lines: examples/Example projects/dht11/dht11-ethernet2/dht11-ethernet2.ino
+5-9Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Example project:
33
* Arduino with ethernet 2 shield connected to a DHT11 temperature and humidity sensor
4-
*
4+
*
55
*/
66

77
#include <SPI.h>
@@ -10,18 +10,17 @@
1010
#include <Homey.h>
1111
#include <SimpleDHT.h>
1212

13-
#define PIN_DHT A3
13+
#define PIN_DHT 2
1414

1515
SimpleDHT11 dht11;
1616

1717
byte mac[] = { 0x48, 0x6F, 0x6D, 0x65, 0x79, 0x00 };
1818

19-
unsigned long previousMillis = 0;
19+
unsigned long previousMillis = 0;
2020
const unsigned long interval = 10000; //Interval in milliseconds
2121

2222
void setup() {
2323
Serial.begin(115200);
24-
while (!Serial);
2524
Serial.println("Starting ethernet...");
2625
Ethernet.begin(mac);
2726
Serial.print("IP address: ");
@@ -30,14 +29,12 @@ void setup() {
3029
Homey.begin("DHT11 sensor");
3130
Homey.setClass("sensor");
3231
Homey.addCapability("measure_humidity");
33-
Homey.addCapability("measure_temperature");
32+
Homey.addCapability("measure_temperature");
3433
Serial.println("Started.");
3534
}
3635

3736
void loop() {
3837
Homey.loop();
39-
40-
//This is the 'blink without delay' code
4138
unsigned long currentMillis = millis();
4239
if(currentMillis - previousMillis > interval) {
4340
previousMillis = currentMillis;
@@ -54,10 +51,9 @@ void updateSensor() {
5451
return;
5552
}
5653

57-
Serial.print((int)temperature); Serial.print(" *C, ");
54+
Serial.print((int)temperature); Serial.print(" *C, ");
5855
Serial.print((int)humidity); Serial.println(" H");
5956

6057
Homey.setCapabilityValue("measure_temperature", (int) temperature);
6158
Homey.setCapabilityValue("measure_humidity", (int) humidity);
6259
}
63-
107 KB
Loading
38.7 KB
Binary file not shown.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.