728x90
출처
BPI-Bit : 온도 센서 사용하기
BPI-Bit에는 온도 센서 모둘이 내장 되어 있습니다. 예제를 통해서 온도 값을 입력 받아보겠습니다.
GPIO control of BPI:bit
GPIO control of BPI:bit | |||
Light Sensor(L) | GPIO 36 | Analog Input | |
Light Sensor(R) | GPIO 39 | Analog Input | |
Botton A | GPIO 35 | Digital Input | |
Botton B | GPIO 27 | Digital Input | |
Temperature Sensor | GPIO 34 | Analog Input | |
Buzzer | GPIO 25 | PWM(Digital Output) / Analog Output | |
RGB_LED | GPIO 4 | Digital Output | |
MPU9250_SCL | GPIO 22 | Digital Output | |
MPU9250_SDA | GPIO 21 | Digital Output | |
MPU9250_INT | GPIO 16 | Digital Input | |
R_LED(SPI_SCK) | GPIO 18 | Digital Output |
예제 소스
// GPIO 핀 #define Temp 34 //ADC2_CH7 // temperature config const float voltagePower = 3.3; const float Rs = 5.1; //Sampling Resistance is 5.1K ohm const int B = 3950; const double T = 273.15 + 25; //Normal Temperature Parameters const double R1 = 10; //Normal Temperature Resistance (K ohm) double Temp_Value = 0; void setup() { Serial.begin(115200); //Serial Port Config 115200-8-N-1 pinMode(TEMPERATURE_SENSOR, INPUT);//TEMPERATURE_SENSOR(IO34) Input Mode } void loop() { Temp_Value = analogRead(TEMPERATURE_SENSOR);//Read Analog Value double voltageValue = (Temp_Value / 4095) * 3.3;// Serial.print("Current voltage value="); Serial.println(voltageValue); //Thermistor value double Rt = ((voltagePower - voltageValue) * Rs) / voltageValue; Serial.print("Current registor value="); Serial.println(Rt); //Temperature value Serial.print("Current temperature value="); Serial.println(((T * B) / (B + T * log(Rt / R1))) - 273.15); Serial.println(); delay(500); }
실행 결과
728x90