![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
water sansor 1
sensor.h@0:2b430503298a, 2017-10-27 (annotated)
- Committer:
- paris8022
- Date:
- Fri Oct 27 03:54:15 2017 +0000
- Revision:
- 0:2b430503298a
- Child:
- 1:06e9441a6f01
water sansor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
paris8022 | 0:2b430503298a | 1 | int ledPin = 13; //連接13針上的LED,或者使用板載的LED |
paris8022 | 0:2b430503298a | 2 | int sensor_in = 2; //將濁度傳感器連接到數字引腳2 |
paris8022 | 0:2b430503298a | 3 | |
paris8022 | 0:2b430503298a | 4 | void setup(){ |
paris8022 | 0:2b430503298a | 5 | pinMode(ledPin,OUTPUT); //將ledPin設為輸出模式 |
paris8022 | 0:2b430503298a | 6 | pinMode(sensor_in,INPUT); //將濁度傳感器引腳設置為輸入模式 |
paris8022 | 0:2b430503298a | 7 | } |
paris8022 | 0:2b430503298a | 8 | |
paris8022 | 0:2b430503298a | 9 | void loop(){ |
paris8022 | 0:2b430503298a | 10 | if(digitalRead(sensor_in)== LOW){//讀取傳感器信號 |
paris8022 | 0:2b430503298a | 11 | digitalWrite(ledPin,HIGH); //如果傳感器為低電平,則開啟 |
paris8022 | 0:2b430503298a | 12 | }else{ |
paris8022 | 0:2b430503298a | 13 | digitalWrite(ledPin,LOW); //如果傳感器為高電平,則關閉LED |
paris8022 | 0:2b430503298a | 14 | } |
paris8022 | 0:2b430503298a | 15 | } |