TMP36 reading inaccurate values on arduino

Status
Not open for further replies.

jpanhalt

Joined Jan 18, 2008
11,087
View attachment 211560

Is this setting more accurate to produce a better result than the one where i connect the heater ground to the arduino(image below)
in order to avoid ground noise
and should i connect a flyback diode in the process , of which i don't understand the need ?
View attachment 211484
That latest schematic is not going to work. The mosfet source must be referenced to the same ground as the gate. You still have a diode in the sensor ground.
 

Reloadron

Joined Jan 15, 2015
7,517
RR, while there can be a connection between the analog input common line and "ground", system common,, simply tying the analog signal common will not be the best choice. It is fine in power circuits where a few millivolts of noise will not matter, but signal circuits must avoid power current flowing in any of their conductors.
Maybe this would go better if you had a board just like he is using laying in front of you. Then just maybe you would understand there is no analog ground. The board uses an Atmega 328P (Micro Chip) which does not have for example Analog Ground, Digital Ground and Ground. All it has is Ground. This is the data sheet. The project board, an Arduino Uno has 6 Analog Input pins labeled A0 through A5 and three pins labeled GND which are all bonded to the uC GND pins as seen in the data sheet. So there is but a single Ground as far as the board is concerned. The analog signal common for all six analog channels which are multiplexed is Gnd and that is all there is. The same ground which is ground for all of the Digital In / Out lines and power supply ground.

I made a suggestion several post back that the thread starter try to eliminate the digital out stuff for now and just get the analog in portion working and reading temperature. There isn't much to it. A three pin temp sensor using Vcc, GND and Sig or Vout. If wired correctly and a known good sensor it should work.

Ron
 

Thread Starter

Kadav

Joined May 11, 2018
158
As mentioned by others, personally, I'd wire the ground wire from the heater back direct to the power supply only.
And the Arduino ground direct back via another wire to the power supply.
can you please explain me how to do this i do not get it well
 

Reloadron

Joined Jan 15, 2015
7,517
Your heater is a 12 volt heater according to your drawing. Can we assume a separate power sup[ply for the heater? If the heater element is a source of noise and there is concern about noise I would consider the use of an optocoupler and just isolate the load and be done with it. Come off your Arduino Digital Out and drive an optocoupler. Have you looked at anything on a scope? We seem to be chasing possible ground problems and there is no way to know for sure why you are getting erratic temperature readings. Have you looked at your sensor Vout? Would that be stable?

While it will likely work because it has a low Vthreshold voltage have you looked at the data sheet for the IRF520 MOSFET? That MOSFET is a poor choice using a 5 volt gate signal. Read the data sheet! Consider a MOSFET like the IRL 540 Logic Level MOSFET which is designed for applications like you have. I am not saying the IRF520 will not work, I am saying it is a poor choice in this application.

If you want isolation then consider using an optocoupler and separating your heater ground and control circuit ground. You are using an N Channel MOSFET so if you don't want to use an optocoupler I would place a 220 Ohm resistor between your Arduino D) pin and your MOSFET Gate. I would place a 10K resistor between MOSFET Gate and ground to make sure when you go low on your DO pin the MOSFET turns off. You write your code accordingly, logic high MOSFET (Heater) On logic low MOSFET (Heater) Off. You are low side switching the heater element.

Ron
 

dendad

Joined Feb 20, 2016
4,476
Depending on your Arduino board type, there is an internal reference voltage for the ADC available.
https://www.arduino.cc/en/Reference.AnalogReference
Some processors have 1.1V and others 2.56V. The default ref is the 5V (or 3.3V) processor power, or you can also select to use the external pin.
analogReference(INTERNAL) will select it, analogReference(DEFAULT) for the supply volts and analogReference(EXTERNAL) for the pin.
Just take into concideration the readings will be different depending on the Vref voltage being used.
But back to the gnd discussion.
The gnd pins on the Arduino are all connected together on the board, but use a separate one for the temp sensor. This is to prevent any currents other that those of the temperature sensor flowing on the wires of the sensor. You are trying to measure small voltage changes and currents from the switching will cause small voltage drops in the wires and that will alter your readings if they are picked up.
Always keep analog and digital paths separate if you can.
And get rid of that diode. If you want the diode so you can read lower temps, you then need another analog input to read the voltage between the diode and the temp sensor and work that into the temperature calculations.

My scanner is busted otherwise I would draw it ;)
 

