Here is the code:
float v;
float voltage;
float i;
float current;
float impedance;
void setup()
{
Serial.begin(9600);
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(11,OUTPUT); //Z
pinMode(12,OUTPUT); //I
pinMode(13,OUTPUT); //V
}
void loop() {
v=analogRead(A0);
voltage=0.152*v;
Serial.print(“v=”);
Serial.print(v);
Serial.println();
Serial.print(“voltage=”);
Serial.print(voltage);
Serial.println();
Serial.println();
if(v>600)
{
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
}
else
{
digitalWrite(13,LOW);
}
i=analogRead(A1);
Serial.print(“i=”);
Serial.println(i);
current=(5*i)/(1023*15);
Serial.print(“current=”);
Serial.println(current);
Serial.println();
if(i>700)
{
digitalWrite(12,HIGH);
digitalWrite(11,LOW);
}
else
{
digitalWrite(12,LOW);
}
impedance=voltage/current;
Serial.print(“Impedance=”);
Serial.print(impedance);
Serial.println();
if(impedance<260)
{
digitalWrite(11,HIGH);
digitalWrite(12,LOW);
}
else
{
digitalWrite(11,LOW);
}
delay(200);
}