(3.3V)M5Stamp S3で温度センサー、Grove-Temperature_Sensorで遊ぶ


x かころぐみよ

参考


https://wiki.seeedstudio.com/Grove-Temperature_Sensor/


結果




![o_coq374.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/210193ee-aa31-1ec0-8843-aac7199c59a0.jpeg)




![o_coq375.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/84b57c0d-a38f-12b6-a6ac-d9f947192d85.jpeg)

![o_coq376.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/3ff5fc35-5380-b64c-a900-3ad95ad8b964.jpeg)

![o_coq377.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/b4d8a850-8c43-5926-60fe-7bfc87bcc918.jpeg)


いろいろ(NT東京へ行った)

![o_coq378.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/9e6e4aba-0038-2557-7c4c-9f3a6bafb47f.jpeg)



プログラム(おもに3.3V化)


```c++

/*
/* Grove - Temperature Sensor demo v1.0
*  This sensor detects the environment temperature,
*  Connect the signal of this sensor to A0, use the
*  Serial monitor to get the result.
*  By: https://www.seeedstudio.com
*/
#include <math.h>
int a;
float temperature;
int B=3975;                  //B value of the thermistor
float resistance;

void setup()
{
    Serial.begin(9600);
}

void loop()
{
    //a=analogRead(0);
    a=analogRead(15);
    //resistance=(float)(1023-a)*10000/a; //get the resistance of the sensor;

    float v1,a1,o1; 
    v1 = ((float)a)*(3.3/4096.0); //電圧を求める
    a1 = v1 / 10000.0;            //電流を求める
    o1 = 5.0 / a1;                //全体の抵抗を求める
    resistance = o1 - 10000.0;    //全体の抵抗から検出抵抗を引く
    //Serial.println(v1); //debug
        
    temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;//convert to temperature via datasheet&nbsp;;
    delay(1000);
    Serial.print("Current temperature is ");
    Serial.println(temperature);
}



```

--------------------------


●おまけ
--------------------------


```c++


#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
    printf("START\n");

    int p;
    float resistance;
    int vo;
    
    float v1,a1,o1;

    for(int i = 0;i<1024;i = i + 32){

        p = i;
        resistance=(float)(1023-p)*10000/p;
        
        vo = (i * 5000)/1024;
        
        v1 = ((float)i)*(5.0/1023);
        a1 = v1 / 10000;
        o1 = 5.0 / a1;
        o1 = o1 - 10000;
        
        printf("(%4dmV) (%5.2fK) <%5.2fK>",vo,resistance/1000,o1/1000);
        
        printf("\n");

    }//for
    
    
    
    
}




```



```


START
(   0mV) (  infK) <  infK>
( 156mV) (309.69K) <309.69K>
( 312mV) (149.84K) <149.84K>
( 468mV) (96.56K) <96.56K>
( 625mV) (69.92K) <69.92K>
( 781mV) (53.94K) <53.94K>
( 937mV) (43.28K) <43.28K>
(1093mV) (35.67K) <35.67K>
(1250mV) (29.96K) <29.96K>
(1406mV) (25.52K) <25.52K>
(1562mV) (21.97K) <21.97K>
(1718mV) (19.06K) <19.06K>
(1875mV) (16.64K) <16.64K>
(2031mV) (14.59K) <14.59K>
(2187mV) (12.83K) <12.83K>
(2343mV) (11.31K) <11.31K>
(2500mV) ( 9.98K) < 9.98K>
(2656mV) ( 8.81K) < 8.81K>
(2812mV) ( 7.76K) < 7.76K>
(2968mV) ( 6.83K) < 6.83K>
(3125mV) ( 5.98K) < 5.98K>
(3281mV) ( 5.22K) < 5.22K>
(3437mV) ( 4.53K) < 4.53K>
(3593mV) ( 3.90K) < 3.90K>
(3750mV) ( 3.32K) < 3.32K>
(3906mV) ( 2.79K) < 2.79K>
(4062mV) ( 2.30K) < 2.30K>
(4218mV) ( 1.84K) < 1.84K>
(4375mV) ( 1.42K) < 1.42K>
(4531mV) ( 1.02K) < 1.02K>
(4687mV) ( 0.66K) < 0.66K>
(4843mV) ( 0.31K) < 0.31K>




```