MisterBill2

Joined Jan 23, 2018
18,519
Are we being "Trolled?" The TS has shown us a circuit that contains all of the connections and yet claims to not understand about dividing power connections from signal connections.
That is so very "Nuts and Volts", providing a circuit without one word about what is going on. Several of us have posted detailed descriptions of both the mechanism of the problem and also how to avoid the problem. And the response is "I don't understand".
So I suggest put the arduino in a box and put it away and get some books on basic electricity and electronic circuits and then read and learn about circuits and current flow and voltage drops.
I have spent time carefully wording explanations and so have others and all to no apparent benefit for the TS, who claims to not understand.
 

Reloadron

Joined Jan 15, 2015
7,517
Are we being "Trolled?" The TS has shown us a circuit that contains all of the connections and yet claims to not understand about dividing power connections from signal connections.
That is so very "Nuts and Volts", providing a circuit without one word about what is going on. Several of us have posted detailed descriptions of both the mechanism of the problem and also how to avoid the problem. And the response is "I don't understand".
So I suggest put the arduino in a box and put it away and get some books on basic electricity and electronic circuits and then read and learn about circuits and current flow and voltage drops.
I have spent time carefully wording explanations and so have others and all to no apparent benefit for the TS, who claims to not understand.
No we are not being trolled. The same post was placed in the Arduino forums. What we are seeing is the result of millions of "kits" and modular boards being marketed. Combine that with a group of enthusiast who choose to learn to swim in the deep end of the pool. Combine that with Fritzing and the problems become apparent leading to post and threads just like this one. We see them daily and while I agree every hobby enthusiast needs to start somewhere the beginning is a much better somewhere than the middle. Make me a drawing, write my code. I don't understand.

Ron
 

jpanhalt

Joined Jan 18, 2008
11,087
I agree. It seems pretty obvious changes being made by the TS result from the blind leading the blind on other forum(s). There is no reason for addition of a diode in the ground from the sensor and isolation of the mosfet ground from the gate ground (post #39), yet those changes suddenly appeared.
 

MisterBill2

Joined Jan 23, 2018
18,519
What is so complicated about the concept of using seperate wires for different parts of a circuit? Why is that hard to understand? I learned all about that from a seventh grade science teacher way back in 1960, or 1959.
That analysis method was simple, just imagine every wire as a resistor and then see what currents produce voltage drops in each wire. Then look at the sums. Not any real math and not much in the line of algebra. Just a bit of thinking.
 

SamR

Joined Mar 19, 2019
5,045
I need to see if I made any notes because I had the same issue with either the TMP36 or the LM35. One worked fine with the proper scaling in the code and the other "danced" just as you say. Arduino has the ability to port the raw input value out to its serial monitor to see just what is going on with the input and screen print it as it is read in. It was very inconsistent. Yes, you could average it but GIGO. Anything else can be scaled to fit in the code. I often had to make corrections to scaling from what the "book code" was to correct for real inputs. That can't fix broke. And yes, a lot of Arduino learning is "Monkey See, Monkey Do" unless you engage your brain in the process. Nope, didn't find it in my main notebook. Ah well, note to self, take better notes!
 

djsfantasi

Joined Apr 11, 2010
9,163
Has anyone tried the change to define sensorPin as A0; NOT 0?

Arduino analog pins are defined by the constants A0 through A7 (depending on the board). These constants map to the physical pins on the Arduino. Read the Arduino reference page for the analogRead() command.

Pin 0 (physical) on an Arduino is RX Data; nothing to do with analog input.
sensorPin = A0;
 

Reloadron

Joined Jan 15, 2015
7,517
Has anyone tried the change to define sensorPin as A0; NOT 0?

Arduino analog pins are defined by the constants A0 through A7 (depending on the board). These constants map to the physical pins on the Arduino. Read the Arduino reference page for the analogRead() command.

Pin 0 (physical) on an Arduino is RX Data; nothing to do with analog input.
sensorPin = A0;
I did that just out of curiosity and it didn't matter. The code loaded and ran fine using A0 or 0. I ran his code and it worked as well as a few variations. I did not have the TMP35 sensor so just applied simulated voltages and it always worked. I suggested something is not wired correctly which is difficult since all of the temperature measuring consist of three wires. Anyway it did surprise me as to using 0 or A0 but either reference works. I even suggested removing all of the digital out side and just trying to measure temp and see if they get a stable display. Can't help those who won't help themselves was my final conclusion.

Ron
 

SamR

Joined Mar 19, 2019
5,045
I did that just out of curiosity and it didn't matter. The code loaded
The code doesn't care whether you point to a digital or analog pin so it compiles and runs either way. But you won't get the input to the code from A0 if you tell it 0... Sigh... I'm being lazy again and don't want to drag a card out and play.:(
 

Thread Starter

Kadav

Joined May 11, 2018
158
Excuse Me sorry . i am not trollin
I did that just out of curiosity and it didn't matter. The code loaded and ran fine using A0 or 0. I ran his code and it worked as well as a few variations. I did not have the TMP35 sensor so just applied simulated voltages and it always worked. I suggested something is not wired correctly which is difficult since all of the temperature measuring consist of three wires. Anyway it did surprise me as to using 0 or A0 but either reference works. I even suggested removing all of the digital out side and just trying to measure temp and see if they get a stable display. Can't help those who won't help themselves was my final conclusion.

Ron
I did that and i said it was working . and you gave me an idea of isolating using an optocoupler , which is what i will do when i get to the lab and that as well .

and for the information i am not trolling . i am actually doing a master's of electronics project , which i am a student in electronics . but i have never done a project before where i have to work with the components on my own . Yes this discussions help me soo much and i am very thankful.

If i tell you that i don't understand the concept is really that i don't understand it. some things might be obvious to you who is a well rounded proffessional . but might not be to someone like me
again im sorry if you feel trolled

GBU
 

djsfantasi

Joined Apr 11, 2010
9,163
I did that just out of curiosity and it didn't matter. The code loaded and ran fine using A0 or 0. I ran his code and it worked as well as a few variations. I did not have the TMP35 sensor so just applied simulated voltages and it always worked. I suggested something is not wired correctly which is difficult since all of the temperature measuring consist of three wires. Anyway it did surprise me as to using 0 or A0 but either reference works. I even suggested removing all of the digital out side and just trying to measure temp and see if they get a stable display. Can't help those who won't help themselves was my final conclusion.

Ron
I’m surprised that it worked. Of course, “well, it works when I did it that way” isn’t a great decision when you’re trying to do something that is undocumented. Maybe the compiler is sloppy, but if the compiler is updated, using an undocumented approach may break.

Has the TS mentioned what version of the IDE he is running? And what version do you use?
 

Reloadron

Joined Jan 15, 2015
7,517
I’m surprised that it worked. Of course, “well, it works when I did it that way” isn’t a great decision when you’re trying to do something that is undocumented. Maybe the compiler is sloppy, but if the compiler is updated, using an undocumented approach may break.

Has the TS mentioned what version of the IDE he is running? And what version do you use?
No and he disappeared here as quickly as the other forum. There was never any mention of the IDE version so I haven't a clue. I believe we all know just because something works is no reason to use it and that holds true for code as well as components. What I see happening is the thread starter just got in over his or her head leaving questions by those who try to help them unanswered. The IDE I used is 1.8.12 on an Arduino Uno Rev 3 board. Again too, surprise me. :)

Ron
 
Status
Not open for further replies.
Top