water sansor 1

Dependencies:   mbed

sensor.h

Committer:
paris8022
Date:
2017-10-27
Revision:
0:2b430503298a
Child:
1:06e9441a6f01

File content as of revision 0:2b430503298a:

int ledPin = 13; //連接13針上的LED,或者使用板載的LED
int sensor_in = 2; //將濁度傳感器連接到數字引腳2

void setup(){
  pinMode(ledPin,OUTPUT); //將ledPin設為輸出模式
  pinMode(sensor_in,INPUT); //將濁度傳感器引腳設置為輸入模式
}

void loop(){
   if(digitalRead(sensor_in)== LOW){//讀取傳感器信號 
        digitalWrite(ledPin,HIGH); //如果傳感器為低電平,則開啟
     }else{
        digitalWrite(ledPin,LOW); //如果傳感器為高電平,則關閉LED
     }
}