Go Down

Topic: Trouble understanding some arithmetic in my code for an EC sensor A1003v1  (Read 489 times) previous topic - next topic

BearManTooth

I tried to contact the distributor but there contact tab doesn't seem to be functional

Can some one please help me understand the values used to convert from analogInPin to analogRead

My end goal is to convert this EC value into PPM

Code: [Select]


void setup() {
 



const int analogInPin = A1; 
const int analogOutPin = 9;

int sensorValue = 0;       
int outputValue = 0;       

 
  Serial.begin(9600);
}

void loop() {
 
sensorValue = analogRead(analogInPin);           
  // map it to the range of the analog out:
                                                               outputValue = map(sensorValue, 0, 1023, 0, 5000); 
  // change the analog out value:
  analogWrite(analogOutPin, outputValue);           

  // print the results to the serial monitor:
  Serial.print("sensor = " );                       
  Serial.print(sensorValue);     
  Serial.print("\t EC = ");     
                                                                Serial.println(analogRead(1)* 5.00 / 1024, 2); 

  // wait 10 milliseconds before the next loop
  // for the analog-to-digital converter to settle
  // after the last reading:
  delay(500);                     
}


el_supremo

You've used code tags correctly before. How did you get it so wrong this time?
And changing the text colour to yellow is a disaster. It's unreadable.

Pete
Don't send me technical questions via Private Message.

BearManTooth

lol yeah I noticed and im not sure how I screwed that code tag up so hard. 

el_supremo

Where did you get that code from? It doesn't compile, so maybe the conversions are rubbish.
This bit doesn't make sense:
Code: [Select]
  outputValue = map(sensorValue, 0, 1023, 0, 5000);
  // change the analog out value:
  analogWrite(analogOutPin, outputValue);

it is converting the sensor value from a range of 0-1023 to a range of 0-5000 and then outputting that value with analogWrite. The problem is that analogWrite only takes an 8-bit value on 328-based Arduinos. So which Arduino is this written for?

Pete
Don't send me technical questions via Private Message.

wvmarle

For NaCl solutions, EC 1 mS/cm is approx. 500 ppm.

For typical hydroponic fertiliser solutions, EC 1 mS/cm is approx 700 ppm.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up