wu66666 发表于 2017-5-17 19:59:07

MSP430G2Launchpad户外实时紫外线检测系统LCD1602和串口窗口显示

第一次发帖,就简便一点。
需要工具:MSP430G2 launchpad,杜邦线公母/母母若干,面包版,紫外线传感器UVM30A(out接P1.4,输出范围0—3V),LCD1602


// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 13, 8, 9, 10, 11);//LiquidCrystal(rs, enable, d4, d5, d6, d7)前面引脚分别对应这些
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);//1602两行16列
// Print a message to the LCD.
   Serial.begin(9600);//串口初始化
analogReference(DEFAULT); //以VCC3.57V为基准电压
}
void loop() {
lcd.clear();//清零
delay(50);
float sensorValue = analogRead(A4); //P1.4的模拟量
float vol = sensorValue * (3.57 / 1020.0*1000);//转换为标准电压MV
int UV =0.0034*vol;//紫外线指数
Serial.print("vol: ");
Serial.println(vol);
Serial.print("UV: ");
Serial.println(UV);//串口打印
lcd.setCursor(0, 0); //行列起始值都为0
lcd.print("UV Index: ");//第一行第一列开始显示“UV Index: ”
lcd.setCursor(10, 0);
lcd.print(UV);//第一行第11列显示UV值
delay(5000);
}


因为是晚上,UVM30A无法采集数据,将电压源3.57V直接接到模拟信号采集口P1.4,3.57*1000*0.0034=12
页: [1]
查看完整版本: MSP430G2Launchpad户外实时紫外线检测系统LCD1602和串口窗口显示