Arduino just stops calculating...!

Well, im using this very simple program to display a voltage over some capacitors with an LCD. The strangest thing happens when the capacitors reaches 55 Volts, the arduino just stops calculating the voltage.
The voltage displayed just stays at 55 Volts, but i can clearly see that the caps are far over 55V on my multimeter...

Im using the voltage divider method to calculate the voltage, the maximum amps that would be going into A1 on the arduino is 100 uA (300V/3M ohm = 100 uA).

What's wrong here? Is it a code problem?

#include <LiquidCrystal.h> // we need this library for the LCD commands // initialize the library with the numbers of the interface pins
LiquidCrystal lcd(4,5,6,7,8,9); // define our LCD and which pins to user
int temp = 23;
int state = 0;
int analogInput = 1;
float vout = 0.0;
float vin = 0.0;
float R1 = 3000000.0;    // !! resistance of R1 !!
float R2 = 300000.0;     // !! resistance of R2 !!
int value = 0;

void setup()
{
  lcd.begin(16, 2);
  lcd.clear();
  pinMode(analogInput, INPUT);
  drawWelcomeScr();
}

void loop()
{
  if (state == 0)
  {
    if (millis() >= 4000)
    {
      state = 1;
    }
  }else{
    calculateVoltage();
    drawInfoScr();
    delay(100);
  }
  
}

void drawWelcomeScr()
{
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Welcome!");
  lcd.setCursor(0,1);
  lcd.print("By Chief");
}

void drawInfoScr()
{
  lcd.clear();
  lcd.setCursor(0,0);
  
  if (vin > 0.0){
    lcd.print("Charge: ");
    lcd.print(vin);
    lcd.print("V");
  }else{
    lcd.print("Charge: NONE");
  }
  lcd.setCursor(0,1);
  lcd.print("Fake Temp: ");
  lcd.print(temp);
  lcd.print("C");
}

void calculateVoltage()
{
  value = analogRead(analogInput);
  vout = (value * 5.0) / 1024.0;
  vin = vout / (R2/(R1+R2));  
}

Since your voltage divider divides by 11, its going to saturate at 55V, and then the reading will be constant. If you want to measure above 55V you need a higher ratio.

55V corresponds to 5V at the pin input, if I've read your code correctly. And that's the full-scale of the ADC. Reduce R2 to get greater voltage range (at the expense of precision).

Aha! So if I understand this correctly, i have to have a ratio of 60 (300/5) -> Which means R2 has to be 50k ohm? This way it will go all the way up to 300V, but no further? :slight_smile:

If you're dealing with 300V you have safety issues to worry about first. 300V on a capacitor is absolutely capable of killing someone stone dead. If you have a fault in the circuit (or an insect lands on the wrong resistor) your whole Arduino could go to lethal voltages.

Ensure all the high voltage (or potentially high voltage) parts of the circuit are insulated and cannot be accidentally touched.

For a high-voltage voltage divider have several resistors in series in the high-voltage arm so that the failure of any one of them doesn't endanger life. Keep high voltages separated by enough distance to prevent corona discharge.

MarkT:
If you're dealing with 300V you have safety issues to worry about first. 300V on a capacitor is absolutely capable of killing someone stone dead. If you have a fault in the circuit (or an insect lands on the wrong resistor) your whole Arduino could go to lethal voltages.

Ensure all the high voltage (or potentially high voltage) parts of the circuit are insulated and cannot be accidentally touched.

For a high-voltage voltage divider have several resistors in series in the high-voltage arm so that the failure of any one of them doesn't endanger life. Keep high voltages separated by enough distance to prevent corona discharge.

Yes, I already had them in series, and i've also insulated all wires/joints with a minimum 3mm coat of rubber isolation! :slight_smile: Thanks for warning tho!

As a general point, on the I/O pins it's best to avoid voltages above Vcc (the power supply voltage, usually 5V or 3.3V for Arduinos). Higher voltages can cook the I/O circuitry or even the whole chip.

tim7:
As a general point, on the I/O pins it's best to avoid voltages above Vcc (the power supply voltage, usually 5V or 3.3V for Arduinos). Higher voltages can cook the I/O circuitry or even the whole chip.

Using KVL ill get around 4,9V to the arduino when the caps are at 300V! :smiley: