java温度传感器用法,如何从Arduino Lilypad温度传感器获取环境温度

//TMP36 Pin Variables

int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to

//the resolution is 10 mV / degree centigrade with a

//500 mV offset to allow for negative temperatures

#define BANDGAPREF 14 // special indicator that we want to measure the bandgap

/*

* setup() - this function runs once when you turn your Arduino on

* We initialize the serial connection with the computer

*/

void setup()

{

Serial.begin(9600); //Start the serial connection with the computer

//to view the result open the serial monitor

delay(500);

}

void loop() // run over and over again

{

// get voltage reading from the secret internal 1.05V reference

int refReading = analogRead(BANDGAPREF);

Serial.println(refReading);

// now calculate our power supply voltage from the known 1.05 volt reading

float supplyvoltage = (1.05 * 1024) / refReading;

Serial.print(supplyvoltage); Serial.println("V power supply");

//getting the voltage reading from the temperature sensor

int reading = analogRead(sensorPin);

// converting that reading to voltage

float voltage = reading * supplyvoltage / 1024;

// print out the voltage

Serial.print(voltage); Serial.println(" volts");

// now print out the temperature

float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset

//to degrees ((volatge - 500mV) times 100)

Serial.print(temperatureC); Serial.println(" degress C");

// now convert to Fahrenheight

float temperatureF = (temperatureC * 9 / 5) + 32;

Serial.print(temperatureF); Serial.println(" degress F");

delay(1000); //waiting a second

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值