# Changing Scale on voltage divider.

#### Pepe333

Joined Feb 12, 2018
86
Hi all!,
I have a photodiode, and I want it to work in 2 ways:
-Connected to an ADC to obtain a value from light level.
-Connected to a transistor to obtain a digital signal 1/0.

The easy way will be to have 2 photodiodes, but itsn't possible.
I think in having to different scales with 2 voltage divider. Selecting R1 I'll have an analog reading the ADC, and selecting R2 I'll have a switching value, by the transistor, to obtain digital input for a GPIO.

In my circuit, I have a PCF8574 (I/O I2C expander) that work open drain.

How can I achieve it?

(circuit attached)

#### Attachments

• 84.7 KB Views: 11
Last edited:

#### ericgibbs

Joined Jan 29, 2010
17,972
hi Pepe,
As this is homework I will just give a hint.

What will the voltage be on the transistors Vbe junction, when in the ADC mode.???

E
You posted:
BTW: -Connected to an ADC to obtain. To obtain what.???

#### Attachments

• 55 KB Views: 3

#### Pepe333

Joined Feb 12, 2018
86
Hi ericgibbs!
It will be from Vcc (3.3v) to 0v depending the light on the photodiode.

Connected to an ADC to obtain a value from the light level. (sorry)

What I need, in digital mode, is to have a "0" when light becomes very strong, and "1" rest of the time.

Last edited:

#### ericgibbs

Joined Jan 29, 2010
17,972
hi P,
How can the ADC signal be from 0v to 3.3V. ???
The Vbe junction is like a forward biassed diode across the ADC output line, as you may know a diode will limit the Vbe to approx +0.65V.

E

#### Attachments

• 57.1 KB Views: 1

#### Pepe333

Joined Feb 12, 2018
86
Yes, You're right!
Maybe controling the emitter with an I/O from the PCF8574.
When I need ADC, I'll put "C" high. And when need the digital output turning "C" to low.

#### Attachments

• 77.2 KB Views: 5

#### ericgibbs

Joined Jan 29, 2010
17,972
hi,
Let us know how your design works out.
E

#### Pepe333

Joined Feb 12, 2018
86
Thank you!
But I still have the problem on how to control A/B.

#### ericgibbs

Joined Jan 29, 2010
17,972
hi,
This is the datasheet for the PCF8574, have you read through the data.?
Which type of MCU are you using to control the PCF.?
E

#### Attachments

• 2.1 MB Views: 0

#### Pepe333

Joined Feb 12, 2018
86
I'm using an ESP12.
Yes, I read the datasheet, but maybe there is something I missed.

#### Pepe333

Joined Feb 12, 2018
86
Thank you very much!
Really I'm using the PCF8574 with some inputs/outpus and it works properly.
My problem is how to make active the voltage divider on R1 or R2 without using relays.

#### Pepe333

Joined Feb 12, 2018
86
(SOLVED)
I think the solution was work with collector comun, not emitter comun.
Now the circuit works like expected.

#### Attachments

• 70.6 KB Views: 4

#### ericgibbs

Joined Jan 29, 2010
17,972
hi,
Do you plan to carry out performance tests , using different light intensity levels.?
E

#### Pepe333

Joined Feb 12, 2018
86
Hi,
I tested from the ADC. I achieve 0 to 990 (1024 max) when point with a laser to the photodiode. Enough. I need the ADC to see ambient light variations. And the digital output stays on 0 with ambient light and change to 1 when pointing with the laser. Just what I wanted to make a laser barrier.

Thank you very much, ericgibbs, for your help.

#### ericgibbs

Joined Jan 29, 2010
17,972
hi,
Sounds a very interesting project, good luck with your studies.
E

#### crutschow

Joined Mar 14, 2008
32,840
Why not use the microcontroller to also give you a digital output at the desired voltage level from the sensor?

#### Pepe333

Joined Feb 12, 2018
86
Why not use the microcontroller to also give you a digital output at the desired voltage level from the sensor?
Sorry, I dont understand.
I need 2 inputs, one analogic and one digital, from the photodiode.

#### crutschow

Joined Mar 14, 2008
32,840
I need 2 inputs, one analogic and one digital, from the photodiode.
You don't need two inputs, just two outputs.

I mean, you said you want a digital output when the light is above a certain level, so why not detect that level with the microprocessor from its ADC readings, and generate a digital signal at one of the microprocessor outputs if the ADC count is above that level?
It's simpier and more accurate than using a transistor.

#### Pepe333

Joined Feb 12, 2018
86
I understand.
The thing is velocity. When I read trough ADC, it takes a lot of time (hundred of microseconds). But with a digital level I can use an interrupt associated to a GPIO. The fall/rise time for a photodiode is some nanoseconds, so I can detect something really fast breaking the barrier.

#### crutschow

Joined Mar 14, 2008
32,840
Okay.
If speed is important, than you do need separate inputs.
To allow easy adjustment of the trigger threshold, you might consider a high-speed comparator.
How fast a response do you need?