-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathWaterMonitor.ino
133 lines (117 loc) · 4.16 KB
/
WaterMonitor.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*********************************************************************
* WaterMonitor.ino
*
* Copyright (C) 2017 [DFRobot](http://www.dfrobot.com)
* GitHub Link :https://github.com/DFRobot/watermonitor
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Description:
* This sample code is mainly used to monitor water quality
* including ph, temperature, dissolved oxygen, ec and orp,etc.
*
* Software Environment: Arduino IDE 1.8.2
* Software download link: https://www.arduino.cc/en/Main/Software
*
* Install the library file:
* Copy the files from the github repository folder libraries to the libraries
* in the Arduino IDE 1.8.2 installation directory
*
* Hardware platform : Arduino M0 Or Arduino Mega2560
* Sensor pin:
* EC : A1
* PH : A2
* ORP : A3
* RTC : I2C
* DO : Serial port Rx(0),Tx(1)
* GravityDO:A4
* temperature:D5
*
* SD card attached to SPI bus as follows:
* Mega: MOSI - pin 51, MISO - pin 50, CLK - pin 52, CS - pin 53
* and pin #53 (SS) must be an output
* M0: Onboard SPI pin,CS - pin 4 (CS pin can be changed)
*
* author : Jason(jason.ling@dfrobot.com)
* version : V1.0
* date : 2017-04-06
**********************************************************************/
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include "GravitySensorHub.h"
#include "GravityRtc.h"
#include "OneWire.h"
#include "SdService.h"
#include "Debug.h"
#include <SoftwareSerial.h>
// clock module
GravityRtc rtc;
// sensor monitor
GravitySensorHub sensorHub;
SdService sdService = SdService(sensorHub.sensors);
void setup() {
Serial.begin(9600);
rtc.setup();
sensorHub.setup();
sdService.setup();
}
//********************************************************************************************
// function name: sensorHub.getValueBySensorNumber (0)
// Function Description: Get the sensor's values, and the different parameters represent the acquisition of different sensor data
// Parameters: 0 ph value
// Parameters: 1 temperature value
// Parameters: 2 Dissolved Oxygen
// Parameters: 3 Conductivity
// Parameters: 4 Redox potential
// return value: returns a double type of data
//********************************************************************************************
unsigned long updateTime = 0;
void loop() {
rtc.update();
sensorHub.update();
sdService.update();
// ************************* Serial debugging ******************
if(millis() - updateTime > 2000)
{
updateTime = millis();
Serial.print(F("ph= "));
Serial.print(sensorHub.getValueBySensorNumber(0));
Serial.print(F(" Temp= "));
Serial.print(sensorHub.getValueBySensorNumber(1));
Serial.print(F(" Do= "));
Serial.print(sensorHub.getValueBySensorNumber(2));
Serial.print(F(" Ec= "));
Serial.print(sensorHub.getValueBySensorNumber(3));
Serial.print(F(" Orp= "));
Serial.println(sensorHub.getValueBySensorNumber(4));
}
}
//* ***************************** Print the relevant debugging information ************** ************ * /
// Note: Arduino M0 need to replace Serial with SerialUSB when printing debugging information
// ************************* Serial debugging ******************
//Serial.print("ph= ");
//Serial.print(sensorHub.getValueBySensorNumber(0));
//Serial.print(" Temp= ");
//Serial.print(sensorHub.getValueBySensorNumber(1));
//Serial.print(" Orp= ");
//Serial.println(sensorHub.getValueBySensorNumber(4));
//Serial.print(" EC= ");
//Serial.println(sensorHub.getValueBySensorNumber(3));
// ************************************************************ time ********************** **********
//Serial.print(" Year = ");//year
//Serial.print(rtc.year);
//Serial.print(" Month = ");//month
//Serial.print(rtc.month);
//Serial.print(" Day = ");//day
//Serial.print(rtc.day);
//Serial.print(" Week = ");//week
//Serial.print(rtc.week);
//Serial.print(" Hour = ");//hour
//Serial.print(rtc.hour);
//Serial.print(" Minute = ");//minute
//Serial.print(rtc.minute);
//Serial.print(" Second = ");//second
//Serial.println(rtc.second);