Sie sind auf Seite 1von 12

Experiment 2

In order to measure voltages greater than the 5 V reference voltage, you need to divide the input voltage so that
the voltage actually input to the Arduino is 5 V or less. in this experiment, we will use a 90.9 kohm resistor and a 10
kohm resistor to create a 10:1 divider. This will allow us to measure voltages up to 50 V.

Hardware Required

1x Arduino Mega2560

1x 90.9 kohm resistor

1x 10 kohm resistor

1x LCD (Liquid Crystal Display)


1x 5k potentiometer

1x breadboard

female connector

jumper wires

Wiring Diagram

The circuit for this experiment is exactly the same as Experiment #1, except that we now have a voltage divider,
made up of a 90.9 kohm resistor and a 10 kohm resistor connected to the input. See the diagram below.

Program

The program for this experiment is nearly the same as for Experiment #1. The only difference is that now we have
to divide the calculated voltage by the ratio R2/(R1 + R2), which in this case is 10,000/(90,900 + 10,000) ≈ 0.1.

Code

#include "LiquidCrystal.h"

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

float input_voltage = 0.0;


float temp=0.0;
float r1=90900.0;
float r2=10000.0;

void setup()
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
lcd.begin(16, 2); //// set up the LCD's number of columns and rows:
lcd.print("DIGITAL VOLTMETER");
}
void loop()
{

//Conversion formula
int analog_value = analogRead(A0);
temp = (analog_value * 5.0) / 1024.0;
input_voltage = temp / (r2/(r1+r2));

if (input_voltage < 0.1)


{
input_voltage=0.0;
}
Serial.print("v= ");
Serial.println(input_voltage);
lcd.setCursor(0, 1);
lcd.print("Voltage= ");
lcd.print(input_voltage);
delay(300);
}
#include "LiquidCrystal.h"

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

float input_voltage = 0.0;


float temp=0.0;

void setup()
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
lcd.begin(16, 2); //// set up the LCD's number of columns and rows:
lcd.print("DIGITAL VOLTMETER");
}
void loop()
{

//Conversion formula for voltage

int analog_value = analogRead(A0);


input_voltage = (analog_value * 5.0) / 1024.0;

if (input_voltage < 0.1)


{
input_voltage=0.0;
}
Serial.print("v= ");
Serial.println(input_voltage);
lcd.setCursor(0, 1);
lcd.print("Voltage= ");
lcd.print(input_voltage);
delay(300);
}

https://www.allaboutcircuits.com/projects/make-a-digital-voltmeter-using-the-arduino/

vide the input voltage so that


e a 90.9 kohm resistor and a 10
0 V.
we now have a voltage divider,
ut. See the diagram below.

difference is that now we have


0/(90,900 + 10,000) ≈ 0.1.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
a 5 . 5 5 . 5 5 . 7 1 2 . 5
b 1 2 . 5 1 0 . 6 1 2 . 5

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
a 1 2 . 1 5 1 2 . 1 5 1 2 . 1
b 1 2 . 1 5 1 2 . 1 5 1 2 . 1

V O L T M E T E R 6 P O R T
6 C H A N N E L D I
G I T A
A W A S P E R H A T
I A N
H A T I H A T I
C H 1 2 3 4 M A X 5 0 V
C H 5 6 > > M A X 2 5 0 V
g-the-arduino/
L

Das könnte Ihnen auch gefallen