Professional Documents
Culture Documents
Objective:
Circuit Diagram:
Code:
const int analogPin = A0; // Analog pin for voltage measurement
const float knownVoltage = 5.0; // Known voltage (in volts)
void setup() {
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
float voltage = analogRead(analogPin) * (knownVoltage / 1023.0); // Read analog voltage
float current = (knownVoltage - voltage) / resistorValue(); // Calculate current
float resistance = voltage / current; // Calculate resistance
Serial.print("Resistance: ");
Serial.print(resistance);
Serial.println(" ohms");
float resistorValue() {
// Replace with the actual value of the resistor connected to A0
return 1000.0; // Example: 1k ohm resistor
}
Conclusion :