// void setup(){
//   Serial.begin(9600);
// }

// void loop(){
//   int read_adc = analogRead(A0);
//   float voltage = read_adc * (5.0 / 1023.0);
//   Serial.print("Voltage V: ");
//   Serial.print(voltage);
//   Serial.println();

//   float current_millis = (voltage / 250) * 1000;
//   Serial.print("Current mA: ");
//   Serial.print(current_millis);
//   Serial.println();

//   // convert millis into sensor value
//   float sensor_value_mgl = (current_millis - 4) / 0.5;
//   Serial.print("Sensor Level: ");
//   Serial.println(sensor_value_mgl);
//   delay(500);
// }


#define REFERENCE_INPUT_VOLTAGE   5.0            // 5VDC
#define RESISTOR_VALUE            250            // 250 Ohm 1W
#define SENSOR_PH_PIN             A0
#define ANALOG_RESOLUTION         1023

#define PH_MIN_VALUE 0
#define PH_MAX_VALUE 14

void setup() {
  Serial.begin(9600);
}

void loop() {
  int read_adc = analogRead(SENSOR_PH_PIN);  // 10-bit resolution
  float reading_voltage = read_adc * (REFERENCE_INPUT_VOLTAGE / ANALOG_RESOLUTION);
  float reading_current_millis = (reading_voltage / RESISTOR_VALUE) * 1000;
  Serial.print("Millis: ");
  Serial.println(reading_current_millis);

  float proportion = (reading_current_millis - 4.0) / (20.0 - 4.0);
  float sensor_value = PH_MIN_VALUE + proportion * (PH_MAX_VALUE - PH_MIN_VALUE);
  Serial.println(sensor_value);
  delay(500);
}