Advertisement
basyair7

program_voltage.ino

Mar 19th, 2023
589
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 0.56 KB | Source Code | 0 0
  1. // float for ADC voltage & input voltage
  2. float adc_voltage = 0.0;
  3. float in_voltage = 0.0;
  4.  
  5. // float for resistor values in divider (in ohm)
  6. float R1 = 30000.0;
  7. float R2 = 7500.0;
  8.  
  9. // integer for ADC value
  10. int adc_value = 0;
  11.  
  12. float get_voltage(int pinSensor, float ref_voltage)
  13. {
  14.   // Read the Analog Value
  15.   adc_value = analogRead(sensor_voltage_1);
  16.  
  17.   // Determine voltage at ADC input
  18.   adc_voltage = (adc_value * ref_voltage) / 1024.0;
  19.   // Calculate voltage at divider input
  20.   in_voltage = adc_voltage / (R2 / (R1 + R2));
  21.  
  22.   return in_voltage;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement