Módulo sensor de nível de água para Arduino Keyestudio
Product name: Water Sensor
Operating voltage: DC5V
Operating current: ﹤20mA
Sensor type: Analog
Detection area: 40mm x16mm
Production process: FR4 double-side tinned
Humanized design: Anti-slippery semi-lunar recess
Operating temperature: 10%~90% without condensation
Product weight: 3g
Product size: 65mm x 20mm x 8mm
int analogPin = 0; //connect water sensor to analog interface 0
int led = 13; //LED to digital interface 13
int val = 0; //define the initial value of variable ‘val’ as 0
int data = 0; //define the initial value of variable ‘data’ as 0
void setup()
{
pinMode(led, OUTPUT); //define led as output pin
Serial.begin(9600); //set baud rate at 9600
}
void loop()
{
val = analogRead(analogPin); //read and assign analog value to variable ’val’
if(val>700){ //decide whether variable ‘val’ is over 700 digitalWrite(led,HIGH); //turn on LED when variable ‘val’ is over 700
}
else{
digitalWrite(led,LOW); //turn off LED when variable ‘val’ is under 700
}
data = val; //variable ’val’ assigns value to variable ‘data’
Serial.println(data); //print variable ‘data’ by Serial.print
delay(100);
}