Why not read anlog vlue..?

Discussion on both general simulation and Proteus VSM microcontroller simulation.
Post Reply
Rumesh
Unlicenced User
Posts: 1
Joined: Sat 2024-01-13 1:33

Why not read anlog vlue..?

Post by Rumesh »

ScreenShot_20240113071812.jpeg
ScreenShot_20240113071812.jpeg (551.87 KiB) Viewed 477 times
I am trying to measure the voltage value of the voltage source.Using Arduino voltage sensor method.why it is not work?

Code: Select all

// Define analog input
#define ANALOG_IN_PIN A2
 
// Floats for ADC voltage & Input voltage
float adc_voltage = 0.0;
float in_voltage = 0.0;
 
// Floats for resistor values in divider (in ohms)
float R1 = 30000.0;
float R2 = 7500.0; 
 
// Float for Reference Voltage
float ref_voltage = 5.0;
 
// Integer for ADC value
int adc_value = 0;
 
void setup(){
  // Setup Serial Monitor
  Serial.begin(9600);
}
 
void loop(){
  // Read the Analog Input
  adc_value = analogRead(ANALOG_IN_PIN);
  
  // Determine voltage at ADC input
  adc_voltage  = (adc_value * ref_voltage) / 1024.0;
  
  // Calculate voltage at divider input
  in_voltage = adc_voltage*(R1+R2)/R2;
  
  // Print results to Serial Monitor to 2 decimal places
  Serial.print("Input Voltage = ");
  Serial.println(in_voltage, 2);
  
  // Short delay
  delay(500);
}
Ettore
Labcenter Staff
Posts: 2931
Joined: Fri 2006-03-03 11:56
Location: Milan
Contact:

Re: Why not read anlog vlue..?

Post by Ettore »

We can't help without looking at your project. So, please attach the full Proteus project (the .pdsprj file) including the full source code.
Kind regards,
Ettore Arena - Labcenter Electronics.
Post Reply