Hi All,
I am trying to build a circuit that measure an unknown resistor. then check to see if the value is within a range. if the resistance is withing range then all is good and a green led is on. if not then a red led is triggered and a relay. I have had this working on an Arduino but am having a few issues when converting to Partical. I believe the fault is with the Vin value as the Arduino would have been 5v and the Partical is 3.3v.
Any help would be appreciated, I’m sure the issue is with the maths but I’m now all a muddle.
Ref: http://www.circuitbasics.com/arduino-ohm-meter/
int Vin=3.3; //voltage at 3.3V pin of Photon
float Vout=0; //voltage at A0 pin of Photon
float R1=8200.0; //value of known resistance
float R2=0; //value of unknown resistance
int Edge_data=0;
float buffer=0;
float var= R2;
int GreenLED = D2;
int RedLED = D3;
int Relay = D4;
void setup()
{
pinMode(GreenLED, OUTPUT);
pinMode(RedLED, OUTPUT);
pinMode(Relay, OUTPUT);
Particle.variable("Edge_data", &Edge_data, INT);
}
void loop()
{
Edge_data=analogRead(A0);
if(Edge_data)
{
buffer=Edge_data*Vin;
Vout=(buffer)/1024.0;
buffer=Vout/(Vin-Vout);
R2=R1*buffer;
// Insert your check here
if (R2 > 8000 && R2 < 8300)
//if(R2 >= 8300)
{
digitalWrite(RedLED, LOW); // In Range
digitalWrite(GreenLED, HIGH);
digitalWrite(Relay, LOW);
}
else
{
digitalWrite(GreenLED, LOW);
digitalWrite(RedLED, HIGH);
delay(1000); // Out of Range or short
}
{
digitalWrite(Relay, HIGH);
}
}
}