int apin =A0;
int r = 12;
void setup() {
Serial.begin(115200);
pinMode(r, OUTPUT);
}
void loop() {
int val = analogRead(apin);
Serial.print("Analog value = ");
Serial.println(val);
delay(100);
if (val >= 512)
{
digitalWrite(r, HIGH);
}
else digitalWrite(r, LOW);
}