I know this is simple, but i was pleased as punch to make this little app that will output the ohms of an unknown resistor in a voltage divider when you only know the R of one of the two. I'm applying this to making an NTC based temp probe app.
#include <stdio.h>
#include <math.h>
int analoginput=4;
int vin=5;
int knownResistor = 1000;
void setup() {
pinMode(analoginput, INPUT);
Serial.begin(9600);
}
void loop()
{
int raw = analogRead(analoginput);
float vout = fmap(raw, 0, 1023, 0.0, 5.0);
int unknownResistance = knownResistor * vout/(vin-vout);
Serial.println(unknownResistance);
delay(1000);
}
float fmap(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}