const int analogInPin = A0; // Analog input pin for current measurement
const float R1 = 1000.0; // Resistance value of R1 in ohms
const float R2 = 1000.0; // Resistance value of R2 in ohms
void setup() {
Serial.begin(9600); // Initialize serial communication
}
void loop() {
// Read the analog input
int sensorValue = analogRead(analogInPin);
// Convert analog reading to voltage
float voltage = sensorValue * (5.0 / 1023.0); // Assuming 5V reference
// Calculate current using voltage divider formula
float current = voltage / ((R1 + R2) / R2); // I = V / (R1 + R2)
// Print current value to serial monitor
Serial.print("Current: ");
Serial.print(current, 3); // Print with 3 decimal places
Serial.println(" A");
delay(1000); // Delay for readability
}