Photon Ohms meter, Help needed

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);
                            }
        }
        
          
}

That's not the only difference.
You also need to consider the Photon's ADCs are spreading the 3.3V over 12 bit (0..4095) opposed to 5V over 10 bit (0..1023).

Hence this has to be changed too

BTW, to be exact that would need to be 1023.0 on Arduino to get 5V * 1023/1023.0 = 5V * 1.0

2 Likes

Thank you so much, I will give that ago. I really appreciate your fast response and advice. :+1:

1 Like