Author Topic: Any ideas on how to offset a sensors output without an op-amp  (Read 902 times)

0 Members and 1 Guest are viewing this topic.

Offline sofa-kingTopic starter

  • Contributor
  • Posts: 11
  • Country: us
Any ideas on how to offset a sensors output without an op-amp
« on: December 20, 2022, 01:49:52 am »
I'm using an ambient light phototransistor to control the brightness of a display. The ADC is the lousy one in the ESP32 which essentially has no reading changes below about 100mv. The problem is I need to detect both absolute darkness, very bright lighting and typical indoor light levels. So to be more concise I need to be able to measure below 100mV. My thought is to just add an op-amp to the design and add a small offset (0.1v), but I'd really like to avoid the extra components if I can find a practical solution. The phototransistor is just a typical circuit with the collector connected to 3v3 and a resistor connected to the emitter and ground.

any ideas will be greatly appreciated!
 

Online uer166

  • Super Contributor
  • ***
  • Posts: 1002
  • Country: us
Re: Any ideas on how to offset a sensors output without an op-amp
« Reply #1 on: December 20, 2022, 02:10:52 am »
If you're going to add an active external part, you might as well add literally any ADC on a SPI bus that would actually work, instead of using the broken-by-design ESP32 analog peripherals. Alternatively, you can do a 3-way resistive divider to pull up the "zero" output of photo-device above 100mV.
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3248
  • Country: us
Re: Any ideas on how to offset a sensors output without an op-amp
« Reply #2 on: December 20, 2022, 04:35:34 am »
Here's what uer166 is talking about:

Code: [Select]

  3.3V --/\/\/---ADC---/\/\/-- Vin
           R1            R2


The formula for the voltage at the ADC pin is:
$$
V_{adc} = V_{in}\frac{R_1}{R_1+R_2} + 3.3 \frac{R_2}{R_1+R_2}
$$
All that matters is the ratio between R1 and R2, so setting R1 = a*R2 we have:

$$
V_{adc} = V_{in}\frac{a}{1+a} + 3.3 \frac{1}{1+a}
$$
If you want the ADC to read 0.5V when the input is 0V, you would solve:
$$
  0.5 = 3.3 \frac{1}{1+a}
      \quad\Rightarrow\quad 1+a = 3.3/0.5
      \quad\Rightarrow\quad a = 5.6
$$
So if R2 = 10K, R1 would be 56K. The final formula for the ADC voltage would be:

$$
  V_{adc} = V_{in}\frac{5.6}{6.6} + 0.5
$$


 

Offline sofa-kingTopic starter

  • Contributor
  • Posts: 11
  • Country: us
Re: Any ideas on how to offset a sensors output without an op-amp
« Reply #3 on: December 20, 2022, 06:08:07 pm »
Thank you for your replies!

Does this look right?
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3248
  • Country: us
Re: Any ideas on how to offset a sensors output without an op-amp
« Reply #4 on: December 20, 2022, 07:14:49 pm »
Well, the formula I gave assumed the output impedance of Vin was 0. The output impedance of the phototransistor is likely to be high so you would have to experiment with the resistor values and I'm not sure how well it would work.

How about putting the resistor on the collector of the phototransistor? Then the voltage at the ADC will start from 3.3V and go downwards and you'll avoid the bad part of the ESP32's ADC.


 

Offline sofa-kingTopic starter

  • Contributor
  • Posts: 11
  • Country: us
Re: Any ideas on how to offset a sensors output without an op-amp
« Reply #5 on: December 20, 2022, 09:00:59 pm »
Thanks again for your reply. Unfortunately the ADC in the ESP32 doesn't differentiate between ~3.2-3.3v either. The ADC is really quite bad :( I think I'll experiment with some resistor values and see if I can get reasonable readings. Accuracy is not all that important so I might be able to get it to work.

I'm guessing this is a bad idea:

1668934-0
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf