Connecting 5V devices to Photon?

I’m connecting a number of 5V devices to the Photon and reading outputs via Analog Pins…

Is there a general schematic & set of components to convert the 5V analog output to 3.3V, thus avoiding damage to the Photon’s ADC & get more usable readings?

I used an LDR, connected to the Vin Pin of Photon, to calculate Ambient Light. And the photon never read 0 when there is no light. In a range of 0-100, the minimum photon could compute is 12-13. Then I powered the LDR with 3.3V Pin of Photon. And now it shows 0 when there’s no light. Now my device is safe and I get better usable readings.

This makes me think converting the Analog Output from 5V devices to 3.3V will solve a lot of issues. In my case I use a MQ135, MQ6 sensors and they need to be powered with 5V(using Vin) so they get heated up and work correctly. But now the output of these devices has to be converted to 3.3V.

For the MQ135 this is already done via the load resistor Rl which builds a voltage divider that can be calculated via Ohm’s Law.
You just need to choose an Rl less than the minimal expected Rs times 2 (Rl < 2 * Rs,min).
Rl = 2*Rs,min would give you a voltage drop of Vcc * 1/3 across Rs leaving you with Vcc * 2/3 on your sensor pin (5V * 2/3 = 3.3333V - just a bit too much, hence less than! Best with some margin for tolerance of resistance, voltage and temp drift).

If you have other sensors that actively output up to 5V (and you don’t know the output impedance) you might want an OpAmp circuit with a voltage devider in the feedback loop.

like here

1 Like

I have the MQ135 from this link:

This is not the bare MQ135 sensor alone. The sensor is mounted on a board with Vcc, Gnd, D0 & A0. It’s got some SMD resistors and it has a variable resistor. But VR is only to set a threshold trigger a digital high or low via D0…

So, for me to choose the Rl, I need to know the Rs
Rs - Is this the resistance at the analog output?
When I measured impedance between sensor’s analog output and ground, my fluke digital multimeter measured 1K Ohm. Is this how calculate Rs?

How do I calculate/know the minimal expected Rs?
Rl - Where do I connect the Rl?

Can you suggest a wiring diagram, for MQ135 mounted on a PCB?

Your board looks somewhat like this one.

Where R2 (102 = 1k) corresponds to Rl and is not adjustable, so you you’d need to take other steps like adding your own voltage divider with two resistors 1R + 2R to bring 5V down to 3.3V or better add your voltage follower.

On the other hand the MQ135 datasheet states a range for Rs of 30k~200k and a recommended Rlof 10k~47k.
But with 1k for Rl you’d be looking at a max voltage of around 0.16V (:confused: ??? :confused:)
Something seems fishy there :stuck_out_tongue_closed_eyes:

But since I haven’t got any of these sensors at hand I’m only theorizing :wink:
With one at hand I could get some real measurements.

Maybe you can get a voltage measurement between analog out and GND when you put the sensor in a “pure”/saturated atmosphere of any of the detectable gasses.

Its exactly the same as you’ve mentioned at link

So, I’ve added a voltage divider with resistors R1 = 820 Ohms, R2 = 1470 Ohms for stepping down 5V to 3.21V (couldn’t find 500 and 1000 ohm resitors for a perfect 3.33V)

Voltage & RAW Analog Read, without voltage divider:-
.34, 1540 - Pure Air Outside
.48V, 1600 - Normal Room Condition
1.8V, 3325 - Cigarette Lighter LPG for a minute
2.3V, 4080 - Incense Stick Smoke, placed 1cm below sensor, for 3 minutes
2.35V, 4095 - Incense Stick Smoke, placed 1cm below sensor, for 3 minutes

At 2.3V, analog read’s value is 4080, at 2.35V, analog read’s value peaks at 4095
And voltage kept raises up to 2.5 max, that’s not much after it reaches peak value right?
Technically, shouldn’t analog read value of 4095 happen only at 3.3V?

Voltage & RAW Analog Read, with voltage divider:-
.18V, 1350 - Pure Air Outside
.33V, 1580 - Normal Room Condition
1.1V, 2450 - Cigarette Lighter LPG for a minute
1.6V, 3154 - Incense Stick Smoke, placed 1cm below sensor, for 3 minutes

I’m still dealing only with voltage & raw analog reads here. So, once we’re done with this, please guide me to translate these to ppm values :smiley:

That is odd.
Can you also take a voltage measurement between 3V3 pin and GND?
How are you powering the sensor and the Photon?
Could you have a look with an oszilloscope how smooth your supply DC is?

Voltage between 3V3 and GND is 3.329 volts
Voltage between Vin and GND is 4.83 volts

I’m powering photon, via its Micro USB port with an Aukey Charger. Like the one from here:

And I’m using the green port of the charger, that provides 5V/2.4A max!

And I’m powering the sensor using the Vin pin of photon itself…

No, I don’t have an oscilloscope, at the moment. Is there anyway I can check my DC Supply without it?

@ilak2k, @ScruffR, adding the voltage divider in PARALLEL to the existing sensor/resistor divider will only behave as expected IF the resistor values are greater than the existing resistor values. Putting two resistors in parallel will always produce a resistance of less than the smallest resistor. So, you can increase the resistor values or add a voltage follower (op-amp) and THEN add the voltage divider.

As for the 2.35v yeilding a count of 4095 on the ADC, can you please show your sampling code? The values tend to suggest a ripple voltage you wont’ be able to measure with your multimeter in DC mode. Try putting it on AC mode, low voltage, to see if an AC ripple exists. Chargers can be a source of frustration so if you can test with another supply, it would provide a good comparison. :grinning:

1 Like

Will replace resistors and take readings again…

Sampling Code for measuring the analog pin:

void setup() {
    // Serial Monitor
    // Not defining pinModes for LDRPin, SmokePin, FirePin as Photon takes INPUT mode by default
    // Blynk Service

void loop() {
    if (WiFi.ready()) {;
int smokelevelraw = analogRead(SmokePin);

I’m reading MQ135’s analog out with this code and also on Blynk, with Analog Pin A5, without any range mapping, reads value as is…

Switched to AC Mode and measured between Ground and Analog Out… Reads 0.003V AC

I have my PC’s USB Port and the Aukey Charger… With Sony & Amkette Chargers, I receive slight electric shock from the pins and exposed metal parts of the circuit :confused:. Sometimes to the point I couldn’t touch the exposed pins. So I stopped using these and had to stick with the Aukey, for now… Aukey is clean, shock wise