樹莓派練習程序(土壤溼度檢測)

土壤溼度檢測模塊以下:git

樹莓派的引腳以下圖:編程

咱們將Vcc引腳鏈接物理接口2,GND引腳鏈接物理接口39,DO引腳鏈接物理接口40。編碼

實物鏈接以下圖:spa

編程使用WiringPi庫,使用wpi引腳編碼方式控制GPIO。code

代碼以下:blog

#include <wiringPi.h> #include <stdio.h> #include <sys/time.h>

#define GuanMin    29

int main(void) { if (wiringPiSetup() == -1) { printf("setup wiringPi failed !"); return 1; } pinMode(GuanMin, INPUT); 
    
    while (1) { if (digitalRead(GuanMin) == 1) { printf("Dry\n"); delay(333); } else { printf("water detected\n"); delay(333); } } return 0; }

輸出結果:接口

相關文章
相關標籤/搜索