0% found this document useful (0 votes)
12 views4 pages

Here Are Some Arduino Codes For Simulating Different Op

The document provides Arduino code examples for simulating various Op-Amp circuits, including inverting and non-inverting amplifiers, as well as an Op-Amp comparator for controlling an LED. Each example includes circuit details, expected behavior, and Arduino code to read input signals and display output voltages. The Op-Amps used are primarily the LM358, with specific gain configurations for each circuit.

Uploaded by

Veera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Here Are Some Arduino Codes For Simulating Different Op

The document provides Arduino code examples for simulating various Op-Amp circuits, including inverting and non-inverting amplifiers, as well as an Op-Amp comparator for controlling an LED. Each example includes circuit details, expected behavior, and Arduino code to read input signals and display output voltages. The Op-Amps used are primarily the LM358, with specific gain configurations for each circuit.

Uploaded by

Veera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Here are some Arduino codes for simulating different Op-Amp circuits using an Arduino and sensors.

These circuits use the ADC (Analog-to-Digital Converter) and PWM (Pulse Width Modulation) to
interact with operational amplifiers.

1. Inverting Op-Amp with Arduino

This example reads an analog input (e.g., a sine wave) from a sensor or signal generator and prints
the amplified and inverted output voltage.

Circuit Details:

• R1 = 10kΩ, Rf = 100kΩ (Gain = -10)

• Op-Amp: LM358 or any general-purpose Op-Amp

• Input: Analog signal (A0)

• Output: Connected to Arduino A1

Arduino Code:

const int inputPin = A0; // Input signal from sensor

const int outputPin = A1; // Amplified output from Op-Amp

void setup() {

Serial.begin(9600); // Start serial monitor

void loop() {

int Vin = analogRead(inputPin); // Read input voltage

int Vout = analogRead(outputPin); // Read amplified & inverted output

float voltageIn = Vin * (5.0 / 1023.0); // Convert ADC to voltage

float voltageOut = Vout * (5.0 / 1023.0);

Serial.print("Input Voltage: "); Serial.print(voltageIn); Serial.print(" V | ");

Serial.print("Output Voltage: "); Serial.print(voltageOut); Serial.println(" V");

delay(500);

}
Expected Behavior:

• The output voltage is inverted and amplified compared to the input.

• If you apply 1V, the output should be around -10V (depending on power supply limits).

2. Non-Inverting Op-Amp with Arduino

This example reads an input signal and displays its amplified (non-inverted) output.

Circuit Details:

• R1 = 10kΩ, Rf = 100kΩ (Gain = 11)

• Op-Amp: LM358

• Input: Analog signal (A0)

• Output: Amplified at A1

Arduino Code:

const int inputPin = A0; // Input signal

const int outputPin = A1; // Amplified output

void setup() {

Serial.begin(9600);

void loop() {

int Vin = analogRead(inputPin);

int Vout = analogRead(outputPin);

float voltageIn = Vin * (5.0 / 1023.0);

float voltageOut = Vout * (5.0 / 1023.0);

Serial.print("Input: "); Serial.print(voltageIn); Serial.print(" V | ");

Serial.print("Output: "); Serial.print(voltageOut); Serial.println(" V");

delay(500);

}
Expected Behavior:

• The output is not inverted but amplified by 11x.

3. Op-Amp as a Comparator (LED Indicator)

In this example, the Op-Amp acts as a comparator:

• If input voltage > reference voltage, the LED turns ON.

• If input voltage < reference voltage, the LED stays OFF.

Circuit Details:

• Reference Voltage: 2.5V (from a voltage divider)

• Op-Amp: LM358

• Input: A variable voltage from a potentiometer

• Output: Digital HIGH or LOW to control an LED

Arduino Code:

const int inputPin = A0; // Comparator input voltage

const int ledPin = 13; // LED output

void setup() {

pinMode(ledPin, OUTPUT);

Serial.begin(9600);

void loop() {

int Vin = analogRead(inputPin);

float voltageIn = Vin * (5.0 / 1023.0); // Convert to voltage

Serial.print("Input Voltage: "); Serial.print(voltageIn); Serial.println(" V");

if (voltageIn > 2.5) { // Compare with 2.5V reference

digitalWrite(ledPin, HIGH); // LED ON

} else {

digitalWrite(ledPin, LOW); // LED OFF


}

delay(500);

Expected Behavior:

• When the input voltage exceeds 2.5V, the LED turns ON.

• When the input is below 2.5V, the LED turns OFF.

You might also like