// Pin definitions
const int fabricVoltagePin = A0; // Pin to measure voltage across the fabric
const int resistorVoltagePin = A1; // Pin to measure voltage across the 500-ohm resistor
const float supplyVoltage = 5.0; // Supply voltage in volts
const float resistorValue = 500.0; // Resistor value in ohms
void setup() {
Serial.begin(9600); // Initialize serial communication
}
void loop() {
// Measure the voltage across the fabric
int fabricAnalogValue = analogRead(fabricVoltagePin);
float fabricVoltage = (fabricAnalogValue / 1023.0) * supplyVoltage;
// Measure the voltage across the 500-ohm resistor
int resistorAnalogValue = analogRead(resistorVoltagePin);
float resistorVoltage = (resistorAnalogValue / 1023.0) * supplyVoltage;
// Calculate the current through the resistor (and fabric) using Ohm's Law
float current = resistorVoltage / resistorValue; // Current in amperes
// Calculate the resistance of the fabric using Ohm's Law
if (current > 0) { // Avoid division by zero
float fabricResistance = fabricVoltage / current;
Serial.print("Fabric Resistance: ");
Serial.print(fabricResistance);
Serial.println(" ohms");
} else {
Serial.println("Error: Current is zero or invalid");
}
// Print the current for monitoring
Serial.print("Current through fabric: ");
Serial.print(current * 1000); // Convert to mA for easier reading
Serial.println(" mA");
delay(1000); // Wait 1 second before the next reading
}