PH4502C-Sensor
Loading...
Searching...
No Matches
ph4502c_sensor.cpp
1#include <Arduino.h>
2#include "ph4502c_sensor.h"
3
5 pinMode(this->_ph_level_pin, INPUT);
6 pinMode(this->_temp_pin, INPUT);
7}
8
9void PH4502C_Sensor::recalibrate(float calibration) {
10 this->_calibration = calibration;
11}
12
14 float reading = 0.0f;
15
16 for(int i = 0; i < this->_reading_count; i++) {
17 reading += analogRead(this->_ph_level_pin);
18 delayMicroseconds(this->_reading_interval);
19 }
20
21 reading = PH4502C_VOLTAGE / this->_adc_resolution * reading;
22 reading /= this->_reading_count;
23 reading = this->_calibration + ((PH4502C_MID_VOLTAGE - reading)) / PH4502C_PH_VOLTAGE_PER_PH;
24
25 return reading;
26}
27
29 float reading = analogRead(this->_ph_level_pin);
30
31 reading = PH4502C_VOLTAGE / this->_adc_resolution * reading;
32 reading /= this->_reading_count;
33
34 return this->_calibration + ((PH4502C_MID_VOLTAGE - reading)) / PH4502C_PH_VOLTAGE_PER_PH;
35}
36
38 return analogRead(this->_temp_pin);
39}
int read_temp()
Read the temperature from the sensor.
void recalibrate(float calibration)
Recalibrate the sensor with a new calibration value.
float read_ph_level()
Read and calculate the pH level.
void init()
Initialize the PH4502C sensor.
float read_ph_level_single()
Read and calculate the pH level without averaging multiple readings.
Arduino Library for PH4502C Sensor.
#define PH4502C_VOLTAGE
Operating voltage for the PH4502C sensor.
#define PH4502C_PH_VOLTAGE_PER_PH
Rate of change in voltage per unit change in pH.
#define PH4502C_MID_VOLTAGE
Voltage that represents a neutral pH reading (pH = 7).