Devices & Components
Breadboard - 400 contacts
Arduino Uno Rev3
Resistor 220 ohm
Gravity: Analog TDS Sensor
4.7K ohm resistor
DS18B20 temperature sensor
pH Analog Sensor
Breadboard Jumper Wire Pack (200mm&100mm)
Gravity: Analog Dissolved Oxygen Sensor / Meter Kit For Arduino
Software & Tools
Arduino IDE
Project description
Code
Light Dependent Resistor (LDR) Code
cpp
Code for only LDR individual
1void setup() 2{ 3 Serial.begin(9600); 4} 5 6void loop() 7{ 8 int lightIntensity = analogRead(A1); 9 Serial.print("Light Intensity : "); 10 Serial.println(ldr); 11 delay(1000); 12}
Temperature Sensor Code
cpp
Code for only Temp Sensor individual
1#include <OneWire.h> 2#include <DallasTemperature.h> 3 4#define ONE_WIRE_BUS 9 5 6OneWire oneWire(ONE_WIRE_BUS); 7DallasTemperature sensors(&oneWire); 8 9float Celcius = 0; 10 11void setup() 12 13{ 14 Serial.begin(9600); 15 sensors.begin(); 16} 17 18void loop() 19{ 20 sensors.requestTemperatures(); 21 Celcius=sensors.getTempCByIndex(0); 22 Serial.print(" C "); 23 Serial.print(Celcius); 24 delay(1000); 25}
TDS Sensor Code
cpp
Code for only TDS Sensor individual
1/* 2 DFRobot Gravity: Analog TDS Sensor/Meter 3 <https://www.dfrobot.com/wiki/index.php/Gravity:_Analog_TDS_Sensor_/_Meter_For_Arduino_SKU:_SEN0244> 4 5 This sample code shows how to read the TDS value and calibrate it with the standard buffer solution. 6 707ppm standard buffer solution is recommended. 7 8 Created 2018-1-3 9 By Jason <jason.ling@dfrobot.com@dfrobot.com> 10 11 GNU Lesser General Public License. 12 See <http://www.gnu.org/licenses/> for details. 13 All the above must be included in any redistribution. 14*/ 15 16#define TdsSensorPin A2 17#define TDS 5.0 // analog reference voltage(Volt) of the ADC 18#define SCOUNT 30 // sum of sample point 19int analogBuffer[SCOUNT]; // store the analog value in the array, read from ADC 20int analogBufferTemp[SCOUNT]; 21int analogBufferIndex = 0,copyIndex = 0; 22float averageVoltage = 0,tdsValue = 0,temperature = 25; 23 24void setup() 25{ 26 Serial.begin(115200); 27 pinMode(TdsSensorPin,INPUT); 28} 29 30void loop() 31{ 32 static unsigned long analogSampleTimepoint = millis(); 33 if(millis()-analogSampleTimepoint > 40U) //every 40 milliseconds,read the analog value from the ADC 34 { 35 analogSampleTimepoint = millis(); 36 analogBuffer[analogBufferIndex] = analogRead(TdsSensorPin); //read the analog value and store into the buffer 37 analogBufferIndex++; 38 if(analogBufferIndex == SCOUNT) 39 analogBufferIndex = 0; 40 } 41 static unsigned long printTimepoint = millis(); 42 if(millis()-printTimepoint > 800U) 43 { 44 printTimepoint = millis(); 45 for(copyIndex=0;copyIndex<SCOUNT;copyIndex++) 46 analogBufferTemp[copyIndex]= analogBuffer[copyIndex]; 47 averageVoltage = getMedianNum(analogBufferTemp,SCOUNT) * (float)TDS / 1024.0; // read the analog value more stable by the median filtering algorithm, and convert to voltage value 48 float compensationCoefficient=1.0+0.02*(temperature-25.0); //temperature compensation formula: fFinalResult(25^C) = fFinalResult(current)/(1.0+0.02*(fTP-25.0)); 49 float compensationVolatge=averageVoltage/compensationCoefficient; //temperature compensation 50 tdsValue=((133.42*compensationVolatge*compensationVolatge*compensationVolatge - 255.86*compensationVolatge*compensationVolatge + 857.39*compensationVolatge)*0.5) - 270 + 90; //convert voltage value to tds value 51 //Serial.print("voltage:"); 52 //Serial.print(averageVoltage,2); 53 //Serial.print("V "); 54 Serial.print("TDS Value:"); 55 Serial.print(tdsValue,0); 56 Serial.println("ppm"); 57 delay(60000); 58 } 59} 60 61int getMedianNum(int bArray[], int iFilterLen) 62{ 63 int bTab[iFilterLen]; 64 for (byte i = 0; i<iFilterLen; i++) 65 bTab[i] = bArray[i]; 66 int i, j, bTemp; 67 for (j = 0; j < iFilterLen - 1; j++) 68 { 69 for (i = 0; i < iFilterLen - j - 1; i++) 70 { 71 if (bTab[i] > bTab[i + 1]) 72 { 73 bTemp = bTab[i]; 74 bTab[i] = bTab[i + 1]; 75 bTab[i + 1] = bTemp; 76 } 77 } 78 } 79 if ((iFilterLen & 1) > 0) 80 bTemp = bTab[(iFilterLen - 1) / 2]; 81 else 82 bTemp = (bTab[iFilterLen / 2] + bTab[iFilterLen / 2 - 1]) / 2; 83 return bTemp; 84}
Downloadable files
Schematic Temp Sensor
Here is the circuit layout for the Temp sensor
Schematic Temp Sensor.png

Schematic TDS Sensor
Here is the circuit layout for the TDS sensor
Schematic TDS Sensor.png

Schematic LDR Sensor
Here is the circuit layout for the LDR
Schematic LDR Sensor.png

Comments
Only logged in users can leave comments