Arduino Interfacing with pH sensor diagram,working,code
This app note covers Arduino Interfacing with pH sensor diagram and its working. It describes pH sensor used and mentions arduino code.
Introduction:
As we know pH sensors are used in chemical labs for acidity test in order to determine nature of any liquid.
Acidity test consumes lot of time if it is done without the use of pH sensor.
Measurement of acidity test is very quick when pH sensor is interfaced with arduino board.
Let us understand the same in this application note.
About pH sensor
The sensor which detects hydrogen ion (H+) concentration of liquid is known as pH sensor. This indicates acidity or alkalinity of a liquid.
When pH sensor is immersed in liquid solution, smaller ions get penetrated in the boundary area of the glass membrane where as larger ions remain in the liquid solution. This develops potential difference. pH meter measures potential difference between electrodes.
As shown below pH sensor output is connected with analog read input of the arduino board. The pH sensor provides different analog outputs for different liquid solutions. By knowing pH value of known solution such as water one can easily determine pH value for other liquid solutions.
The pH meter with display can be constructed by interfacing LCD display with arduino and pH sensor with arduino.
About Arduino board
• Arduino Uno houses ATmega328 microcontroller from ATMEL. This microcontroller contains flash memory (32 KB), RAM (2 KB), 8 bit wide CPU and 1 KB EEPROM.
• It also supports 6 analog pins which reads voltage and not current. Inside, it converts analog measurement to digital for various purposes.
It supports digital pins (0 to 13) which can function either as input or output.
• It has various interfaces viz. I2C, digital pins, analog pins, serial communication, USB etc.
• It also has reset pin, power port, crystal oscillator and Tx/Rx LEDs.
• This open source prototype board can be easily programmed using easy to use arduino IDE and USB interfaced between
laptop PC and arduino board.
• IDE uses simplified C++ program.
• Board requires 5V DC which can be powered using AC/DC adapter or battery.
Arduino Interfacing with pH sensor diagram and its working
As shown in the figure-1, the three pins of pH sensor are connected with arduino board. The pH sensor is from ORP Meter.
Following are the connections between pH sensor and arduino board.
Vcc (+ pin of pH sensor side) - 5V (Arduino side)
GND (- pin of pH sensor side) - GND (Arduino side)
OUT (A pin of pH sensor side) - A1 (Arduino side)
Arduino pH sensor interface code
Following is the arduino code compiled and uploaded to the arduino board using Arduino IDE. Following code is used for testing pH sensor based ORP meter. This provides pH sensor readings on Arduino Serial Monitor.
#define OFFSET 0 //zero drift voltage
#define LED 13 //operating instructions
double orpValue;
#define ArrayLenth 40 //times of collection
#define orpPin 1 //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){
for(i=0;i
}
avg = amount/number;
return avg;
}else{
if(arr[0]
}
else{
min=arr[1];max=arr[0];
}
for(i=2;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)
{
printTime=millis()+800;
Serial.print("ORP: ");
Serial.print((int)orpValue);
Serial.println("mV");
digitalWrite(LED,1-digitalRead(LED));
}
}
Reference : https://wiki.dfrobot.com/Analog_ORP_Meter_SKU_SEN0165_
Conclusion: In this application note we have seen pH sensor interfacing with Arduino Uno board. Arduino board is also used for interfacing different types of sensors for applications. The typical sensors interfaced with arduino are sound sensor, gyro sensor, LDR sensor, GPS sensor, color sensor, heartbeat sensor etc.
IoT system on chip tutorial Related Links
Main tutorial IoT section IoT article Cellular IoT Components Sensors INDIAN companies Antenna Types Wireless technologies IoT transceiver SoC