OPAMP with esp32

i have opamp lmv358 and try to controll it with esp32 so from 3.3v i can achieve an output near 5v

if analogWrite(M6,0); i measure:
0v on M6 before resistor (R37)
1.77v after resistor (R37)
2.29v VOUT-B

if analogWrite(M6,254); i measure:
3.30v before resistor (R37)
3.29v after resistor (R37)
2.72v VOUT-B

i think when analogWrite(M6,254); then VOUT-B need to be near 5v

what can be the problem here , i was trying to achieve around 5v ussing esp32 3.3v

If you are trying to use the DACs on the ESP, use dacWrite(yourGPIO, yourNUMBER);

ok ill use it. but same problem

Using this Link as a guide, try the author’s code to reproduce his results.


/*
  ESP32 DAC - Voltage Output Experiment
  espdac-voltage.ino
  ESP32 DAC Voltage Output Demo
  Steps through preset output voltages
  
  DroneBot Workshop 2022
  https://dronebotworkshop.com
*/

// Define DAC pins
#define DAC_CH1 25
#define DAC_CH2 26

void setup() {
  // Setup Serial Monitor
  Serial.begin(115200);
}

void loop() {

  // Step through voltages, delay between levels
  dacWrite(DAC_CH1, 0);
  Serial.println("DAC Value 0");
  delay(3000);

  dacWrite(DAC_CH1, 64);
  Serial.println("DAC Value 64");
  delay(3000);

  dacWrite(DAC_CH1, 128);
  Serial.println("DAC Value 128");
  delay(3000);

  dacWrite(DAC_CH1, 192);
  Serial.println("DAC Value 192");
  delay(3000);

  dacWrite(DAC_CH1, 255);
  Serial.println("DAC Value 255");
  delay(3000);
}

i dont have problem with esp. coz i can produce voltage i want, before resistor voltage of esp is correct.

the problem is after OPAMP im not getting voltage i need, its lower than ESP32 voltage.
like i send 3.3v and i get 2.7 insteand of 5v(near5v)

Show us your actual wiring.

M6 is io26 (DAC2) so when that is 3.3v then VOUT-b is 2.7 and it should be 5v

It's nice that you drew a schematic, but using the right symbols and conventions can make a huge difference. In this case, the correct op-amp symbol would make your diagram easier to interpret. Also, Ground is typically shown pointing downwards. Showing it pointing up requires more cognitive load to read as opposed to just seeing "oh, that's a noninverting op-amp configuration. He has the resistors reversed."

Actual wiring.

Make R1 = R2

1 Like

So R13 need to be 10K and R12 need to be 20K ?

then when i send 3.3v from esp OPAMP will have output around 5v, right?

Maybe. LM358 is a really old opamp so you're not going to be able to get the full rail voltage. With a 5V Vcc, you probably won't get more than about 3.6V output.

If you want 5V output, consider powering the opamp from 12V or whatever higher voltage is available.

i have 42v but i dont think it can handle.

any other solution to use so i can have 1-5v from esp32

Yeah... op-amps (or any amplifier) doesn't "make voltage". It can amplify a voltage or a signal if another source of voltage is available. It's sort-of like the gas pedal in your car "amplifying" the signal from your foot, with the energy coming from the gasoline.

It's also hard to find voltage regulators that can handle 40V input. :frowning:

Do you have 5V available?

With a "rail-to-rail" op-amp and a 5V power supply to the op-amp you can get very-close to 5V (and very-close to ground).

...Typically for the things I'm doing I use a "regular" op amp with + & - 12V power supplies. Then if I need to protect something (like the input to an Arduino) against excess voltage or negative voltages (when the unexpected happens) I'll add an over-voltage protection circuit which is a resistor and a couple of diodes.

i asked this question few months ago before making the pcb and people suggested me lmv358i

Connect the lmv358i op-amp as a non-inverting amplifier:

    • Connect the non-inverting input (+) of the op-amp to your ESP32's 0-3.3V output.
  • Connect the inverting input (-) of the op-amp to a reference voltage, typically 2.5V (halfway between 0V and 5V).
  • Connect a resistor (R1) between the non-inverting input (+) and the output of the op-amp.
  • Connect another resistor (R2) between the output of the op-amp and its inverting input (-).
  1. Choose the resistor values: You can calculate the resistor values to achieve the desired gain (in your case, a gain of 5/3.3 ≈ 1.5152). Use the following formula:Gain (A) = 1 + (R2 / R1)

.....

if you use a 20 kΩ resistor (R1) and a 10 kΩ resistor (R2) in your op-amp circuit, the gain (A) would be calculated as follows:

A = 1 + (R2 / R1)
A = 1 + (10 kΩ / 20 kΩ)
A = 1.5

So, with these resistor values, the gain of your op-amp circuit would be 1.5.

Now, if you send an input voltage of 0.5V (V_in = 0.5V), you can calculate the output voltage (V_out) as follows:

V_out = V_in * A
V_out = 0.5V * 1.5
V_out = 0.75V

With a gain of 1.5 and an input of 0.5V, you will get an output voltage of 0.75V.

Now, if you send an input voltage of 3.3V (V_in = 3.3V), you can calculate the output voltage (V_out) as follows:

V_out = V_in * A
V_out = 3.3V * 1.5
V_out = 4.95V

With a gain of 1.5 and an input of 3.3V, you will get an output voltage of 4.95V. The output voltage will be scaled up by the gain factor of 1.5, and it will be very close to the maximum 5V output.

What happens when you change R35 and 37 to 0 (zero) ohms ?

lmv358 was the problem, i replaced it and start to work , but how can it burn, is there any problem in wirings or do i need to use any protection or something

is the below code ok to use coz in esp32 i change nonstop the M6


void loop (){
      analogWrite(M6, analogRead(gpioPIN));
delay(50);
}

or


void loop (){
      dacWrite(DAC_CHANNEL_2, analogRead(gpioPIN));
delay(50);
}

it burn out again as soon as i connect other module on it.

i replace the lmv358 and when i measure with voltmeter its working ok i can have output of 0-4.6v

but as soon as i add the other modle that need to get 0-5v signal from it then it burn out.

is there a way to test whats going on, or is there any protecction i need to do

Maybe dont be so cryptic and just say what this other module is?

1 Like

It is a motor controller and has a signal wire so you can use a potentiometer to control motor. - voltage 0-5v

It works well.until i cut power of controller and when i start again then opamp will not work.
I tested also with mcp6022 and same happend

Measure the current out of the op amp when the controller power is off and I'm sure that you'll find it exceeds the Absolute Maximum current output.