How to get current value from voltage sensor?

Hello , Is it possible to get current value from voltage sensor? I try to set up variable float for current because i think ( if im not wrong ) just by dividing the voltage obtained from arduino divide by the resistors 30k and 7.5k could get it done but when i open serial monitor it still shows zero.Can someone please explain why this happens and how to fix this? do i need to use current sensor also? sorry for my bad english and Thank you

int analogInput = A1;
float vout = 0.0;
float vin = 0.0;
float current = 0.0;
float power = 0.0;
float R1 = 30000.0; //  
float R2 = 7500.0; // 
int value = 0;
void setup(){
   pinMode(analogInput, INPUT);
   Serial.begin(9600);
   Serial.println("CLEARDATA");
   Serial.print("LABEL,Time,voltage,current,power");
}
void loop(){
   // read the value at analog input
   value = analogRead(analogInput);
   vout = (value * 5.0) / 1024.0; // see text
   vin = vout / (R2/(R1+R2)); 
   current = vin / (R1+R2);
   power = vin * current ;
   
Serial.print("DATA,TIME,");
Serial.print(vin,2);
Serial.print(",");
Serial.print(current,2);
Serial.print(",");
Serial.println(power,2);
delay(500);
}

Do you mean the voltage value as it is NOW, or the value of the number of coulombs per second?

You seem to have way too many global variables

Hallo lolpaard, you need a current sensor.

The "voltage sensor" is just two resistors. The name "voltage sensor" is made up by sellers of those modules. We call that a "voltage divider".

Search for: arduino current shunt load
Also search for: acs712 arduino

A small resistor is used (it could be as low a few milliOhm), and the current through that resistor causes a voltage drop. That voltage drop can be measures.

The ACS712 measures current with a magnetic hall sensor that measures the magnetic field around a wire that carries current.

1 Like

Current as in now or current as in Amps? If the later can you provide a schematic of your voltage input and associated circuitry?

1 Like

@lolpaard, your topic has been moved to a more suitable location on the forum.

Hi, @lolpaard
Welcome to the forum.

Can you please post a circuit diagram, showing your input circuit and power supply?
Please not a Fritzy image, a picture of a hand drawn schematic will be fine.
Please include pin labels and component names.

What model Arduino are you using?

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

The current that you are calculating, is in fact the current that is been drawn by your 'voltage sensor'. This is not the current being drawn by whatever your load is.

The voltage sensor is purposely made so that it only draws a small current, so that it does not load the circuit under test.

If the input voltage is 25V (maximum it can be to give 5V on the analogue input) then the current is only 0.667mA, or 0.000667A. (= 25 / 37500)
Because you are calculating it in amps, and only displaying 2 decimal places then this gets rounded down to zero.

As has already been said you need a dedicated current sensor to measure the current being drawn by your load.

My friend jules says that while this project has a lot of potential, currently there is no way to measure amps without a current sensor