I'm tring to read a signal generated by an op. amp. with a microcontroller through an input digital pin. All signals I'm working with are DC.

The op. amp. is connected to a light sensor so that it outputs 0V when the sensor is shaded and between 4.8 and 5.2 volts (fluctuates all the time) when the sensor is detecting light. I have measured this signal with a multimeter.

The microcontroller's pin is configured as a digital input with a pull-down resistor. The voltage levels for the pin are a logical 1 if the input voltage is 3.3V < voltage < 5V and a logical 0 if voltage < 3.3.

The problem I have is that when I connect the op. amp.'s output to the input digital pin, and the sensor is enabled, the voltage drops to something between 0.8V and 1.5V, and it doesn't reach a steady level (always fluctuates, wider range than before).

The microcontroller is supposed to change the color of an LED depending on the digital input state. What happens is that the LED blinks all the time. In addition, However, I have connected a steady 3.3V signal coming out of another microcontroller's pin (output) and everything works as expected. In addition, I have measured the voltage at the output pin and it doesn't drop as it happens with the op. amp.

I'm not sure I can connect the op. amp. output directly to a digital input pin. My questions are:

Is the op. amp. output signal considered analog?

If so, if an analog signal has two known 'steady' states, can it be considered a digital signal?

Can I connect that signal directly to the input pin, given that it is still DC? Do I need to connect it to an ADC?

Note: The microcontroller is a TM4C123GXL. I'm configuring the pin PB4 as a digital input and PB6 as a digital output (3.3V). When connection PB6 to PB4, everything works as expected.


The schematics is here: enter image description here

Notice that R3 is a photocell. The op. amp. is a OPA2344

Currently my MCU is powered over USB, from my laptop. Notice that I'm connecting the op. amp. output directly to the digital input pin. Not sure if this can be done.

As you can see I'm using a voltage divider. This is because, if I power the op. amp. with the 3.3V coming out of the regulator, its output is always below 3.3V, so the MCU will never interpret it as a logic 1.

I would like to do this without the help of a transistor.


I have tried it again powering the op. amp. with the steady 3.3V coming out of the regulator. The output of the op. amp. is steady at 3.3V when the photocell is not shaded, as soon as I connect it to the MCU digital input it drops to 3.29V, so the MCU doesn't detect it as a logic 1.

I have observerd one listake I was doing: I was connecting the MCU GND pin to the common ground. That makes everything 'go mental', I think that is what caused the voltage drop at the op. amp.'s output I saw before. I deduce that it's wrong to connect the MCU GND to the common ground, why?

  • \$\begingroup\$ What op amp are you using? Please include a schematic. \$\endgroup\$
    – Ron Beyer
    Mar 1, 2020 at 22:00
  • \$\begingroup\$ And what's the value of the pulldown resistor on the input of the microcontroller. The fluctuations of 4.8V to 5.2V that you measured with a multimeter may be an indication that the op amp is oscillating. Like Ron Beyer said, need to a schematic to go further. \$\endgroup\$
    – SteveSh
    Mar 1, 2020 at 22:14
  • \$\begingroup\$ Martel, why don't you just use a couple of BJTs and some passives to create a circuit with hysteresis and a clean digital signal? For example, not unlike this. \$\endgroup\$
    – jonk
    Mar 1, 2020 at 22:31
  • \$\begingroup\$ 3.3V as digital output... what voltage is your uC (not the launchpad) working on? 3.3V? And can you apply 5V to the ADC? (Its on page 1350 or so of the datasheet, way tl;dr on this phone) \$\endgroup\$
    – Huisman
    Mar 1, 2020 at 23:02
  • 2
    \$\begingroup\$ Look up the data sheet, which voltages are recognized as "high" and "low", resp. A voltage of 3.29V will still be read as "1" on a 3.3V microcontroller, I'm sure. \$\endgroup\$ Mar 2, 2020 at 7:45

3 Answers 3


From your explanation, it sounds like you have configured the Op-Amp to output 0-5 V and the microcontroller's digital pin is trying to read a 0-5 V signal. Please note that the microcontroller TM4C123GXL, which you are using, operates with I/O logic levels of 3.3 V and you are using a 5 V logic to drive the microcontroller's digital pin. This appears to be the cause of what you are seeing at the output. Have a look at the microcontroller TM4C123GXL's datasheet here : http://www.ti.com/lit/pdf/spmu296&ved=2ahUKEwjP1-DeqPrnAhVkTxUIHYoLDiEQFjAAegQIBxAC&usg=AOvVaw0XulafQFE2JHx9LJ_xC5p-&cshid=1583103090057 As @Ron and @Steve suggested, please provide a schematic of your circuit.


First of all you need a common ground. If you only connect the output from the op-amp to PB4 of the MCU, you have established a common reference voltage. But no current will flow before you make a second connection between the two so that there is a loop between the two circuits.

Also you can use one of the ADC channels of the MCU and read the photocell directly from it without the op-amp. Use the photoresistor in a voltage divider.

I would also have have used only one power source. So either power everything from the regulator or from USB.


The problem was that I was powering the whole circuit with a 9V battery (converted to 3.3V through the regulator) but the MCU through my laptop's USB port.

Disconnecting the op. amp. output from the MCU input pin I could measure 3.3V steady. In the moment I connect the MCU GND (ground) pin to the bradboard ground (which is connected to the battery's negative terminal) the op. amp. output goes mental (starts to jump all the time from 1.5 to 2.3 V aprox.)

What I have done is disconnect the MCU from the laptop and connect its GND pin to the breadboard common ground, the VBUS pin to the regulator's output (3.3V) and the op. amps. output to PB4 (input pin). By doing so, everything is working as expected.


I have tried a different thing: connect the MCU to my laptop and power the board with its 3.3V pin. At the beginning it didn't work (the op. amp. output dropped to 0V), and I have discovered that that was caused by the multimeter. I have disconencted it and everything works.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.