Skip to content

Commit 6607f4b

Browse files
authored
v1.1.0 - Introduce Water Detector API (#22)
* v1.1.0 with WaterDetector and WaterFlow starting * Fix travis errors * Travis fix * fix travis
1 parent c0f2619 commit 6607f4b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+876
-387
lines changed

.travis.yml

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
language: c
22
before_install:
3+
# Download and install Arduino IDE environment
34
- wget http://downloads.arduino.cc/arduino-1.8.5-linux64.tar.xz
45
- tar xf arduino-1.8.5-linux64.tar.xz
56
- sudo mv arduino-1.8.5 /usr/local/share/arduino
67
- sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino
78
install:
9+
# Install the library in the arduino user libraries folder
810
- ln -s $PWD /usr/local/share/arduino/libraries/Easyuino
911
script:
10-
- arduino --verify --board arduino:avr:uno $PWD/examples/Leds/RGBLedExample.ino
11-
- arduino --verify --board arduino:avr:uno $PWD/examples/Leds/RelayExample.ino
12-
- arduino --verify --board arduino:avr:uno $PWD/examples/Leds/RelayNamedExample.ino
13-
- arduino --verify --board arduino:avr:uno $PWD/examples/Leds/DistanceMeterExample.ino
14-
- arduino --verify --board arduino:avr:uno $PWD/examples/Leds/DistanceMeterNonBlockExample.ino
15-
- arduino --verify --board arduino:avr:uno $PWD/examples/Leds/DistanceMeterAccurateExample.ino
12+
- arduino --verify --board arduino:avr:uno $PWD/examples/Leds/RGBLed/RGBLedExample.ino
13+
- arduino --verify --board arduino:avr:uno $PWD/examples/Relay/RelayExample.ino
14+
- arduino --verify --board arduino:avr:uno $PWD/examples/Relay/RelayNamed/RelayNamedExample.ino
15+
- arduino --verify --board arduino:avr:uno $PWD/examples/UltraSonicModule/DistanceMeter/DistanceMeterExample.ino
16+
- arduino --verify --board arduino:avr:uno $PWD/examples/UltraSonicModule/DistanceMeterNonBlock/DistanceMeterNonBlockExample.ino
17+
- arduino --verify --board arduino:avr:uno $PWD/examples/UltraSonicModule/DistanceMeterAccurate/DistanceMeterAccurateExample.ino
18+
- arduino --verify --board arduino:avr:uno $PWD/examples/WaterDetector/WaterDetectorExample.ino
1619
notifications:
1720
email:
1821
on_success: change
19-
on_failure: change
22+
on_failure: change

Easyuino.vcxitems

+9-6
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@
3131
<ClCompile Include="$(MSBuildThisFileDirectory)src\main\UltraSonicModule\DistanceMeter.cpp" />
3232
<ClCompile Include="$(MSBuildThisFileDirectory)src\main\UltraSonicModule\DistanceMeterPrintable.cpp" />
3333
<ClCompile Include="$(MSBuildThisFileDirectory)src\main\InfraRedReceiver\InfraRedReceiver.cpp" />
34-
<ClCompile Include="$(MSBuildThisFileDirectory)src\main\Displays\OLEDlcd.cpp" />
35-
<ClCompile Include="$(MSBuildThisFileDirectory)src\main\WaterDetector\RainDetector.cpp" />
34+
<ClCompile Include="$(MSBuildThisFileDirectory)src\main\WaterDetector\WaterDetector.cpp" />
3635
<ClCompile Include="$(MSBuildThisFileDirectory)src\main\Relay\Relay.cpp" />
3736
<ClCompile Include="$(MSBuildThisFileDirectory)src\main\Relay\RelayNamed.cpp" />
3837
<ClCompile Include="$(MSBuildThisFileDirectory)src\main\Utilities\Utilities.cpp" />
38+
<ClCompile Include="$(MSBuildThisFileDirectory)src\main\WaterFlow\WaterFlowMeter.cpp" />
39+
<ClCompile Include="$(MSBuildThisFileDirectory)src\main\WaterFlow\WaterFlowSensor.cpp" />
3940
<ClCompile Include="$(MSBuildThisFileDirectory)src\tests\ManualTest.cpp" />
4041
</ItemGroup>
4142
<ItemGroup>
@@ -48,8 +49,8 @@
4849
<ClInclude Include="$(MSBuildThisFileDirectory)src\DistanceMeter.h" />
4950
<ClInclude Include="$(MSBuildThisFileDirectory)src\DistanceMeterPrintable.h" />
5051
<ClInclude Include="$(MSBuildThisFileDirectory)src\InfraRedReceiver.h" />
51-
<ClInclude Include="$(MSBuildThisFileDirectory)src\OLEDlcd.h" />
52-
<ClInclude Include="$(MSBuildThisFileDirectory)src\RainDetector.h" />
52+
<ClInclude Include="$(MSBuildThisFileDirectory)src\tests\WaterDetectorTest.h" />
53+
<ClInclude Include="$(MSBuildThisFileDirectory)src\WaterDetector.h" />
5354
<ClInclude Include="$(MSBuildThisFileDirectory)src\Relay.h" />
5455
<ClInclude Include="$(MSBuildThisFileDirectory)src\RelayNamed.h" />
5556
<ClInclude Include="$(MSBuildThisFileDirectory)src\RGBLed.h" />
@@ -63,18 +64,20 @@
6364
<ClInclude Include="$(MSBuildThisFileDirectory)src\tests\RelayNamedTest.h" />
6465
<ClInclude Include="$(MSBuildThisFileDirectory)src\tests\RelayTest.h" />
6566
<ClInclude Include="$(MSBuildThisFileDirectory)src\tests\RGBLedTest.h" />
67+
<ClInclude Include="$(MSBuildThisFileDirectory)src\WaterFlowMeter.h" />
68+
<ClInclude Include="$(MSBuildThisFileDirectory)src\WaterFlowSensor.h" />
6669
</ItemGroup>
6770
<ItemGroup>
6871
<None Include="$(MSBuildThisFileDirectory).gitignore" />
6972
<None Include="$(MSBuildThisFileDirectory).travis.yml" />
7073
<None Include="$(MSBuildThisFileDirectory)examples\Displays\.gitkeep" />
7174
<None Include="$(MSBuildThisFileDirectory)examples\GSM\.gitkeep" />
7275
<None Include="$(MSBuildThisFileDirectory)examples\InfraRedReceiver\.gitkeep" />
73-
<None Include="$(MSBuildThisFileDirectory)examples\RainDetector\.gitkeep" />
76+
<None Include="$(MSBuildThisFileDirectory)examples\WaterFlow\.gitkeep" />
7477
<None Include="$(MSBuildThisFileDirectory)LICENSE" />
7578
<None Include="$(MSBuildThisFileDirectory)README.md" />
7679
</ItemGroup>
7780
<ItemGroup>
78-
<Image Include="$(MSBuildThisFileDirectory)examples\Leds\20171022_232756.jpg" />
81+
<Image Include="$(MSBuildThisFileDirectory)examples\Leds\RGBLed\RGBLedCircuit.jpg" />
7982
</ItemGroup>
8083
</Project>

Keywords.txt

+19
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@ updateDistanceNonBlock KEYWORD2
5757
##################################################
5858
DistanceMeterAccurate KEYWORD1
5959
##################################################
60+
# WaterDetector #
61+
##################################################
62+
WaterDetector KEYWORD1
63+
begin KEYWORD2
64+
end KEYWORD2
65+
getWaterStatus KEYWORD2
66+
getWaterStatusRange KEYWORD2
67+
isWaterDetected KEYWORD2
68+
##################################################
69+
# WaterStatus #
70+
##################################################
71+
WaterStatus KEYWORD1
72+
DRY LITERAL1
73+
FEW_DROPS LITERAL1
74+
WET LITERAL1
75+
FLOOD LITERAL1
76+
INVALID LITERAL1
77+
NOT_INITIALIZED LITERAL1
78+
##################################################
6079
# GSMService #
6180
##################################################
6281
GSMService KEYWORD1

README.md

+21-8
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,39 @@ The Easyuino library has 5 fundamental goals:
1212
## Sensors and Devices Support
1313

1414
The development of the library, including fixes and addition of new sensors/devices, will be done depending on:
15-
- My time availability (Now I am doing my Masters Degree Thesis in Computer Science and Engineering that stoles a good slice of my time)
15+
- My time availability (Now I am doing my Masters Degree Thesis in Computer Science and Engineering that stoles a huge slice of my time)
1616
- Interest of people in Easyuino
1717

1818
Important: Nevertheless I will accept suggestions for interesting devices/sensors to develop and if there are a lot of interest I will start prioritize them.
1919

20-
More Important: If you have any question about the library or some doubts about the supported devices you can contact me too !!!
20+
More Important: If you have any question about easyuino you can contact me !!!
2121

2222
Contact Channels:
2323
2424

25-
### Implemented, Documented and Tested = Ready to Use
25+
### Already Implemented, Documented and Tested = Ready to Use
2626

27-
- RGB led, Ultrasonic Module (measure distances) , GSM Module (currently only SMS services), Relay Module
27+
- RGB led
28+
- Ultrasonic Module (measure distances)
29+
- GSM Module (currently only SMS services)
30+
- Relay Module
31+
- Water Detector Sensor
2832

2933
### Currently Developing
3034

31-
- Water/Rain Detector
32-
- Displays: OLED lcd and Seven Segments
35+
- Water Flow Sensor (as a sensor exclusively and as a flow rate meter)
36+
- Seven Segments Display
3337

3438
### Develop in a Near Future
3539

36-
- Infra Red Receiver
40+
- Soil moisture/humidity Sensor
41+
- Photoresistor/Light Sensor
3742
- Flame Sensor
43+
- Infra Red Receiver
3844

3945
### Develop in a Long Term Future
4046

4147
- Temperature/Humidity sensor
42-
- Photoresistors/Light sensor
4348
- Knock sensor
4449
- Sound sensor
4550
- Optical Fingerprint sensor
@@ -53,6 +58,14 @@ Contact Channels:
5358
3. *[Optional]* Look at https://github.com/Strabox/Easyuino/wiki to usage examples and details about the API
5459
4. **[Not Optional]** Have fun!!!
5560

61+
## Important: API Usage Examples and Additional Information
62+
63+
**Project's wiki has a set of usage examples of the library API plus more detailed information about it: https://github.com/Strabox/Easyuino/wiki**
64+
65+
## Related and Useful Libraries
66+
67+
https://github.com/Strabox/GSMLibrary I have this Arduino library too that is used to interact with GSM/GPRS boards. It is separated from this one because addresses a much more complex device but follows identical rules of Easyuino.
68+
5669
## Easyuino History
5770

5871
I am Computer Scientist and Engineer (not an Electrotechnical one) that loves programming special in C/C++.

examples/Leds/RGBLedExample.ino renamed to examples/Leds/RGBLed/RGBLedExample.ino

+20-17
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,37 @@ RGBLedExample.ino
55
#include <Easyuino.h> // Include the library in order to the compiler know you want Easyuino library
66

77
using Easyuino::RGBLed; // Necessary in order to use RGBLed
8+
using Easyuino::Color; // Necessary for some method calls
89

9-
int red_pin = 9; // Arduino pin connected to led red pin
10-
int green_pin = 10; // Arduino pin connected to led green pin
10+
int red_pin = 9; // Arduino pin connected to led red pin
11+
int green_pin = 10; // Arduino pin connected to led green pin
1112
int blue_pin = 11; // Arduino pin connected to led blue pin
1213

1314
RGBLed led(red_pin, green_pin, blue_pin); // Create the RGBLed object that exposes the API to use
1415

1516
void setup() {
16-
led.begin(); // Called in setup method to initialize the RGBLed in order to accept requests
17+
led.begin(); // Called in setup method to initialize the RGBLed in order to accept requests
1718
}
1819

1920
void loop() {
21+
/*
22+
- This method call sets the color to YELLOW. There are several ones
23+
you can chose normally as seen in the list below.
24+
- List of Colors Available: RED, GREEN, BLUE, YELLOW, WHITE, ORANGE,
25+
PINK, SALMON, VIOLET, AQUA, BROWN, FIREBRICK, DARKGREY, OLIVE, SKYBLUE
26+
*/
27+
led.setColor(Color::YELLOW);
28+
29+
delay(2000);
30+
2031
/*
2132
- This method call set the led color to RED.
2233
- First parameter controls the amount of red (0-255).
2334
- First parameter controls the amount of green (0-255).
2435
- First parameter controls the amount of blue (0-255).
2536
- The color of the led will be the overlap of the amount of 3 colors. See:
26-
https://en.wikipedia.org/wiki/Additive_color
27-
- You can use this link to pick up RGB colors:
37+
https://en.wikipedia.org/wiki/Additive_color
38+
- You can use this link to pick up RGB colors:
2839
https://www.w3schools.com/colors/colors_picker.asp
2940
*/
3041
led.setColor(255, 0, 0);
@@ -41,23 +52,15 @@ void loop() {
4152

4253
delay(2000);
4354

44-
/*
45-
- This method sets the color to YELLOW. There are several ones
46-
you can chose normally you can see the list in IDEs.
47-
*/
48-
led.setColor(RGBLed::COLOR::YELLOW);
49-
50-
delay(2000);
51-
52-
/*
53-
- This method will set the color to BLUE. See Hexadecimal color code on how to use it.
54-
- You can use this link to pick up Hexadecimal codes https://www.w3schools.com/colors/colors_picker.asp
55+
/*
56+
- This method will set the color to BLUE. See Hexadecimal color code on how to use it.
57+
- You can use this link to pick up Heaxadecimal codes https://www.w3schools.com/colors/colors_picker.asp
5558
*/
5659
led.setColor("#0000ff");
5760

5861
delay(2000);
5962

60-
/*
63+
/*
6164
- This method will turn off the led. After this call you can't set
6265
the color of the led anymore while led.begin(); is not called again.
6366
*/

examples/Relay/RelayExample.ino

+6-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ RelayExample.ino
66

77
using Easyuino::Relay; // Necessary in order to use Relay
88

9-
int arduinoPin = 6; // Arduino pin that controls the relay
9+
int arduinoPin = 6; // Arduino pin that controls the relay
1010

1111
Relay relay(arduinoPin); // Create the Relay object that exposes the API to use
1212

@@ -15,11 +15,10 @@ void setup() {
1515
- Initialize the Relay API.
1616
- The first parameter is TRUE if we connect something to the Normally Closed (NC) of the relay,
1717
and FALSE if we connect to the Normally Open (NO).
18-
- The second parameter is the level of the relay when it is in Normally Closed state.
18+
- The second parameter is the digital level of the relay when it is in Normally Closed state.
1919
This is needed because some relays activate when we put HIGH on the pin and others on LOW.
20-
- relay.begin(); is equal to relay.begin(false, HIGH); which is the common configuration.
2120
*/
22-
relay.begin(false, HIGH);
21+
relay.begin(false, HIGH); // Equivalent to: relay.begin(); which is the common configuration
2322
}
2423

2524
void loop() {
@@ -38,13 +37,13 @@ void loop() {
3837
delay(2000);
3938

4039
/*
41-
Return TRUE if the device is on and FALSE if it is off
40+
Return true if the device is on and false if it is off
4241
*/
4342
bool result = relay.isOn();
4443

4544
/*
46-
- This method will turn off the relay and after that no more calls to
47-
the relay will work without call the relay.begin(); again.
45+
- This method will turn off the device and after that no more calls to
46+
the relay will be possible without call the relay.begin(); again.
4847
*/
4948
relay.end();
5049
}

examples/Relay/RelayNamedExample.ino renamed to examples/Relay/RelayNamed/RelayNamedExample.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ RelayNamedExample.ino
77
using Easyuino::RelayNamed; // Necessary in order to use RelayNamed
88

99
int arduinoPin = 6; // Arduino pin that controls the relay
10-
char* controlledDevice = "Lamp";// The difference for normal relay is that the relay stays with a name identifier name attached
10+
const char* controlledDevice = "Lamp";// The difference for normal relay is that the relay stays with a name identifier name attached
1111

1212
RelayNamed relayNamed(arduinoPin, controlledDevice); // Create the RelayNamed object that exposes the API to use
1313

1414
void setup() {
1515
Serial.begin(9600); // Used to start the serial connection with the computer. Change the 9600 if needed.
16-
relayNamed.begin(false, HIGH); // See RelayExample.ino for the explanation
16+
relayNamed.begin(false, HIGH); // See RelayExample.ino for the explanation
1717
}
1818

1919
void loop() {

examples/UltraSonicModule/DistanceMeterAccurateExample.ino renamed to examples/UltraSonicModule/DistanceMeterAccurate/DistanceMeterAccurateExample.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
DistanceMeterAccurateExample.ino
33
*/
44

examples/UltraSonicModule/DistanceMeterNonBlockExample.ino renamed to examples/UltraSonicModule/DistanceMeterNonBlock/DistanceMeterNonBlockExample.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
DistanceMeterNonBlockExample.ino
33
*/
44

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
WaterDetectorExample.ino
3+
*/
4+
5+
#include <Easyuino.h> // Include the library in order to the compiler know you want Easyuino library
6+
7+
using Easyuino::WaterDetector; // Necessary in order to use WaterDetector
8+
using Easyuino::WaterStatus; // Necessary for some methods calls
9+
10+
int digitalPin = 7; // Arduino pin that connects to the digital pin of the sensor (normally called D0)
11+
int analogPin = 6; // Arduino pin that conencts to the analog pin of the sensor (normally called A0)
12+
13+
WaterDetector waterDetector(digitalPin, analogPin); // Create the WaterDetector object that exposes the API to use
14+
15+
void setup() {
16+
/*
17+
Initialize the serial monitor
18+
*/
19+
Serial.begin(9600);
20+
/*
21+
- Initialize the WaterDetector API
22+
- The first parameter is the digital level (HIGH or LOW) that appear in the digital pin when
23+
the water touches the sensor and the amount of it is above the pre-defined threshold set by the
24+
potentiometer of the board. This is necessary because some sensor versions use HIGH others LOW.
25+
*/
26+
waterDetector.begin(LOW); // Equivalent to: waterDetector.begin(); which is the common configuration
27+
}
28+
29+
void loop() {
30+
/*
31+
This API call will return true when water is detected in the sensor and false otherwise.
32+
*/
33+
bool res = waterDetector.isWaterDetected();
34+
Serial.println(res);
35+
36+
delay(2000);
37+
38+
/*
39+
This API call will return a set of results (see C++ enumerates) that you can compare to see
40+
how much water is touching the sensor.
41+
WARNING: This reading is independent from the above one because the above one is controlled by
42+
the physical potentiometer and digital pin of the sensor. On the other hand the
43+
getWaterStatus uses the analog pin to decide how "wet" :) the sensor is.
44+
*/
45+
WaterStatus status = waterDetector.getWaterStatus();
46+
47+
if (status == WaterStatus::DRY) {
48+
Serial.println("Sensor is dry!");
49+
}
50+
else if (status == WaterStatus::FEW_DROPS) {
51+
Serial.println("Sensor has a few drops in it!");
52+
}
53+
else if (status == WaterStatus::WET) {
54+
Serial.println("Sensor is wet!");
55+
}
56+
else if (status == WaterStatus::FLOOD) {
57+
Serial.println("Sensor is flooded!");
58+
}
59+
else if (status == WaterStatus::INVALID) {
60+
Serial.println("Sensor had a strange invalid reading!");
61+
}
62+
else {
63+
Serial.println("Begin method was not called!");
64+
}
65+
66+
delay(2000);
67+
68+
/*
69+
This API call is more advanced basically it gives you a number from [0,1023] to describe how "wet"
70+
:) the sensor is. 1023 is when the sensor is completely dry and 0 when is completely flooded.
71+
Note: The method getWaterStatus is based on this call.
72+
*/
73+
unsigned int howWet = waterDetector.getWaterStatusRange();
74+
Serial.println(howWet);
75+
76+
delay(2000);
77+
78+
/*
79+
This API call will terminate the sensing ability of the water detector and all the requests
80+
after this one will be invalid. If you want use the sensor again you must call the begin
81+
method again.
82+
*/
83+
waterDetector.end();
84+
}

examples/WaterFlow/.gitkeep

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#pragma once

0 commit comments

Comments
 (0)