极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 22849|回复: 0

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

[复制链接]
发表于 2017-5-17 19:59:07 | 显示全部楼层 |阅读模式
第一次发帖,就简便一点。
需要工具:MSP430G2 launchpad,杜邦线公母/母母若干,面包版,紫外线传感器UVM30A(out接P1.4,输出范围0—3V),LCD1602


[kenrobot_code]// 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);
}[/kenrobot_code]


因为是晚上,UVM30A无法采集数据,将电压源3.57V直接接到模拟信号采集口P1.4,3.57*1000*0.0034=12

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-25 19:26 , Processed in 0.039192 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表