Arduino Forum

Using Arduino => General Electronics => Topic started by: beingobserver on Sep 06, 2013, 01:04 am

Title: De-coupling.
Post by: beingobserver on Sep 06, 2013, 01:04 am
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 :)

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
Title: Re: De-coupling.
Post by: jack wp on Sep 06, 2013, 01:21 am
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?
Title: Re: De-coupling.
Post by: beingobserver on Sep 06, 2013, 01:24 am
Ok, should i use just a capacitor or double ?

Sorry :)
Title: Re: De-coupling.
Post by: jack wp on Sep 06, 2013, 01:27 am
If you have several use 2 (or 3) the more you use does not hurt, and may actually help.
Title: Re: De-coupling.
Post by: beingobserver on Sep 06, 2013, 01:36 am
I used them like this (attached). But never helped at all. Readings are much far from accurate :)
Title: Re: De-coupling.
Post by: jack wp on Sep 06, 2013, 01:39 am
How about if you take all but one of these out of circuit? Does the one left give a expected reading?
Title: Re: De-coupling.
Post by: beingobserver on Sep 06, 2013, 01:48 am
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..
Title: Re: De-coupling.
Post by: jack wp on Sep 06, 2013, 01:55 am
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 #).
Title: Re: De-coupling.
Post by: beingobserver on Sep 06, 2013, 02:13 am
Code: [Select]
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;
 }


}
Title: Re: De-coupling.
Post by: GilchristT on Sep 06, 2013, 11:41 am

Grumpy_Mike suggested me to use 0.1uF decoupling capacitors

That's his answer to everything  :smiley-roll:

To be fair, he's been right every time as well  ;)
Title: Re: De-coupling.
Post by: beingobserver on Sep 06, 2013, 01:04 pm
He must be :)

But i don't know what is the problem.
Title: Re: De-coupling.
Post by: beingobserver on Sep 06, 2013, 11:08 pm
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 :)
Title: Re: De-coupling.
Post by: jack wp on Sep 06, 2013, 11:16 pm
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?
Title: Re: De-coupling.
Post by: xl97 on Sep 06, 2013, 11:22 pm
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?

Title: Re: De-coupling.
Post by: jack wp on Sep 06, 2013, 11:37 pm
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.
Title: Re: De-coupling.
Post by: alnath on Sep 06, 2013, 11:48 pm
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 ?
Title: Re: De-coupling.
Post by: beingobserver on Sep 07, 2013, 01:08 am
@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 :) 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 :D

Thank you
Title: Re: De-coupling.
Post by: alnath on Sep 07, 2013, 01:34 am
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 ;) -
Title: Re: De-coupling.
Post by: beingobserver on Sep 07, 2013, 01:43 am
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 :)

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 :)
Title: Re: De-coupling.
Post by: alnath on Sep 07, 2013, 01:57 am
thanks, I'll have a look .

did you check the +5V on each sensor with and without TMP sensor ?
Title: Re: De-coupling.
Post by: beingobserver on Sep 07, 2013, 02:01 am
I can say that its the same with or without the TMP sensor.

4.70 to 4.75. Its changing in this range.
Title: Re: De-coupling.
Post by: alnath on Sep 07, 2013, 02:30 am
ph circuit seems to need a particularly clean environment and doesn't like interferences  :smiley-eek:
maybe you could try to put it far from the TMP sensor , or even on a separate breadboard.....
and.... back to a decoupling capacitor, between its +5V and its GND (very close to the device)

what about the led indications ?
Title: Re: De-coupling.
Post by: jack wp on Sep 07, 2013, 02:55 am
Maybe a smoothing / averaging code would make it look better.
Average = ((average*5)+newReading)/6
or something like that.
Title: Re: De-coupling.
Post by: beingobserver on Sep 07, 2013, 11:23 am
@alnath I did you what you said. I used seperate breadboard and changed the position of capacitors (same result). Do you want me to turn off the leds?

@jack wp i could try smoothing the PH results but i never get any different value from 7.0.
This PH circuit is capable of measuring 0.1 to 14. So 7.0 is the half way of its range :D

