De-coupling.

Hi friends, i have 3 sensors which i can get accurate readings until i wire another tempreature sensor.
Even if i connect its GND pin to Arduino, results become inaccurate.

Grumpy_Mike suggested me to use 0.1uF decoupling capacitors and gave me a link (some schematics and explanation) about it. I think i understand how to use but i am not sure and i don't want to burn another circuit anymore :slight_smile:

Can you please tell me how to use this capasitors to prevent inaccurate readings?

By the way thanks to Grumpy_Mike because of his great help.

Thanks

there are many locations that de-coupling capacitors "may" do some good. The first one I see from your photo, put a couple on the bread board, between the +5 and ground. The second place may be between the analog input pins, and ground.
Did those help?

Ok, should i use just a capacitor or double ?

Sorry :slight_smile:

If you have several use 2 (or 3) the more you use does not hurt, and may actually help.

I used them like this (attached). But never helped at all. Readings are much far from accurate :slight_smile:

How about if you take all but one of these out of circuit? Does the one left give a expected reading?

Just one sensor (PH) and the GND pin of Temp. sensor. I can't take accurate readings.

As soon as i wire the GND i get inaccurate readings..

A mystery.. what do you think it could be?
How about putting one of those caps across the ground to analog in?
Can you format your sketch, and show it in code tags? ( button looks like #).

String PHsensorString = "";
boolean PHsensorStringComplete = false;
String PHValueString = "";
float PHValueFloat = 0;

String TMPsensorString = "";
String TMPValueString = "";
float TMPsensorStringComplete = false;

void setup(){
  Serial.begin(38400);
  Serial1.begin(38400);
  Serial2.begin(38400);

  PHsensorString.reserve(30);
  TMPsensorString.reserve(30);
}

void serialEvent1() {
  if(Serial1.available() > 0){
    char inchar = (char) Serial1.read(); 
    PHsensorString += inchar; 
  
  if(inchar == '\r'){
    char charray[PHsensorString.length() + 1];  
    PHValueString = PHsensorString;
    PHValueString.trim();
    PHsensorString.toCharArray(charray, sizeof(charray));
    PHValueFloat = atof(charray);
    PHsensorStringComplete = true;
}}}

void serialEvent2() {
  if(Serial2.available() > 0){
    char inchar = (char) Serial2.read(); 
    TMPsensorString += inchar; 
    
  if(inchar == '\r'){
      TMPValueString = TMPsensorString;
      TMPValueString.trim();
      TMPsensorString = 0;
      TMPsensorStringComplete = true;
}}}

void loop() { 
  if(PHsensorStringComplete == true){
    Serial.print("PH: ");
    Serial.println(PHValueString);
    PHsensorString = "";                                                       
    PHsensorStringComplete = false;
  }
  
  if(TMPsensorStringComplete == true){
    Serial.print("TMP: ");
    Serial.println(TMPValueString);
    TMPsensorString = "";                                                       
    TMPsensorStringComplete = false;
  }


}

beingobserver:
Grumpy_Mike suggested me to use 0.1uF decoupling capacitors

That's his answer to everything :roll_eyes:

To be fair, he's been right every time as well :wink:

He must be :slight_smile:

But i don't know what is the problem.

Sorry friends but do you have any other idea?

How can i test step by step? Firstly i thought its a power issue but Grumpy_Mike and some other friends told me its not.
I tried de-coupling as you can see above.

Note: I have an avometer :slight_smile:

In looking at your sketch, I must have missed where your are reading your input.
Can you make a short sketch that demonstrates your problem?

all gnds connected for all components? (tie them together)

any +3.3v LOGIC devices? (not being level shifted?)

decoupling caps on ALL power pins, on all components?

We are here to help. We enjoy providing suggestions (even if our suggestions are not always the answer). We should be patient, a step at a time.
Another suggestion (may not fix it tho). If you are taking several analog readings (especially if they are close together), try using two reads. First read to be discarded, then the second one to be used.
A second suggestion: do some averaging (smoothing) of your analog readings.

as far as I can see from the sketch, there are no analog readings, sensors values are sent via serial transmissions, right ?
BTW, what kind of "bad results" do you get ?
Are all your sensors fixed at 38400 bauds, or can you change the speed, and if yes, did you try a lower speed ?

@jack wp - i cleaned the code above. just PH and TMP sensor.

@xl97 now i have just 2 sensors. Both of 2 sensors can be work with 5v. I don't know too much about caps :slight_smile: Just put them there.

@alnath yes, as you can see the code from previous page, there is not any analog readings. I am using serial 1 and serial 2 ports.
38400 bauds is the rate of factory. All sensors came with this settings. I can't change the speed without using delay.

The Story:
First, i am wiring the PH sensor.
Results are good, 6.8 to 6.9 and so on..
I checked this result with the PH sheets. And i tried with low PH waters also like 1.0 to 2.0 etc.

Then when i wire the GND pin of the TMP sensor, PH value sticks to 7.0.
I am continuing to wire other cables and TMP results are accurate even if the PH is always 7.0.

Then i unwire the TMP sensor, i get "check probe" message repeatedly.

I am resetting the Arduino, uploading the code and unplug the usb for "several times" and i am getting the accurate readings again.

I think its weird :smiley:

Thank you

weird, yes .... maybe something wrong in the call of serialEvent() functions, but it seems to be a hardware issue .

do you have an oscilloscope ? you could see the signal, and probably see what happens

do you have a link to the sensors datasheet ?

edit : if it is a software problem, maybe you miss some bytes ? you could try, in the serialEventn() functions, to replace the if(serialn.available() ) with a while(serialn.available() ) - just make sure you get out of the loop before the string is full :wink: -

Actually, i can work with PH, ORP and DO sensors at the same time with the accurate results.
But when i wire this TMP sensor, things become weird :slight_smile:

I don't have an oscilloscope unfortunately. I wish i have one :s

You can find all the things about the circuits.
PH: https://www.atlas-scientific.com/product_pages/embedded/ph.html
TMP: https://www.atlas-scientific.com/product_pages/sensors/env-tmp-d.html

Addition: I tried with the "while" instead of if also. The same result :slight_smile:

thanks, I'll have a look .

did you check the +5V on each sensor with and without TMP sensor ?