Analog ORP Meter(SKU:SEN0165) with ESP32
![userHead](https://dfimg.dfrobot.com/dfPortrait2.png)
Hi, I purchased the "Analog ORP Meter (SKU: SEN0165)" sensor for a water monitoring project.
Everything works correctly if connected to an Arduino Uno, but my intent is to move the project on the ESP32 module, but with this chip the sensor does not work properly.
More than the sensor, I'm guilty of the ESP32 ADC pin .... Did anyone already have the possibility to connect the sensor and the module together?
As a development ide I use Arduino 1.8.6 and the sketch is the example provided in the sensor wiki.
Sorry for my bad english, thanks in advance
Everything works correctly if connected to an Arduino Uno, but my intent is to move the project on the ESP32 module, but with this chip the sensor does not work properly.
More than the sensor, I'm guilty of the ESP32 ADC pin .... Did anyone already have the possibility to connect the sensor and the module together?
As a development ide I use Arduino 1.8.6 and the sketch is the example provided in the sensor wiki.
Sorry for my bad english, thanks in advance
2018-09-07 11:32:28 Hi.
According to your description of the questions. If you want to use "Analog ORP Meter (SKU: SEN0165)" on the ESP32 Board. I hope you can try the following sample code.
makermuyi
According to your description of the questions. If you want to use "Analog ORP Meter (SKU: SEN0165)" on the ESP32 Board. I hope you can try the following sample code.
Code: Select all
#define VOLTAGE 5.00 //system voltage
#define OFFSET 0 //zero drift voltage
#define LED D9 //operating instructions
double orpValue;
#define ArrayLenth 40 //times of collection
#define orpPin A1 //orp meter output,connect to Arduino controller ADC pin
int orpArray[ArrayLenth];
int orpArrayIndex=0;
double avergearray(int* arr, int number){
int i;
int max,min;
double avg;
long amount=0;
if(number<=0){
printf("Error number for the array to avraging!/n");
return 0;
}
if(number<5){ //less than 5, calculated directly statistics
for(i=0;i<number;i++){
amount+=arr[i];
}
avg = amount/number;
return avg;
}else{
if(arr[0]<arr[1]){
min = arr[0];max=arr[1];
}
else{
min=arr[1];max=arr[0];
}
for(i=2;i<number;i++){
if(arr[i]<min){
amount+=min; //arr<min
min=arr[i];
}else {
if(arr[i]>max){
amount+=max; //arr>max
max=arr[i];
}else{
amount+=arr[i]; //min<=arr<=max
}
}//if
}//for
avg = (double)amount/(number-2);
}//if
return avg;
}
void setup(void) {
Serial.begin(9600);
pinMode(LED,OUTPUT);
}
void loop(void) {
static unsigned long orpTimer=millis(); //analog sampling interval
static unsigned long printTime=millis();
if(millis() >= orpTimer)
{
orpTimer=millis()+20;
orpArray[orpArrayIndex++]=analogRead(orpPin); //read an analog value every 20ms
if (orpArrayIndex==ArrayLenth) {
orpArrayIndex=0;
}
orpValue=((30*(double)VOLTAGE*1000)-(75*avergearray(orpArray, ArrayLenth)*VOLTAGE*1000/1024))/75-OFFSET; //convert the analog value to orp according the circuit
}
if(millis() >= printTime) //Every 800 milliseconds, print a numerical, convert the state of the LED indicator
{
printTime=millis()+800;
Serial.print("ORP: ");
Serial.print((int)orpValue);
Serial.println("mV");
digitalWrite(LED,1-digitalRead(LED));
}
}
![userHeadPic](https://dfimg.dfrobot.com/dfPortrait2.png)