下面介紹一下我的Seeeduino V3/Arduino UNO玩板經驗,供大家學習參考,通過下面四個小項目從淺入深介紹Seeeduino V3在生活中的應用
使用LCD1602液晶屏顯示文字
使用DHT11溫濕度傳感器測量溫濕度并在LCD1602液晶屏顯示環境溫濕度
使用HC-SR04超聲波模塊測距并在LCD1602液晶屏顯示物體間距
使用RTC模塊DS1307和DHT11溫濕度傳感器在LCD1602液晶屏顯示時間日期工作日和環境溫濕度數據
開發環境搭建:
Seeeduino V3/Arduino UNO需要下載Arduino IDE來編程和燒寫到開發板,到官網根據操作系統下載安裝Arduino IDE即可,
安裝好Arduino IDE后打開程序按下圖選擇開發板類型
?
然后將Seeeduino V4.2用手機USB線連接到電腦的USB口,安裝下面驅動
然后會在設備管理器里面看出USB串行設備記下串口號
?
在Arduino IDE里面修改串口號為上面串口號
這樣就完成了開發環境的配置
一、使用LCD1602液晶屏顯示文字
下面從最簡單的使用LCD1602液晶屏顯示文字開始學習,為了減少連接線,使用I2C方式連接LCD1602
硬件連接方法:
LCD1602的VCC GND SDA SCL分別連接到seeed紅版(Arduino uno r3)增強板的5V GND A4 A5,然后使用數據線連接seeed紅版(Arduino uno r3)增強板和電腦
查看LCD1602的I2C地址:
首先打開Arduino IDE,輸入下面sketch掃描i2c地址
#include void setup(){ Wire.begin(); Serial.begin(115200); Serial.println(" I2C Scanner");}void loop(){ byte error, address; int nDevices; Serial.println("Scanning..."); nDevices = 0; for(address = 1; address < 127; address++ ) { Wire.beginTransmission(address); error = Wire.endTransmission(); if (error == 0) { Serial.print("I2C device found at address 0x"); if (address<16) Serial.print("0"); Serial.print(address,HEX); Serial.println(" !"); nDevices++; } else if (error==4) { Serial.print("Unknow error at address 0x"); if (address<16) Serial.print("0"); Serial.println(address,HEX); } } if (nDevices == 0) Serial.println("No I2C devices found "); else Serial.println("done "); delay(5000);}
然后上傳開發板運行
然后打開串口檢測
查看串口信息如下
?
可知液晶屏i2c地址3f,然后打開庫管理,搜索Liquid Crystal I2C庫并安裝
然后創建一個新sketch,輸入下面
#include #include LiquidCrystal_I2C lcd(0x3f,16,2);void setup(){lcd.init();// Print a message to the LCD.lcd.backlight();lcd.print("www.ickey.cc");}void loop(){}上傳后效果如下
二、使用DHT11溫濕度傳感器測量溫濕度并在LCD1602液晶屏顯示環境溫濕度
硬件連接方法:
LCD1602連接方法和之前一樣,使用I2C連接方法,將VCC GND SDA SCL分別連接開發板的5V GND A4 A5
DHT11的VCC GND DATA連接開發板的3V3 GND D7
軟件配置方法:
需要安裝的庫LiquidCrystal_I2C、DHT11,dht11庫可以按下圖安裝
?
然后加入選擇下面文件即可安裝DHT11庫
?
然后創建一個sketch
?
然后上傳到開發板運行效果如下
三、使用HC-SR04超聲波模塊測距并在LCD1602液晶屏顯示物體間距
硬件連接方法:
將LCD1602使用I2C連接到開發板,SDA SCL分別連接開發板上SDA SCL,LCD1602的VCC GND連接到開發板JP3的VCC GND
將HC-SR04超聲波傳感器的VCC GND TRIG ECHO分別連接到開發板的5V GND D0 D1
軟件配置方法:
打開Arduino IDE,確認安裝LiquidCrystal_I2C庫后新建sketch,輸入下面代碼
#include #include #define Trig 0#define Echo 1 float cm;float range; LiquidCrystal_I2C lcd(0x3F,16,2); void setup() { pinMode(Trig, OUTPUT); pinMode(Echo, INPUT); lcd.init(); lcd.backlight();} void loop() { digitalWrite(Trig, LOW); delayMicroseconds(2); digitalWrite(Trig,HIGH); delayMicroseconds(10); digitalWrite(Trig, LOW); range = float(pulseIn(Echo, HIGH)); cm = range*0.034/2; lcd.setCursor(0,0); lcd.print("D = "); lcd.print(cm); lcd.setCursor(0,1); lcd.print("Distance in CM"); delay(500); }
上傳后運行如下圖
四、使用RTC模塊DS1307和DHT11溫濕度傳感器在LCD1602液晶屏顯示時間日期工作日和環境溫濕度數據
硬件連接方法:
LCD1602的SDA SCL分別連接到開發板A4 A5,LCD1602的VCC GND連接開發板JP3的VCC GND
DS1307模塊的VCC GND SDA SCL連接開發板的5V GND SDA SCL
DHT11溫濕度傳感器的VCC GND DATA連接開發板的3V3 GND D7
軟件配置方法:
打開Arduino IDE安裝RTCLIB庫、LiquidCrystal_I2C庫、DHT Sensor Library by Adafruit庫、Adafruit Unified Sensor庫
新建sketch輸入下面代碼
#include #include #include "DHT.h"#include #define DHTPIN 7#define DHTTYPE DHT11DHT dht(DHTPIN, DHTTYPE);float hum;float temp;LiquidCrystal_I2C lcd(0x3F,16,2);RTC_DS1307 RTC;char daysOfTheWeek[7][12] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};void setup () { Serial.begin(9600); lcd.init(); lcd.backlight(); dht.begin(); Wire.begin(); RTC.begin(); RTC.adjust(DateTime(__DATE__, __TIME__)); }void loop () { int h = dht.readHumidity(); int t = dht.readTemperature(); DateTime now = RTC.now(); Serial.print(now.year(), DEC); Serial.print('-'); Serial.print(now.month(), DEC); Serial.print('-'); Serial.print(now.day(), DEC); Serial.print(' '); Serial.print(now.hour(), DEC); Serial.print(':'); Serial.print(now.minute(), DEC); Serial.print(':'); Serial.print(now.second(), DEC); Serial.print(' '); Serial.print(daysOfTheWeek[now.dayOfTheWeek()]); Serial.println(); lcd.setCursor(0,0); lcd.print(now.year(), DEC); lcd.print('-'); lcd.print(now.month(), DEC); lcd.print('-'); lcd.print(now.day(), DEC); lcd.print(' '); lcd.print(daysOfTheWeek[now.dayOfTheWeek()]); delay(1000); lcd.setCursor(0,1); lcd.print(now.hour(), DEC); lcd.print(':'); lcd.print(now.minute(), DEC); lcd.print(':'); lcd.print(now.second(), DEC); lcd.print(' '); lcd.setCursor(9,1); lcd.print(t); lcd.print("C"); lcd.print(" "); lcd.print(h); lcd.print("%");}效果如下
評論
查看更多