I lost nearly a week with this. I have lots of things to do but can't move because my mind is stuck with this problem :)

Do i have to find an oscillator to test? Do you think i could find out the reason with that? I could try to find one.
Title: Re: De-coupling.
Post by: alnath on Sep 07, 2013, 11:39 am
no, I asked about the leds, because in the datasheet, they describe their meaning .

does the Ph circuit still works if alone ??

no more idea (for now  :smiley-mr-green:  ) I have an oscilloscope, so I'd use it to watch the signal Ph sensor sends,
but a logic analyser would be more useful here. If you can borrow one ..... ;)
Title: Re: De-coupling.
Post by: beingobserver on Sep 07, 2013, 11:43 am
PH led is blinking green, i think its ok.

Yes, PH is working good if i wire it alone.

Hmm, so i have to find one to borrow if i need one :) I have to make it work.
Title: Re: De-coupling.
Post by: TomGeorge on Sep 07, 2013, 12:03 pm
Hi, reading the posts is it right in stating that the readings you get are inaccurate not unstable when you install another sensor.
Where are you getting your power supply for the sensors, I hope not from the arduino 5V.  If this is the case then have you tried a separate power supply for the sensors?
You were asked about what the supply was measured at your sensors and I gather the 4.70 to 4.75V stated was the result.
It should be 5 volts if its coming from a regulated supply, again if its the 5V on the arduino board that you are using then I'd say you are overloading it regulator.
Tom.
Title: Re: De-coupling.
Post by: beingobserver on Sep 07, 2013, 01:11 pm
Yes, inaccurate readings when i connect the TMP sensor.

Yes, i am feeding the sensors with the Arduino :D I think i tried with external power supply in the past.
I can't remember because i tried tons of things :) I can try again if you want after seeing the values.

Please check the results, do you think there is something wrong?

Note: I am waiting someone to ban me from the forum :D
Title: Re: De-coupling.
Post by: alnath on Sep 07, 2013, 01:19 pm
TomGeorges might be right, I cannot see any electrical characteristics in the TMP sensor datasheet
the sensors are designed to work between 3,3V - 5V , then 4,7V should work,  but it should not vary ....

why would someone ban you ?  XD


edit : the ph circuit datasheet warns a lot about wrong wiring etc.... maybe you could try a +5V power supply just for it (but all GND connected) ?
Title: Re: De-coupling.
Post by: beingobserver on Sep 07, 2013, 01:32 pm
Actually it is varying but too little amounts. For example 4.75 to 4.80.

@alnath my topic is always at the top of General Electronics section :)

Thank you so much.
Title: Re: De-coupling.
Post by: beingobserver on Sep 07, 2013, 01:38 pm
Ok, i will try with seperate power source.
Title: Re: De-coupling.
Post by: beingobserver on Sep 07, 2013, 02:46 pm
I shot a short video with my elementary level english :)

PH circuit with Arduino.
PH circuit with External Power source.
TMP with external power source.

You can see the results.
http://www.youtube.com/watch?v=_Xx1StvEvBE
Title: Re: De-coupling.
Post by: alnath on Sep 07, 2013, 03:02 pm
OK
I saw you disconnect the GND wire . Why ?
GNDs should be connected together

In your video you didn't try Arduino + TMPsensor with one power supply (say arduino USB powered and TMP sensor powered from arduino 5V pin) ,
and PH-circuit with its own 5V power supply
But : All GNDs connected together
That's what I would try .

BTW, these are not really advice, I'm more on a  "here is what I would try ...... "  mode  ;)
Title: Re: De-coupling.
Post by: polymorph on Sep 07, 2013, 03:03 pm
All those big loops of wire are going to act like antennas. A microcontroller is a noisy thing. And your instability is very small.

Are you running that 5V regulator into the barrel jack on the Arduino? If so, that is meant to have at least 7V into it, as it is connected to a linear 5V regulator on board.

Also, the output from switching power supplies is notoriously noisy. Certainly the manufacturer of a charger isn't worried about making a source of clean 5V.

The sockets on an Arduino are made for those big square pins, and the thin wires meant for a protoboard are likely to not make the best electrical connection.

