Read Pin State

Hii There

My Setup:
Arduino MKR1010
kemo rain detector m152

This rain detector is connect to my Arduino Pin A4/Ground and open/Closes a internal contact.

How can i read the state of that Pin (High/Low) and save it as a variable for later use?

You have to adapt this to your blynk sketch

int inPin = 4;   
int val = 0;      // variable to store the read value

void setup() {
   pinMode(inPin, INPUT);    // sets the digital pin 4 as input
}

void loop() {
  val = digitalRead(inPin);   // read the input pin
 }

This doesn’t sound like it’s a Blynk related question at all.

You’d normally connect a sensor that gives an analog output (values between 0 and 1023 for example) to an antilog pin, and digital sensors that give a HIGH/LOW output to a digital pin.
Having said that, analog pins can be make to work like digital pins if required.

You need to declare the oin as an input in your void setup, the read the value using either a digitalRead() or analogRead command.

Pete.

1 Like

kemo rain detector m152 has only a relay output state wire :wink:
2022-01-15_183011

Im sooorry, what does that mean? :grimacing:

Hi Blynk_Coeur

Thanks a lot for the answer

but how can i store the value 1 / high instead of 0 ?

int inPin = 4; int val = 0; // variable to store the read valu

If i use 1, i think it takes pin1 instead of value 1

@Avi1 This is a Blynk forum, not a C++ Coding 101 forum.

I’d suggest that you either ask a Blynk related question or take a crash-course in C++ coding.

Pete.

1 Like

val store any result 0 or 1
val = digitalRead(inPin);

1 Like