# Lesson 26--Microduino & Operational Amplifier--Differential Ratio Operation

Microduino & Operational Amplifier--Differential Ratio Operation

## Purpose

This tutorial offers the basic knowledge of the operational amplifier, adopting differential ratio operation circuit. By changing the input voltage and watch the output result, you can have a better understanding of the usage of the differential ratio operation circuit.

## Equipment

Microduino-Core is the 8-bit single-chip development core board with Atmel ATmega328P as the core, which is an open and Arduino Uno compatible controller.

Microduino-USBTTL is the program download module, capable of connecting with Microduino-Core or Microduino-Core+ and making the modules communicate with the computer. It uses MicUSB as the download interface, which is also the smallest part of Microduino. Microduino is just as small as a quarter. Besides, the download cable is just like the USB cable of most smart phones, easy to use.

• Other hardware equipment
 Related hardware Number Function LM358 One As a dual operational amplifier, easy to achieve the mathematical operation circuit. 30K Ω resistor Two For differential ratio operation. 3K Ω resistor Two For differential ratio operation. adjustable DC power supply One By adjusting the button, you can change the output voltage. In this example, we adopts 0-60V adjustable DC power supply. (Below the 36V safe voltage.) USB cable One For connecting Microduino modules and PC. Breadboard One All components gather here. Jumper One box Connector

We often see the adjustable DC power supply in the lab. By adjusting the button of the potentiometer, the output voltage will change along with the adjustment of the button, which will often be shown on the LED display screen. The maximum voltage and current value allowed by the adjustable DC power supply will be different according to various needs. The most common adjustable DC power supply can be classified into two: One is the switching power supply, which has high output efficiency but has turbulence. The other is the linear power supply, which has a stable output and lower efficiency. This example adopts the 0-60V adjustable DC power supply with the maximum current output of 20A. (Switching power supply)

## Schematic

What will you do if you want to measure the voltage of a 24V-battery and output the voltage value via Microduino? The first thing you think of may be lowering the voltage to one-tenth by resistive subdivision. (That is 2.4V, which can be recognized by Microduino analog interface.) Yes, that works! By the resistive subdivision, the measured negative voltage terminal needs to be connected with Microduino's GND end. By LM358 differential ratio operation circuit, this example can also achieve the measurement of the voltage(24V) without connecting the negative end of the voltage and Microduino's GND end. In the example, Vout=Vin*（R2/R1） provided that R1=R3, R2=R4. If R1=R3=3M, R2=R4=30K, you can detect a relatively higher voltage in the circuit. (The editor has used the parameter testing 400v DC voltage.) (Notes: The 3M resistor is cascaded by 1M and 2M resistors. Mind your safety when testing the high voltage.)

## program

```///A0  connect  amp358  output
int  anaValueAmp;  //amp  value   map(0--1023)
float anaVoltageAmp;  //amp  output  voltage
void  setup()
{
Serial.begin(9600);
}
void loop()
{
anaVoltageAmp=anaValueAmp/1023.0*5;
Serial.print("Amp358  output  voltage  is  ");
Serial.print(anaVoltageAmp);
Serial.println("V");
delay(1000);
Serial.print("The actual voltage  is  ");
Serial.print(anaVoltageAmp*10);
Serial.println("V");
delay(1000);
}```

## Debugging

• You can refer to the wire connection above and make sure it is all right.
• You can refer to the wire connection above and make sure it is all right.
• Compile the program and choose the right board and the related serial port.
• Click Upload, open the serial monitor of Arduino IDE and watch the result.
• Adjust the DC power supply and you can watch the change of the output voltage in the serial port. The picture above shows the actual output value in the serial monitor when the output voltage is 12V or 24V.
• You can refer to the wire connection above and make sure it is all right.
• Copy the program to Arduino IDE.
• Compile the program and choose the right board and the related serial port.
• Click Upload, open the serial monitor of Arduino IDE and watch the result. The output voltage of Vout-pin 1 can be measured by the multimeter.
• Change the resistance value and watch the change of the output voltage value in the serial monitor. Eg. R3=2K and the other resistance keeps unchanged. Watch the output voltage and compare it with the formula.

## Result

Build the circuit according to the schematic. After the download, you can watch the output voltage in the serial monitor of Arduino IDE. By analyzing the output data in the serial monitor, you can see the differential ratio operation circuit can measure the input voltage. Although the actual serial output voltage exists some errors and Microduino's 5V end is lower than 5V., there is anaVoltageAmp=anaValueAmp/1023.0*5 statement in the program. If you connect Microduino's 3V3 end to the analog quantity REF end and then modify the program, you can reduce the error.