This commit is contained in:
parent
7b3fb46475
commit
29a885313a
1 changed files with 104 additions and 9 deletions
|
|
@ -7,15 +7,20 @@
|
|||
* Waterproof DS18B20 water temperature sensor
|
||||
* TMP36 air temperature sensor
|
||||
* HC-SR04 distance sensor (for water level..)
|
||||
* A european two pin plug for EC measurements
|
||||
* Output in CSV; no error handling yet
|
||||
* write out all the results in the following format:
|
||||
* uptime (ms),water level (cm), pH, pH Voltage, water temp (degrees C), air temp (degrees C)
|
||||
* uptime (ms),water level (cm), pH, pH Voltage, water temp (degrees C), air temp (degrees C), RC, EC, PPM
|
||||
*
|
||||
* This code is entirely based on some awesome examples, re-worked for this application
|
||||
* The internal pullup library is needed to avoid an external 4.7k resistor on the DS18B20
|
||||
* Great blog entry by josh levine @bigjoshlevine - Thanks! I was thinking EXACTLY the same thing
|
||||
* https://wp.josh.com/2014/06/23/no-external-pull-up-needed-for-ds18b20-temp-sensor/
|
||||
*
|
||||
* PPM code
|
||||
* Modified from ElCheapo Arduino EC-PPM measurments
|
||||
* 28/8/2015 Michael Ratcliffe Mike@MichaelRatcliffe.com
|
||||
*
|
||||
* Pinouts:
|
||||
*
|
||||
* Pin 10 - DS18B20 data pin
|
||||
|
|
@ -23,11 +28,10 @@
|
|||
* Pin 13 - HC-SR04 Echo
|
||||
* Pin A2 - pH Meter V1.1 data (DF Robot breakout)
|
||||
* Pin A3 - TMP36 data pin
|
||||
* Pin D4 - EC/PPM Power
|
||||
* Pin A1 - EC/PPM Pin
|
||||
* Pin A3 - EC/PPM Ground
|
||||
*
|
||||
* As a reminder to myself, I used pin PA6 on the OrangePiZero that I'm hosting this on for reset (active low)
|
||||
* on the Arduino Pro Mini, there is also a 3v3/5v potential divider on the TX from the Arduino.
|
||||
* The Orange Pi Zero UART being used is UART1
|
||||
*
|
||||
* Licensed under GPL V3. Read the license here:
|
||||
* https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||
*
|
||||
|
|
@ -41,6 +45,35 @@
|
|||
int pHArray[ArrayLenth]; //Store the average value of the sensor feedback
|
||||
int pHArrayIndex=0;
|
||||
|
||||
//PPM code
|
||||
// Modified from ElCheapo Arduino EC-PPM measurments
|
||||
// 28/8/2015 Michael Ratcliffe Mike@MichaelRatcliffe.com
|
||||
int R1= 400;
|
||||
int Ra=25; //Resistance of powering Pins
|
||||
int ECPin= A1;
|
||||
int ECGround=A3;
|
||||
int ECPower = 4;
|
||||
|
||||
//User variales for the PPM/EC measurement
|
||||
float PPMconversion=0.7;
|
||||
float TemperatureCoef = 0.019; //this changes depending on what chemical we are measuring
|
||||
float K=2.85;
|
||||
//Fixed variables
|
||||
//float Temperature=10; variable substituted for Ftemp in this code
|
||||
float EC=0;
|
||||
float EC25 =0;
|
||||
int ppm =0;
|
||||
float raw= 0;
|
||||
float Vin= 5;
|
||||
float Vdrop= 0;
|
||||
float Rc= 0;
|
||||
float buffer=0;
|
||||
|
||||
//water temperature
|
||||
float Ftemp=10;
|
||||
|
||||
|
||||
|
||||
// DS18S20 Temperature chip i/o
|
||||
#include <OneWire.h> //this is the onewire version with the pullup high.
|
||||
|
||||
|
|
@ -57,6 +90,20 @@ int sensorPin = 0;
|
|||
|
||||
void setup(void)
|
||||
{
|
||||
//PPM Measurement setup code
|
||||
pinMode(ECPin,INPUT);
|
||||
pinMode(ECPower,OUTPUT);//Setting pin for sourcing current
|
||||
pinMode(ECGround,OUTPUT);//setting pin for sinking current
|
||||
digitalWrite(ECGround,LOW);//We can leave the ground connected permanantly
|
||||
|
||||
delay(100);// gives sensor time to settle
|
||||
delay(100);
|
||||
//** Adding Digital Pin Resistance to [25 ohm] to the static Resistor *********//
|
||||
// Consule Read-Me for Why, or just accept it as true
|
||||
R1=(R1+Ra);// Taking into acount Powering Pin Resitance
|
||||
|
||||
|
||||
|
||||
pinMode(echopin, INPUT);
|
||||
pinMode(trigpin, OUTPUT);
|
||||
// pinMode(LED,OUTPUT);
|
||||
|
|
@ -93,7 +140,7 @@ void loop(void)
|
|||
byte data[12];
|
||||
byte addr[8];
|
||||
int Temp;
|
||||
float Ftemp;
|
||||
|
||||
ds.reset_search();
|
||||
if ( !ds.search(addr)) {
|
||||
// Serial.print("No more addresses.\n");
|
||||
|
|
@ -224,7 +271,7 @@ Ftemp =(Temp * 0.0625);
|
|||
|
||||
|
||||
//write out all the results in the following format
|
||||
// uptime (ms),water level (cm), pH, pH Voltage, water temp (degrees C), air temp (degrees C)
|
||||
// uptime (ms),water level (cm), pH, pH Voltage, water temp (degrees C), air temp (degrees C), RC, EC, PPM
|
||||
|
||||
|
||||
|
||||
|
|
@ -236,7 +283,10 @@ Serial.print(';');
|
|||
Serial.print(Ftemp);
|
||||
Serial.print(';');
|
||||
Serial.print(temperatureC);
|
||||
Serial.println(';');
|
||||
Serial.print(';');
|
||||
GetEC();
|
||||
PrintReadings();
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -280,4 +330,49 @@ double avergearray(int* arr, int number){
|
|||
avg = (double)amount/(number-2);
|
||||
}//if
|
||||
return avg;
|
||||
}
|
||||
}
|
||||
|
||||
void GetEC(){
|
||||
|
||||
|
||||
|
||||
//************Estimates Resistance of Liquid ****************//
|
||||
digitalWrite(ECPower,HIGH);
|
||||
raw= analogRead(ECPin);
|
||||
raw= analogRead(ECPin);// This is not a mistake, First reading will be low beause if charged a capacitor
|
||||
digitalWrite(ECPower,LOW);
|
||||
|
||||
|
||||
|
||||
|
||||
//***************** Converts to EC **************************//
|
||||
Vdrop= (Vin*raw)/1024.0;
|
||||
Rc=(Vdrop*R1)/(Vin-Vdrop);
|
||||
Rc=Rc-Ra; //acounting for Digital Pin Resitance
|
||||
EC = 1000/(Rc*K);
|
||||
|
||||
|
||||
//*************Compensating For Temperaure********************//
|
||||
EC25 = EC/ (1+ TemperatureCoef*(Ftemp-25.0));
|
||||
ppm=(EC25)*(PPMconversion*1000);
|
||||
|
||||
|
||||
;}
|
||||
//************************** End OF EC Function ***************************//
|
||||
|
||||
|
||||
|
||||
|
||||
//***This Loop Is called From Main Loop- Prints to serial usefull info ***//
|
||||
void PrintReadings(){
|
||||
//Serial.print("Rc: ");
|
||||
Serial.print(Rc);
|
||||
Serial.print(';');
|
||||
//Serial.print(" EC: ");
|
||||
Serial.print(EC25);
|
||||
Serial.print(';');
|
||||
//Serial.print(" Simens ");
|
||||
Serial.print(ppm);
|
||||
//Serial.print(" ppm ");
|
||||
Serial.println(';');
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue