LM335 Sensor controlled by transistor - Page 1
Forum section: electronics / beginners

author: ElCerrajero
author_rank: Newbie
timestamp: March 28, 2023, 06:25:57 pm
content: Hi, I'm working on creating a temperature sensor using the LM335. The first circuit in the image shows my current setup, which follows the configuration recommended in the datasheet. The output voltage is connected to an input pin.However, I would like the sensor to only turn on when I press a button and start the process of measuring the temperature. Additionally, I want the 5V power supply to come from an external power source rather than an Arduino pin. I tried using a transistor, but it doesn't seem to be working correctly.Is there a better way to achieve this, or am I missing something with the transistor connection?Circuit:https://imgur.com/a/VrQbXYN

author: BillyO
author_rank: Super Contributor
timestamp: March 28, 2023, 07:03:20 pm
content: Instead of the 2N3904, use a 2N3906 (PNP) and put it above R3 (emitter to 5V, collector to R3) . You will, of course, need a base resistor, maybe 5K to 10K. The 2N3906 will turn on when Vb is low.Also, the two circuits must share a ground.

author: shapirus
author_rank: Super Contributor
timestamp: March 28, 2023, 07:16:52 pm
content: Quote from: BillyO on March 28, 2023, 07:03:20 pmThis will require a voltage source of at least 4.4-4.5V to keep its base above the Vbe threshold. Arduino will only output 3.3V max which won't be enough to keep the PNP turned off.It can be solved by an additional NPN transistor whose base will be driven by the Arduino (via a resistor), emitter connected to GND, collector pulled up to +5V via a resistor and connected to the base of the PNP via another resistor. This will provide a reliable way of keeping the PNP turned off and turning it on by turning on the NPN by setting an Arduino pin high, which will pull the PNP's base to ground.(to OP: easier drawn than described, just play around in falstad and see how it works)

author: BillyO
author_rank: Super Contributor
timestamp: March 28, 2023, 07:40:18 pm
content: ??A typical Arduino WILL output 5V. I have half a dozen UNO's here an a couple of Megas, and they all work at 5V.What Arduino are you talking about?

author: shapirus
author_rank: Super Contributor
timestamp: March 28, 2023, 07:43:27 pm
content: Quote from: BillyO on March 28, 2023, 07:40:18 pmI stand corrected, then. I was assuming that its GPIO pins worked at the 3.3V logic level. Do they actually work at 5V? Yes, power is 5V, but GPIO? 5V as well?up: yes indeed, I googled for it: most Arduino boards operate at 5V GPIO voltage. Interesting. I assumed it was 3.3V as is typical for RPi and many other microcontrollers and SBCs.then yes, the PNP transistor can be controlled directly.

author: BillyO
author_rank: Super Contributor
timestamp: March 28, 2023, 07:48:05 pm
content: Yes, they will go pretty much right to the rail, being CMOS. However, that is load dependent.Your suggestion is probably a good one anyway and would improve the circuit even if it is not completely nesseccary.

author: ElCerrajero
author_rank: Newbie
timestamp: March 28, 2023, 08:35:44 pm
content: QuoteThank you, I will try it, but I have a question. Will the voltage drop of 0.2V in saturation in the transistor affect the LM335? Since this sensor changes its voltage to measure temperature.

author: BillyO
author_rank: Super Contributor
timestamp: March 28, 2023, 08:39:14 pm
content: Quote from: ElCerrajero on March 28, 2023, 08:35:44 pmNo, the LM335 has a constant current source internally. Just pick your series resistor for 1ma. It will be fine.

author: shapirus
author_rank: Super Contributor
timestamp: March 28, 2023, 08:49:03 pm
content: Quote from: ElCerrajero on March 28, 2023, 08:35:44 pmThis is why your original circuit doesn't work: the voltage drop across the transistor affects Vout, because it is placed between the sensor and ground: Vout = Vsensor + Vce_transistor.With a PNP transistor at the +5V rail, Vout isn't affected by anything. You still need to make sure that current flowing through the sensor stays within the allowed range, this is set by selecting the value of R3 appropriately.I recommend running a falstad or everycircuit or any other simulation to help you understand how the circuit works. It's a perfect (at least for the basic circuits like this) way of trying various ideas without the risk of letting any of the magic smoke out and it's much quicker than it can be done on a breadboard. If there's no model for LM335, no problem, just replace it with a low-value zener (e.g. 2.4V). It will allow you to test if power switching works as intended and current stays within reasonable limits.

author: Eraldo
author_rank: Regular Contributor
timestamp: March 29, 2023, 11:09:17 am
content: I'd say why not power the sensor from one of the digital pins of the arduino. It can sink enough current to power the sensor and there is no voltage drop like using the transistor in your example. You can also easily turn it on or off directly from the digital pin. Just a digitalWrite(sensor,HIGH/LOW); is enough for everything.(but do check the voltage output of the pin while high just in case)Edit: now that i think about it i don't know if the usb input goes through the voltage regulator or not. If yes then the output voltage will most likely be lower than 5v since there's a voltage drop from the linear regulator. So definetly check the volt output.

author: BillyO
author_rank: Super Contributor
timestamp: March 29, 2023, 02:33:11 pm
content: Quote from: Eraldo on March 29, 2023, 11:09:17 amThat's actually a great idea. It can certainly handle the 1ma required for the LM335.Voltage is not such a concern as long as you have the required current going through the device.

author: ElCerrajero
author_rank: Newbie
timestamp: March 29, 2023, 09:13:54 pm
content: QuoteI have tested the design you mentioned to me in Falstad, and comparing both designs, the best result is obtained using the PNP. Thank you very much, I will implement this design in my circuit.

author: ElCerrajero
author_rank: Newbie
timestamp: March 29, 2023, 09:18:01 pm
content: Quote from: BillyO on March 29, 2023, 02:33:11 pmI'm not doing it with the Arduino pin because in the final design, I will be using an ATTiny85. I'm using the Arduino to test the design. By using 5V from an external power source, I ensure that the level is correct. Additionally, I use this voltage as a reference to obtain the sensor values.

author: BillyO
author_rank: Super Contributor
timestamp: March 29, 2023, 11:13:42 pm
content: The ATtiny85 will have no issue either. It has the same drive capability as the ATMega328 in the Arduino. The decision is up to you though.

author: ElCerrajero
author_rank: Newbie
timestamp: March 30, 2023, 07:29:18 am
content: Quote from: BillyO on March 29, 2023, 11:13:42 pmThe way you recommend is indeed simpler, but since it is a test circuit, my intention is to learn how to use transistors as switches to control the sensor's activation. I'm sorry if my previous response sounded rude, I'm using ChatGPT to translate to English and it wasn't my intention to be rude. Thank you very much for your help

author: BillyO
author_rank: Super Contributor
timestamp: March 30, 2023, 02:48:41 pm
content: I didn't think you were being rude.Leaning about transistors is worthwhile. If that is your goal, then the arrangement with the NPN driving the PNP is the way to go as you will be using both low side and high side switching.Let us know if you get it all working.