LoginSignup
0
0

More than 1 year has passed since last update.

Arduino UNOと温度センサーS-8120Cで温度をシリアル出力(整数)

Last updated at Posted at 2022-07-10

目的
安価に温度を測る。

v = -8.2 * t + 1705

式の変形

t = (v - 1705.0) / -8.2;

t = DIV082( (1705 - v) );

o_con569.jpg

o_con572.jpg

ADCの値を5Vに変換は、親切な人に教えて貰った。
1024*39.0625=40000
    40000/4=5000

プログラム



//SER_S-8120C_DEC_UNO_1

//0.82で割る 0から400までは、なんとなく正しい+-1
#define DIV082(n) (((n)*78)>>6)

#include <Arduino.h>

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

  //シリアルの初期化
  Serial.begin(9600);

} //setup

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

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

  //センサーのADC値を電圧に変換
  int v = ( ( (unsigned int)0b100111 * (unsigned int)s + (s >> 4 ) ) >> 3);

  //センサーの電圧を温度に変換 温度の10倍を出力 ex 20.1 => 201
  // v = -8.2 * t + 1705  =>  t = (v - 1705.0) / -8.2;
  // => t = (1705 - v) / 0.82
  int t = DIV082( (1705 - v) );

  //温度の表示
  Serial.print(t / 10);
  Serial.print('.');
  Serial.print(t % 10);
  Serial.println();

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

} //loop




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