low voltage on output pins

Jpadie
Posts: 8
Joined: Tue Feb 13, 2018 6:42 pm

low voltage on output pins

Postby Jpadie » Tue Feb 13, 2018 8:22 pm

Hello
I'm using a WROOM 32s module. voltage is supplied cleanly at 3.3v via an ams1117 LDO.
I'm seeing only 0.8v when a GPIO pin is set to high. Which surprises me as I had expected closer to vcc (the datasheet says minimum is 0.8 * vcc). a read of the pin-state after the write says that it is still low.

the test code I'm using is very straight forward (leaving out unnecessary functions)

Code: Select all

#include <WiFi.h>
#include <ArduinoOTA.h>



const byte livePin = 4; //IO4
const byte neutralPin = 21; //IO21

void setup() {
  Serial.begin(115200);
  WifiStart();
  digitalWrite(livePin, LOW); digitalWrite(neutralPin, LOW);
  pinMode(neutralPin, OUTPUT);
  pinMode(livePin, OUTPUT);
   ArduinoOTA.setHostname("**");
  ArduinoOTA.setPassword("**");
  startOTA();
}

void loop() {
  ArduinoOTA.handle();

  int state = digitalRead(neutralPin);
  if(state == LOW){
    Serial.println("Turning pins on");
    digitalWrite(neutralPin, HIGH);
    digitalWrite(livePin, HIGH);
  } else {
    Serial.println("Turning pins off");
       digitalWrite(neutralPin, LOW);
    digitalWrite(livePin, LOW);
  }

  delay(1000);
  ArduinoOTA.handle();

  Serial.println("Port State:");
  Serial.print("Live Pin: ");
  Serial.println(digitalRead(livePin));
  Serial.print("Neutral Pin: ");
  Serial.println(digitalRead(neutralPin));

  delay(1000);
}

this is the serial output I get

Code: Select all

Port State:
Live Pin: 0
Neutral Pin: 0
Turning pins on
Port State:
Live Pin: 0
Neutral Pin: 0
the two pins are connected to the bases of separate NPN transistors (BC549).

Whilst 0.8v is just enough for the transistors, I do need a way of determining port state; and forever reading low is not going to be very useful!

can anyone shed any light on this behaviour?

thanks in advance
Justin

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: low voltage on output pins

Postby ESP_Sprite » Wed Feb 14, 2018 5:28 am

Are you using a resistor between the base of your transistor and the MCU pin?

Jpadie
Posts: 8
Joined: Tue Feb 13, 2018 6:42 pm

Re: low voltage on output pins

Postby Jpadie » Fri Feb 16, 2018 8:50 am

yup. 2k.

tried with and without. the current at the collector is very low. so the current at the base is tiny. even without a resistor the draw would have been negligible.

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: low voltage on output pins

Postby ESP_Sprite » Fri Feb 16, 2018 9:36 am

Hmm, beats me then. My first thought was that maybe you left off the base resistor, which would indeed limit the base voltage to 0.8V. I'm not that familiar with Arduino, but at first glance the code looks OK to me.

iot_guy
Posts: 8
Joined: Thu Aug 31, 2017 8:16 pm

Re: low voltage on output pins

Postby iot_guy » Fri Feb 16, 2018 11:28 am

I'm assuming the transistor emitter is connected to ground here.

If "the current at the collector is very low" then use a bigger base resistor than 2k (e.g 10k or higher) and see if this makes a difference to the MCU pin voltage. If pin still low do the same test with nothing connected to the MCU pin.

Note, the base current is not a function of the collector current when using a transistor this way. If you connect without a base resistor the current is only limited by what the MCU pin is able to supply (this is not good for the MCU).

Jpadie
Posts: 8
Joined: Tue Feb 13, 2018 6:42 pm

Re: low voltage on output pins

Postby Jpadie » Mon Feb 19, 2018 1:27 pm

yup. emitter connected to ground. Collector is now connected to a pole of a relay coil (12v to the other side). coil draw is 30mA.

When testing the relay was not in the circuit. so there was no current flowing from collector to emitter.

Even though the voltage at the pin is still only 0.7-0.8v, the transistor is engaging, the relay is turning on and the whole setup works. But I am concerned about the low voltage and whether I'm living on borrowed time. I've changed the LDO from an AMS1117 to an LM317 as there was a lot of heat being created with the AMS1117 (regulating from 12v). circuit current is 90-120mA (excluding the relays which draw 60mA from the rectified pre LDO power trace. Whilst this is a bit wasteful for a temperature monitor I guess it is a necessary evil for an always on device and it only translates to Eur1.20 a year. which pales in comparison to the overall hot water bill!

I'm surprised about your assertion that the c->e current is not linked to the current at the base. i had thought that there had to be sufficient current at the base for the required current to flow c->e. I will have to go back and look at transistor theory again.

iot_guy
Posts: 8
Joined: Thu Aug 31, 2017 8:16 pm

Re: low voltage on output pins

Postby iot_guy » Tue Feb 20, 2018 9:54 am

When using a transistor as a saturated switch like this the base current is just
(Vmcu_pin - Vbe) / Rbase
You just need t ensure that this current is much greater than the collector current divided by the hfe of the transistor. A good rule of thumb is to make the base current greater than 1/10 or 1/20 of the collector current. And don't rely on the hfe of the transistor being the same for the next transistor you buy, there is huge variance in hfe hence why you should design it so that a hfe as low as 10 or 20 would still work.

And if you are switching a relay coil ensure you have a flyback diode connected across the coil (from collector to coil supply) to limit the voltage when you turn off the coil else you'll destroy the transistor.

mickeypop
Posts: 11
Joined: Mon May 08, 2017 8:56 pm

Re: low voltage on output pins

Postby mickeypop » Tue Feb 20, 2018 10:41 pm

if you can

As an experiment; Put a diode in series with the emitter to ground.
If the base voltage is higher, around 1.6v, you may be sourcing to ground in which case you may need to look over your circuit for other issues.

A possible backdoor approach;
Tie another pin to the output pin and set it as an INPUT_PULLUP.
When you set the output high you are possibly floating the pin. That would also produce the .8V.
The pullup will provide the juice needed in that case.

If that does work you should add an external pullup to the pin instead of using the internal pullups.
They are around 100K and not much to drive with.

m.lettieri
Posts: 2
Joined: Fri Aug 31, 2018 1:20 pm

Re: low voltage on output pins

Postby m.lettieri » Fri Aug 31, 2018 1:21 pm

I've the same issue... pin connected to a transistor give output 0.8V. did you solved?

Who is online

Users browsing this forum: ericchile and 122 guests