LoginSignup
0
0

ArduinoUNOと温度センサーMCP9701で温度をシリアル出力2(map文,使用)

Last updated at Posted at 2022-06-18

x MCP9701-E/TO 販売コード 103199

x ADC値から電圧の変換は、親切な人(@fujitanozomu)がいたので改造して使用

目的
安価に温度を測る。

秋月で売っている安いやつ

1℃ → 19.5mV ステップ

0℃ → 400mV センター

0V → -20.512820512820512820512820512821℃
0.4V → 0℃
3.3V → 148.71794871794871794871794871794‬℃
5V → 235.89743589743589743589743589744℃

数学的 計算式 sは、ADC値 Vは、電圧 tは、温度


v = s * (5.0/1024.0)
t = v * (1.0 / 0.0195)  - (0.4 * (1.0 / 0.0195)) )


その2


v = s * (5.0/1024.0);

t = (v - 0.4) * (1.0 / 0.0195) 

o_con542.jpg

o_con541.jpg

デバッグ時

o_con540.jpg



//SER_MCP9701_MAP_UNO_1

#include <Arduino.h>

//初期化処理
void setup()
{

  Serial.begin(9600);

} //setup

//メインループ
void loop()
{

  //センサーの値を読み込む
  int s = analogRead(A0); // UNO

  //s = 82;   //debug
  //s = 1024; //debug
  //Serial.print("Debug Voltage[");
  //Serial.print( ( (unsigned int)0b100111 * (unsigned int)s + (s >> 4 ) ) >> 3);
  //Serial.println("]");

  //センサーのADC値を温度に変換
  int t = map(s, 0, 1024, -205, 2359);

  //温度の小数点以上の表示
  Serial.print(t / 10);

  //小数点の表示
  Serial.print('.');

  //温度の小数点以下の表示
  Serial.println(t % 10);

  //1秒の待ち
  delay(1000);

} //loop



3.3系の変換


  //センサーのADC値を温度に変換
  int t = map(s, 0, 1024, -205, 1487);

標準C言語で温度を求める式(浮動小数点)





#include <stdio.h>
int main(void){


float s = 0;
float v = 0;

for(int ii=1020;ii<1025;ii++){



printf("%d=",ii);

s = ii;
v = s * (5.0/1024.0);

printf("[%f]",v);
printf("(%f)\r\n",v * (1.0 / 0.0195)  - (0.4 * (1.0 / 0.0195)) );

}//for
    
}



0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0