A voltage divider drops voltage to a safe amount. It uses a input voltage and two resistors in series. More information about voltage dividers can be found here I got the arduino code to use use a voltage divider from this website. The code measures from the analog pin to get the voltage. There is some calibration that needs to be done which is explained on the same website. This code measures the voltage out, I want to measure the voltage in so I used the equation, V_out=V_in*(R2/(R1+R2)), and solved for V_in. Then used Ohm's law to solve for current, I=V/(R1+R2).
I tested it out using a 9V battery, 1000 and 330 ohm resistors and the measurement was only off about about .1V. This could be because of the resolution of the analog pin. To set it up but the resistors in series with R1 connected to the positive end of the battery followed by R2 then to the battery's ground. Connect pin A3 to the end of R1 and the start of R2. and connect the Arduino's ground to the battery's ground. Upload the code and look at the serial monitor (ctrl+shift+m).
Serial Monitor Output |
Arduino and Breadboard |
Here is the code I used-
// number of analog samples to take per reading
#define NUM_SAMPLES 20
int sum = 0; // sum of samples taken
unsigned char sample_count = 0; // current sample number
float voltageIn = 0.0; // calculated voltage
float current = 0.0;
float voltageOut= 0.0;
float Ra=1000.0; // Resistor 1
float Rb=330.0; // Resistor 2
void setup()
{
Serial.begin(9600);
}
void loop()
{
// take a number of analog samples and add them up
while (sample_count < NUM_SAMPLES) {
sum += analogRead(A2);
sample_count++;
delay(10);
}
voltageOut = ((float)sum / (float)NUM_SAMPLES)*5.08 / 1024.0;
voltageIn = ((Ra+Rb)/Rb)*voltageOut;
current= voltageIn/(Ra+Rb);
Serial.print(voltageIn);
Serial.print(" V");
Serial.print("\t");
Serial.print(current,4);
Serial.println( " Amps ");
sample_count = 0;
sum = 0;
}
When using the X-ray machine the input voltage is 30k so we will use 470k and 39 ohm resistors. This combination drops the voltage to a safe 2.43V. I have yet to test it with the machine but my only worry is the resistors not being able to withstand the wattage and heating up, smoking and failing.
No comments:
Post a Comment