Skip to content

Instantly share code, notes, and snippets.

@An-Toha
Created August 31, 2022 14:02
Show Gist options
  • Save An-Toha/5a53f4fbe571c1b9cf02b362a83e93df to your computer and use it in GitHub Desktop.
Save An-Toha/5a53f4fbe571c1b9cf02b362a83e93df to your computer and use it in GitHub Desktop.
This is sketch for internal temperature sensor ESP32 CPU. * The main ideas are: * to ignore 53.3 (128 before converting to Celsius); * WiFi must be connected, if else you'll get 53.3 (128) only. * * Tested in AI Thinker ESP32 Cam module. Can be add to standard camera example in Arduino. * While ESP32 Cam module was idle - the temperature was aro…
/*This is sketch for internal temperature sensor ESP32 CPU.
* The main ideas are:
* to ignore 53.3 (128 before converting to Celsius);
* WiFi must be connected, if else you'll get 53.3 (128) only.
*
* Tested in AI Thinker ESP32 Cam module. Can be add to standard camera example in Arduino.
* While ESP32 Cam module was idle - the temperature was around 47*C.
* While camera video stream was on - the temperature was rising to around 57*C.
* See temperature values in serial monitor at 115200.
* Best regards, Anton S
*/
#include <WiFi.h>
// Replace with your network credentials
const char* ssid = "your SSID";
const char* password = "your pass";
//Intermal temperature sensor function declaration
#ifdef __cplusplus
extern "C" {
#endif
uint8_t temprature_sens_read();
#ifdef __cplusplus
}
#endif
uint8_t temprature_sens_read(); //declare intermal temperature sensor function
uint32_t n; //number of measurement
uint32_t timer; //time from start
uint32_t tm1; //start moment
void setup() {
Serial.begin(115200);
//Standart Wi-Fi connection
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println(WiFi.localIP());
//Table headers in serial monitor number, time(minutes), temperature Celsius
Serial.print("Number\t");
Serial.print("time\t");
Serial.print("temp,C*\n");
int n = 0; //set measurement number to 0 at setup
tm1 = millis(); //set start moment to millis at setup
}
void loop() {
// do something your's, for example increment c-variable
uint8_t c;
c++;
// read internal sensor and print to Serial
if ((temprature_sens_read()) != 128) { //ignore 128 (53.33 C) measurement
n++; //number increment
Serial.print(n); Serial.print("\t"); //print number and tab
timer = millis() - tm1; //get meassurement moment
Serial.print(timer / 60000.0); Serial.print("\t"); //print measurement time (minutes) and tab
Serial.print((temprature_sens_read() - 32) / 1.8); //print Celsius temperature and tab
Serial.print("\n"); //print new line
delay(1000); //read temperature 1 times per sec
}
delay(1000); //delay in loop
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment