Author Topic: LM335 Sensor controlled by transistor  (Read 1027 times)

0 Members and 1 Guest are viewing this topic.

Offline ElCerrajeroTopic starter

  • Newbie
  • Posts: 9
  • Country: es
LM335 Sensor controlled by transistor
« on: March 28, 2023, 06:25:57 pm »
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
 

Offline BillyO

  • Super Contributor
  • ***
  • Posts: 1382
  • Country: ca
Re: LM335 Sensor controlled by transistor
« Reply #1 on: March 28, 2023, 07:03:20 pm »
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.
« Last Edit: March 28, 2023, 07:07:44 pm by BillyO »
Bill  (Currently a Siglent fanboy)
--------------------------------------------------
Want to see an old guy fumble around re-learning a career left 40 years ago?  Well, look no further .. https://www.youtube.com/@uni-byte
 

Offline shapirus

  • Super Contributor
  • ***
  • Posts: 1333
  • Country: ua
Re: LM335 Sensor controlled by transistor
« Reply #2 on: March 28, 2023, 07:16:52 pm »
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.
This 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)
« Last Edit: March 28, 2023, 07:21:14 pm by shapirus »
 
The following users thanked this post: ElCerrajero

Offline BillyO

  • Super Contributor
  • ***
  • Posts: 1382
  • Country: ca
Re: LM335 Sensor controlled by transistor
« Reply #3 on: March 28, 2023, 07:40:18 pm »
??

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?
Bill  (Currently a Siglent fanboy)
--------------------------------------------------
Want to see an old guy fumble around re-learning a career left 40 years ago?  Well, look no further .. https://www.youtube.com/@uni-byte
 

Offline shapirus

  • Super Contributor
  • ***
  • Posts: 1333
  • Country: ua
Re: LM335 Sensor controlled by transistor
« Reply #4 on: March 28, 2023, 07:43:27 pm »
??

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?
I 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.
« Last Edit: March 28, 2023, 07:46:30 pm by shapirus »
 

Offline BillyO

  • Super Contributor
  • ***
  • Posts: 1382
  • Country: ca
Re: LM335 Sensor controlled by transistor
« Reply #5 on: March 28, 2023, 07:48:05 pm »
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. :-+
Bill  (Currently a Siglent fanboy)
--------------------------------------------------
Want to see an old guy fumble around re-learning a career left 40 years ago?  Well, look no further .. https://www.youtube.com/@uni-byte
 

Offline ElCerrajeroTopic starter

  • Newbie
  • Posts: 9
  • Country: es
Re: LM335 Sensor controlled by transistor
« Reply #6 on: March 28, 2023, 08:35:44 pm »
Quote
This 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)

Thank 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.
 

Offline BillyO

  • Super Contributor
  • ***
  • Posts: 1382
  • Country: ca
Re: LM335 Sensor controlled by transistor
« Reply #7 on: March 28, 2023, 08:39:14 pm »
Will the voltage drop of 0.2V in saturation in the transistor affect the LM335? Since this sensor changes its voltage to measure temperature.
No, the LM335 has a constant current source internally.  Just pick your series resistor for 1ma.  It will be fine.
« Last Edit: March 28, 2023, 08:45:04 pm by BillyO »
Bill  (Currently a Siglent fanboy)
--------------------------------------------------
Want to see an old guy fumble around re-learning a career left 40 years ago?  Well, look no further .. https://www.youtube.com/@uni-byte
 

Offline shapirus

  • Super Contributor
  • ***
  • Posts: 1333
  • Country: ua
Re: LM335 Sensor controlled by transistor
« Reply #8 on: March 28, 2023, 08:49:03 pm »
Thank 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.
This 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.
 

Offline Eraldo

  • Regular Contributor
  • *
  • Posts: 65
  • Country: it
Re: LM335 Sensor controlled by transistor
« Reply #9 on: March 29, 2023, 11:09:17 am »
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.
« Last Edit: March 29, 2023, 11:27:37 am by Eraldo »
 

Offline BillyO

  • Super Contributor
  • ***
  • Posts: 1382
  • Country: ca
Re: LM335 Sensor controlled by transistor
« Reply #10 on: March 29, 2023, 02:33:11 pm »
I'd say why not power the sensor from one of the digital pins of the arduino.
That'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.
Bill  (Currently a Siglent fanboy)
--------------------------------------------------
Want to see an old guy fumble around re-learning a career left 40 years ago?  Well, look no further .. https://www.youtube.com/@uni-byte
 

Offline ElCerrajeroTopic starter

  • Newbie
  • Posts: 9
  • Country: es
Re: LM335 Sensor controlled by transistor
« Reply #11 on: March 29, 2023, 09:13:54 pm »
Quote
This 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.
I 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.

 

Offline ElCerrajeroTopic starter

  • Newbie
  • Posts: 9
  • Country: es
Re: LM335 Sensor controlled by transistor
« Reply #12 on: March 29, 2023, 09:18:01 pm »
I'd say why not power the sensor from one of the digital pins of the arduino.
That'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.

I'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.
 

Offline BillyO

  • Super Contributor
  • ***
  • Posts: 1382
  • Country: ca
Re: LM335 Sensor controlled by transistor
« Reply #13 on: March 29, 2023, 11:13:42 pm »
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.
Bill  (Currently a Siglent fanboy)
--------------------------------------------------
Want to see an old guy fumble around re-learning a career left 40 years ago?  Well, look no further .. https://www.youtube.com/@uni-byte
 

Offline ElCerrajeroTopic starter

  • Newbie
  • Posts: 9
  • Country: es
Re: LM335 Sensor controlled by transistor
« Reply #14 on: March 30, 2023, 07:29:18 am »
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.

The 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
 

Offline BillyO

  • Super Contributor
  • ***
  • Posts: 1382
  • Country: ca
Re: LM335 Sensor controlled by transistor
« Reply #15 on: March 30, 2023, 02:48:41 pm »
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. :-+
Bill  (Currently a Siglent fanboy)
--------------------------------------------------
Want to see an old guy fumble around re-learning a career left 40 years ago?  Well, look no further .. https://www.youtube.com/@uni-byte
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf