Sensor PH and EC


#1

Hello

I keep advancing with the theme of the garden: D
I have these meters of ph and ec and I need to know what to put in the code to get me on your platform!

The model of ph is A1004v2 and that of ec is A1003v1

const int analogInPin = A2; // Analog input pin that the sensor is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}

void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 14);
// change the analog out value:
analogWrite(analogOutPin, outputValue);
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(analogRead(2)* 14.0 / 1024, 1);
// wait 10 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(500);
}

#2

With this code I read the sensor from the dashboard but it does not give me the correct readings I get PH 512

// thinger.io config
ThingerEthernet thing("maxcat", "arduino", "***");

void setup() {

    pinMode(A0, INPUT);

    // LDR resource
    thing["LDR"] >> [](pson & out){
        out = (unsigned int) analogRead(A0);
    };
}

void loop() {
  thing.handle();
}

#3

Hi @maxcat, without thinger, what is the correct code that reads and print to serial the expected sensor value? Then we can include that inside any resource. Just think that you need to set this value to the out variable.

Random example:

// example resource
thing["example"] >> [](pson & out){  
  int sensorValue = analogRead(analogInPin);
  // do whatever you want with the value!
  sensorValue = sensorValue* 14.0 / 1024;
  // set the value to the resource
  out = sensorValue;
};

Hope it helps!


#4

Hi Alvaro, I got the ec meter working with this change

void setup() {

pinMode(A2, INPUT);

thing[“Control EC”] >> [](pson & out){
unsigned int value = analogRead(A0);
out = ((1000-value)/500.0)*100;
};

thing[“Temperature”] >> [](pson & out) {
sensors.requestTemperaturesByIndex(0);
out = sensors.getTempCByIndex(0);
};

const int analogInPin = A0;

thing[“ph”] >> [](pson & out){
int sensorValue = analogRead(analogInPin);
// do whatever you want with the value!
sensorValue = sensorValue* 14.0 / 1024;
// set the value to the resource
out = sensorValue;
};
sensors.begin();
}

void loop() {
thing.handle();
}

I’d like to that PH has two decimal places to get it controlled. How could I do? Thank you
Thanks for your support Alvaro :smiley: