1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

Last updated at Posted at 2024-09-07

x かころぐみよ

参考

結果

o_coq374.jpg

o_coq375.jpg

o_coq376.jpg

o_coq377.jpg

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

o_coq378.jpg

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


/*
/* 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);
}




●おまけ



#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>




1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?