Ground wires are providing a path for both signal return and power return. This will affect what shows up at an analog pin, relative to ground at the AVR chip itself.

Plugging and unplugging wires from an Arduino without powering it off first is a risky thing to do.
Title: Re: De-coupling.
Post by: alnath on Sep 07, 2013, 03:43 pm

All those big loops of wire are going to act like antennas. A microcontroller is a noisy thing. And your instability is very small.
......
......
Plugging and unplugging wires from an Arduino without powering it off first is a risky thing to do.


at least 2 points I should have pointed out  :)   especially with that ph-circuit wich seems very sensitive to noise
always good to have "new eyes" on this  8)

Title: Re: De-coupling.
Post by: beingobserver on Sep 08, 2013, 07:22 pm
@alnath Understand the point, there must be common GND between external Power Source, Arduino and the circuit.

@polymorph Thanks for your suggestions. I am now powering off before wiring.

Now. I solved something :)
I burned that digital temperature sensor which includes an onboard memory.
(This is the second atlas-scientific part i burned)
Fortunately i had another one which is a basic analog model.

I am not using any external power, just using the Arduino for all PH, ORP, DO and TMP sensors.
They worked with the first try!!

Money is not my first concern actually but i am distressed because i don't know how i burned these 2 circuits (EC and Digital TMP).
I used maximum of 9v for the Arduino. And 5v for the external power sources.

Thank you

http://youtu.be/VqUmIBhD2wI

Title: Re: De-coupling.
Post by: Grumpy_Mike on Sep 09, 2013, 01:05 am
First off those capacitors are not ceramic ones, and even if they were the legs are far too long. The legs should be cut as short as possible and they should be mounted as close to those sensor boards as possible, not just stuck anywhere like you have them.

Next all four sensors are in the same liquid, can you do that? What happens if you connect all the sensors up but only put one at once into the water, does that change things?

You might have burned the sensors by messing about with the wiring when the power is on like you did in the video. Never change the wiring with the circuit when it is powered.
Title: Re: De-coupling.
Post by: beingobserver on Sep 09, 2013, 01:22 am
Quote
First off those capacitors are not ceramic ones

This mistake belongs to the seller not me :)

Quote
Next all four sensors are in the same liquid, can you do that?

Actually there are things i don't understand about the circuits. For example, if i don't connect the BNC connector, i can get the results anyway instead of saying "Check the Probe". So i am not so sure about the values. I will re-calibrate them with their solutions after finishing these things.

Quote
You might have burned the sensors by messing about with the wiring when the power is on

Yes, it was an expensive lesson for me.

So, i need to buy some ceramic caps. I have a long long long way to go.

I need to go to bed now because tomorrow is the first school day of my little princess :)

Thank you so much.
Title: Re: De-coupling.
Post by: Grumpy_Mike on Sep 09, 2013, 12:49 pm
Quote
For example, if i don't connect the BNC connector, i can get the results anyway instead of saying "Check the Probe".

Not sure what that means.

Good luck to the little princess.  :)
Title: Re: De-coupling.
Post by: dc42 on Sep 09, 2013, 02:50 pm
Is the temp sensor dipped in the same liquid as the ph sensor? (Please excuse me if that should be obvious from the photos, I'm using a smartphone and it is difficult to view them). The ph sensors I've seen only work when the liquid they are in is electrically isolated from ground, unless you isolate the ph sensor itself. Dipping a metal cased grounded temp sensor into the same liquid as the ph sensor would break the isolation.
Title: Re: De-coupling.
Post by: Grumpy_Mike on Sep 09, 2013, 02:57 pm
Quote
Is the temp sensor dipped in the same liquid as the ph sensor

Yes it is.

I have been trying to say that in this and the other thread the OP has.
Title: Re: De-coupling.
Post by: beingobserver on Sep 09, 2013, 05:19 pm
I am really surprised. And i found something confirming this. http://www.eutechinst.com/techtips/tech-tips7.htm

By the way ORP and DO sensors were affected also.

Analog TMP sensor also has a metal case but they are working. But the values might be inaccurate.
Hmm, i think i need to use seperate liquids. This info was critical. Thank you.