# 5v to 3.3v input on pico

#### Gabo

Mar 1, 2023
8
Hi, currently I am working on a project where I reuse an old IR sensor. But the IR sensor is working on 5V and gives a 5V @200mA as signal. When something is detected the voltage drops to 0.5V.
For the Pico an input voltage of 3.3V is needed.
I googled for methods to get the correct input for the Pico but without a clear answer. I tried a voltage divider by 1kOhm and 2kOhm but the voltage drops very low. Reasonable with only 0,2A.
Can you give me advice how to do this? And explain why?

Gabo

#### kellys_eye

Jun 25, 2010
5,511
You can clamp (limit) the voltage using a zener diode with suitable series dropping resistor.

#### Gabo

Mar 1, 2023
8
Hi Kellys, thanks for you reply. Tis is one of my first projects and did not have an electronic study. Just googled what zener diodes are. It becomes clear a resistor is needed to limit the current. For example when I take this zender diode: 1N4728A. The data sheet give 75mA at 3.3V. the voltage difference is 5-3.3= 1.7V so need a resistor of 1.7V / 0.075A= 23Ohm.
Is that correct?

Feb 19, 2021
335
A quick and dirty way is to use a series R between the IR sensor output and the Pico input.
Say ~ 4.7K. That will limit the injection current thru the Pico input diodes used for its protection.
You might check datasheet for max allowed input current but a couple of mA is typical for
CMOS parts. Typical input internal :

If you exceed allowed injection current the part (Pico) can potentially latch up and cause
self destruction. So just look at datasheet input electrical section for any limits.

If datarate low 4.7K should be fine regarding the Rseries and C of pin Tr, Tf. If its
a problem lower the Rseries, 1K would be rough lower limit.

Regards, Dana.

#### Harald Kapp

##### Moderator
Moderator
Nov 17, 2011
13,098
Use a voltage divider like so:

The voltage is limited to the allowed input range of the pico plus the resistor R2 additionally limits the current.

#### bidrohini

Feb 1, 2023
51
I think the easiest method is a to use a bi directional logic level converter module. That can convert 5V to 3.3V and vice versa. You can buy one from sparkfun, waveshare or any other similar websites.

#### Harald Kapp

##### Moderator
Moderator
Nov 17, 2011
13,098
I think the easiest method is a to use a bi directional logic level converter module.
Really? You think an IC is easier to use than 2 resistors? Not here where bidirectionality is not required. Data flows from the sensor to the pico only - that's my understanding.
Of course, once you go bidirectional a logic level converter is required.

Feb 19, 2021
335
Various methods (with various consequences) from single R to R divider to 3.3V clamp :

Regards, Dana.

Last edited:

#### Gabo

Mar 1, 2023
8
Hi you all. Thanks for all the replies here.

I did some more testing on the IR sensor and it give an voltage between 5V and almost 0V depending on the distance (+/- 10cm). Not that I need that for this project, but nice to know.
To sum up I see 3 methods here. Alle seems like a simple options.

Zener diode with suitable series dropping resistor
Not sure how to do this exactly. Have to order on zener diode to test, but how to determine the right zener diode and resistors?
Can it handle voltage levels in between?

bi directional logic level converter module
A nice option, but a complete IC looks to me a bit overdone. Will is handle voltage levels in between?

Voltage devider by resistors
I have a bunch of resistors here with a variaty of sizes. This evening I did some testing with it to find a combination by trail and error. The lowest pairs have a high measuring error, so please neglect these.

22K/100K seems to be a good combination.
But what supprises me is that it is not what I expected by calculation by this formula: Vout = R2/(R1+R2)*Vin
The set should be 51K/100K. Can anybody tell me the reason for this?
The last column in my table is the calculated power that is consumed by the resistors. Can that be of importance by choosing a pair?

Another question what comes in mind: if my pair 22K/100K has 34 μA can that be of infulence when current starts to flow through the Pico as input signal?

Sorry, I am so curious to how it works. I am an mechanical Engineer of lifting compents. So normally I do nothing by trail and error on forehand when I do not know exactly what I am doing.

Big regards,

Gabo

#### Attachments

• voltagedevider.png
29.1 KB · Views: 1

Feb 19, 2021
335

Here is a calc where it will pick standard value R's to use to get divide ratio :

Use R ratio section, and pick V divider, and enter Vin (+5.0 V, Vout + 3.3 V)

Regards, Dana.

#### Harald Kapp

##### Moderator
Moderator
Nov 17, 2011
13,098
But what supprises me is that it is not what I expected by calculation by this formula: Vout = R2/(R1+R2)*Vin
The set should be 51K/100K. Can anybody tell me the reason for this?
22 k and 100 k give a scale factor of 0.180.
0.18 × 4.1 V = 0.74 V
Your measurement is V1 = 3.40 V, V2 = 0.70 V

Seems you mixed up V1 and V2.
0.70 V is not that far away from 0.74 V given the uncertainties of your measurements.

#### Gabo

Mar 1, 2023
8
Sorry guys, I was calculating with the unloaded voltage of 5V. But when current starts flowing the voltage drops to 4.1V at the 22K/100K set. That gives me a V2 of 100/(100+22)*4.1 = 3.36V which matches the outcome of the measuring. FYI the formula comes from wikipedia.

One of my other questions was: since only 34 μA is flowing through the resistors, what will happen when I connect the pico? Will the voltages and currents than change?

#### Harald Kapp

##### Moderator
Moderator
Nov 17, 2011
13,098
Will the voltages and currents than change?
Only by a very small amount. I don't seem to be able to find an exact value in a datasheet but the input current to a raspberry pi pico's GPIO input pins is probably negligible compared to the microamps going through the divider.

Feb 19, 2021
335
RP2040 CPU input leakage is :

Regards, Dana.

#### Harald Kapp

##### Moderator
Moderator
Nov 17, 2011
13,098
Good find. Somehow I missed that info.
With that small leackage (1 µA max, typically less), the input pin is almost no load for the resistive divider.

#### bidrohini

Feb 1, 2023
51
Really? You think an IC is easier to use than 2 resistors? Not here where bidirectionality is not required. Data flows from the sensor to the pico only - that's my understanding.
Of course, once you go bidirectional a logic level converter is required.
I am comfortable using logic-level converter modules rather than looking for resistors and breadboards to connect. Anyway, of course, using resistors will be less costly.

#### Gabo

Mar 1, 2023
8
I am comfortable using logic-level converter modules rather than looking for resistors and breadboards to connect. Anyway, of course, using resistors will be less costly.
What are the pro's using a logic level converter instead of a voltage devider?

#### Harald Kapp

##### Moderator
Moderator
Nov 17, 2011
13,098
What are the pro's using a logic level converter instead of a voltage devider?
Works in both directions (bidirectional) which as far as I take it from your description is not required here.

#### Gabo

Mar 1, 2023
8
Today I connected the reduced input signal to the Pico and... It works!!! Thanks you all for helping me!

Next problem for me is to filter the noise from the signal. It gives false signals sometimes. I do not know the reason for that. Could be interference with other devices or something. My first thought was to place a capacitor on the input signal, but that give a huge delay. My second idea was to program a timefilter on the input l. You you have some other ideas?

Last edited:

Feb 19, 2021
335
IR Sensor datasheet, part number ?

Regards, Dana.

Replies
1
Views
105
Replies
8
Views
299
Replies
7
Views
274
Replies
1
Views
315
Replies
2
Views
329