controling relay with ph sensore

Hy guys,
i'm beginner to Arduino i connected Arduino,PH sensor and oled connections properly. But My output of ph sensor is coming ph value is 0 as well as i,m getting voltage also 0 below is my code please help me out

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>

#define SensorPin 0 // the pH meter Analog output is connected with the Arduino's Analog
unsigned long int avgValue; //Store the average value of the sensor feedback
float b;
int buf[10],temp;

// OLED display height, in pixels
// Reset pin # (or -1 if sharing reset pin)
#define OLED_RESET 4
Adafruit_SH1106 display(OLED_RESET);

void setup()
{
pinMode(13,OUTPUT);
Serial.begin(9600);
Serial.println("Ready"); //Test the serial monitor

display.begin(SH1106_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
// init done

// Show image buffer on the display hardware.
// Since the buffer is intialized with an Adafruit splashscreen
// internally, this will display the splashscreen.
display.display();
delay(2000);

// Clear the buffer.
display.clearDisplay();

display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(0,5);
display.print("PH Sensor");
display.display();
delay(3000);

}
void loop()
{
for(int i=0;i<10;i++) //Get 10 sample value from the sensor for smooth the value
{
buf*=analogRead(SensorPin);*

  • delay(10);*
  • }*
  • for(int i=0;i<9;i++) //sort the analog from small to large*
  • {*
  • for(int j=i+1;j<10;j++)*
  • {*
    _ if(buf*>buf[j])_
    _
    {_
    _ temp=buf;
    buf=buf[j];
    buf[j]=temp;
    }
    }
    }
    avgValue=0;
    for(int i=2;i<8;i++) //take the average value of 6 center sample*

    avgValue+=buf*;
    float phValue=(float)avgValue5.0/1024/6; //convert the analog into millivolt_

    _ phValue=3.5phValue; //convert the millivolt into pH value_
    _ Serial.print(" pH:");
    Serial.print(phValue,2);
    Serial.println(" ");*_

* display.clearDisplay();*
* display.setTextSize(2);*
* display.setCursor(20,0);*
* display.println("Ph Value");*

* display.setTextSize(3);*
* display.setCursor(30,30);*
* display.print(phValue);*

* display.display(); *

* digitalWrite(13, HIGH); *
* delay(800);*
* digitalWrite(13, LOW); *

}

Please follow the advice on posting code given in posting code

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

Sir, in IDE the code in standard format only just i change the format while posting here

@grurajnayak - I got your PM

The code probably looks OK in the IDE as you say, but because you did not use code tags when posting it here it has been mangled because it contains HTML tags as part of teh code, probably [­i] Please read the link that I gave and post your code using code tags

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>
 
#define SensorPin 0        // the pH meter Analog output is connected with the Arduino’s Analog
unsigned long int avgValue;  //Store the average value of the sensor feedback
float b;
int buf[10],temp;
 

 // OLED display height, in pixels
 // Reset pin # (or -1 if sharing reset pin)
#define OLED_RESET 4
Adafruit_SH1106 display(OLED_RESET);


 
void setup()
{
  pinMode(13,OUTPUT);  
  Serial.begin(9600);  
  Serial.println("Ready");    //Test the serial monitor
 
  display.begin(SH1106_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)
  // init done
  
  // Show image buffer on the display hardware.
  // Since the buffer is intialized with an Adafruit splashscreen
  // internally, this will display the splashscreen.
  display.display();
  delay(2000);

  // Clear the buffer.
  display.clearDisplay();
 
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(0,5);
display.print("PH Sensor");
display.display();
delay(3000);
  
}
void loop()
{
  for(int i=0;i<10;i++)       //Get 10 sample value from the sensor for smooth the value
  { 
    buf[i]=analogRead(SensorPin);
    delay(10);
  }
  for(int i=0;i<9;i++)        //sort the analog from small to large
  {
    for(int j=i+1;j<10;j++)
    {
      if(buf[i]>buf[j])
      {
        temp=buf[i];
        buf[i]=buf[j];
        buf[j]=temp;
      }
    }
  }
  avgValue=0;
  for(int i=2;i<8;i++)                      //take the average value of 6 center sample
    avgValue+=buf[i];
  float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt
  phValue=3.5*phValue;                      //convert the millivolt into pH value
  Serial.print("    pH:");  
  Serial.print(phValue,2);
  Serial.println(" ");
  
  display.clearDisplay();
  display.setTextSize(2);
  display.setCursor(20,0);
  display.println("Ph Value");
 
  display.setTextSize(3);
  display.setCursor(30,30);
  display.print(phValue);
 
  display.display(); 
 
  digitalWrite(13, HIGH);       
  delay(800);
  digitalWrite(13, LOW); 
 
}

well done posting code as codesection. You might consider re-editing your first post to have it there as a code-section as well.

There is an automatic function for doing this inthe Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy to forum"
  3. paste clipboard into write-window of a posting

back to your problem:

Do you have a digital multimeter to measure the voltage of the PH-sensor?
Most ph-meter-sensors must be calibrated and are sensitive to wrong use.
Can you provide a datasheet of the ph-Meter.

best regards Stefan

Hi guys i'm new to arduino plz help me
i'm doing one project using arduino so i need a coding of contolling of relay using ph meter
for example if the PH value is come to 7 or 7.1 the relay should other wise the rely should off plz help me out to get the project done
thank you

grurajnayak:
Hi guys i'm new to arduino plz help me
i'm doing one project using arduino so i need a coding of contolling of relay using ph meter
for example if the PH value is come to 7 or 7.1 the relay should other wise the rely should off plz help me out to get the project done
thank you

so little information you share.... :roll_eyes:

  1. please post your code you have so far.
  2. details about the sensor you are using would also be helpful.

...

Topics on the same subject merged

#include Wire.h
#include Adafruit_GFX.h
#include Adafruit_SH1106.h
#define SensorPin 0
#define echoPin 2
#define trigPin 3
#define OLED_RESET 6
Adafruit_SH1106 display(OLED_RESET);
const int valvepin = 4;water walve
const int pumppin = 9;stirrer
const int valvepin1 = 10;valve at the output
unsigned long int avgValue; 
float b;
long duration;
int distance;
int distance1;
int flag = 0;
int sound = 5;
int redled = 7;
int greenled = 8;
int buf[10],temp;
float ph1;
void setup() {
  pinMode(greenled,OUTPUT);
  pinMode(redled,OUTPUT);
  pinMode(sound, OUTPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(valvepin, OUTPUT);
  pinMode(pumppin, OUTPUT);
  pinMode(valvepin1, OUTPUT);

  digitalWrite(valvepin,LOW);
  digitalWrite(pumppin, LOW);
  digitalWrite(valvepin1, LOW);
  Serial.begin(9600);
  Serial.println(Precious Metal Chemical Manufacturing Process Optimization Using IOT  );
  Serial.println(System Booting);
  Serial.println(Ready);
  display.begin(SH1106_SWITCHCAPVCC, 0x3C); 
  display.display();
  delay(2000);
  display.clearDisplay();
  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(2);
  display.setCursor(0,5);
  display.print(PH Sensor);
  display.display();
  delay(3000);
}
void loop() {

for(int i=0;i10;i++)       Get 10 sample value from the sensor for smooth the value
  { 
    buf[i]=analogRead(SensorPin);
    delay(10);
  }
  for(int i=0;i9;i++)        sort the analog from small to large
  {
    for(int j=i+1;j10;j++)
    {
      if(buf[i]buf[j])
      {
        temp=buf[i];
        buf[i]=buf[j];
        buf[j]=temp;
      }
    }
  }
  avgValue=0;
  for(int i=2;i8;i++)                      take the average value of 6 center sample
    avgValue+=buf[i];
  float phValue=(float)avgValue5.010246; convert the analog into millivolt
  phValue=3.5phValue;                      convert the millivolt into pH value
  Serial.print(    pH);  
  Serial.print(phValue,2);
  Serial.println( );
  
  display.clearDisplay();
  display.setTextSize(2);
  display.setCursor(20,0);
  display.println(Ph Value);
 
  display.setTextSize(3);
  display.setCursor(30,30);
  display.print(phValue);
 
  display.display(); 

    
  valve at the end should be close so that pressure will develop
  digitalWrite(valvepin1, LOW);
  distance1 = get_distance(); Read Ultrasonic Sensor
   to let the water flow inside tank1 valve should be opened
  digitalWrite(valvepin,LOW);
   digitalWrite(pumppin,LOW);
  if(distance1 = 10){
    digitalWrite(valvepin, LOW); turn off the valve
    digitalWrite(valvepin1, HIGH); let the water flow

    naoh solonoid valve will open 
    if(distance1 =5){
      naoh solonoid valve will close
      digitalWrite(pumppin, HIGH);
      delay(1000);
      digitalWrite(pumppin,LOW);
      delay(1000);
    
      stirrer will turn on 
     
         for(;;)
         {}
      }
      
    }
  }
delay(500); 
}
 


int get_distance(){
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);   
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance= duration0.0342;
  Serial.print(Distance in cm );
  Serial.println(distance);
  return distance;
}
  for (int i = 0; i10; i++)       Get 10 sample value from the sensor for smooth the value

No!

then what is the proper code will mu plz send me proper one

grurajnayak:
then what is the proper code will mu plz send me proper one

Look for yourself at how to write a for loop in any C tutorial

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.