Hi Guys,
I want to add an option in my code that reads my R2 value and if it is => i want it to change an LED, basic i know but I'm a bit stumped.
At the moment the project reads a resistor vale as long as there is information on A0 to read and prints the value to the serial monitor. if there is no information on A0 it flashes the LED's pin 2 & 3.
I want it to do the math read R2 and then, if the value is too high light an LED (pin 3) if it can do the math and its in range then light another LED (pin2). if it cant do the math the the LED's flash.
int Vin=5; //voltage at 5V pin of arduino
float Vout=0; //voltage at A0 pin of arduino
float R1=220; //value of known resistance
float R2=0; //value of unknown resistance
int a2d_data=0;
float buffer=0;
float var= R2;
void setup()
{
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
}
void loop()
{
a2d_data=analogRead(A0);
if(a2d_data)
{
buffer=a2d_data*Vin;
Vout=(buffer)/1024.0;
buffer=Vout/(Vin-Vout);
R2=R1*buffer;
Serial.println(R2);
digitalWrite(2, HIGH);
delay(1000);
}
else
{
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
delay(1000);
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
delay(1000);
}
}