Grove - Temperature Sensor

From
Jump to: navigation, search

Grove - Temperature Sensor (Seeed-Studio)

Caractéristiques

Temperature Sensor v1.2
Thermistance: NCP18WF104F03RC (NTC)

Temperature Sensor top.jpg Temperature Sensor back.jpg

Tableau

Seeed-Studio
Seeeduino Sensor

5V

Red

GND

Black

Not Conencted

White

A0

Yellow

Grove - Temperature Sensor -

Support

Connecter le 'Grove - Temperature Sensor' au connecteur A0

Voltage

3.3 ~ 5V

Port

connectez au port A0

Code Exemple

	// Demo code for Grove - Temperature Sensor V1.1/1.2
	// Loovee @ 2015-8-26

	#include <math.h>

	const int B = 4275;               // B value of the thermistor
	const int R0 = 100000;            // R0 = 100k
	const int pinTempSensor = A0;     // Grove - Temperature Sensor connect to A0

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

	void loop()
	{
		int a = analogRead(pinTempSensor);

		float R = 1023.0/a-1.0;
		R = R0*R;

		float temperature = 1.0/(log(R/R0)/B+1/298.15)-273.15; // convert to temperature via datasheet

		Serial.print("temperature = ");
		Serial.println(temperature);

		delay(1000);
	}

Résultat

pas oublier d'indiquer 9600

Grove - Temperature Sensor.jpg



Code avec Oled

// Demo code for Grove - Temperature Sensor V1.1/1.2
	// Loovee @ 2015-8-26

  #include <Arduino.h>
  #include <U8x8lib.h>
  #include <Wire.h>

	U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);   // OLEDs without Reset of the Display

	#include <math.h>

	const int B = 4275;               // B value of the thermistor
	const int R0 = 100000;            // R0 = 100k
	const int pinTempSensor = A0;     // Grove - Temperature Sensor connect to A0

	void setup()
	{
		u8x8.begin();
  	u8x8.setFlipMode(1);   // set number from 1 to 3, the screen word will rotary 180

		Serial.begin(9600);
	}

	void loop()
	{
		int a = analogRead(pinTempSensor);

		float R = 1023.0/a-1.0;
		R = R0*R;

		float temperature = 1.0/(log(R/R0)/B+1/298.15)-273.15; // convert to temperature via datasheet

	  u8x8.setFont(u8x8_font_chroma48medium8_r);
	  u8x8.setCursor(4, 10);
  	  u8x8.print("T = ");
	  u8x8.print(temperature);

		Serial.println("temperature = ");
		Serial.println(temperature);

		delay(1000);
	}



Code avec XIAO-ESP32S3 sortie sur Serie ✅

Grove Base for XIAO 1.PNG XIAO-ESP32S3 1.PNG Temperature Sensor back.jpg

Grove Base for XIAO ✅
XIAO-ESP32S3
Temperature Sensor Thermistor (Port A0)

#include <math.h>

const int analogPin = A0;       // Port analogique utilisé
const float B = 3975;           // Coefficient B du thermistor
const float R0 = 10000;         // Résistance à 25°C (10kΩ)
const float T0 = 298.15;        // Température en Kelvin (25°C)

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

void loop() {
  int raw = analogRead(analogPin);

  // Éviter division par zéro
  if (raw == 0) {
    Serial.println("Erreur : lecture analogique nulle");
    delay(1000);
    return;
  }

  float resistance = (4095.0 - raw) * R0 / raw;
  float temperatureK = 1.0 / (log(resistance / R0) / B + 1.0 / T0);
  float temperatureC = temperatureK - 273.15;

  Serial.print("Température : ");
  Serial.print(temperatureC);
  Serial.println(" °C");

  delay(1000);
}



Code avec XIAO-ESP32S3 sortie Oled & 16x2 LCD & Serie ✅

Grove Base for XIAO 1.PNG XIAO-ESP32S3 1.PNG Temperature Sensor back.jpg OLED Display 128x64 recto.jpg 16x2 LCD White on Blue 01.jpg


Grove Base for XIAO ✅
XIAO-ESP32S3
Temperature Sensor Thermistor (Port A0)
OLED Display 128×64 (Port I2C : 0x3C)
16x2 LCD (Port I2C : 0X3E)


LCD I2C Adresse 0X3E
RGB I2C Adresse 0X62
#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h>
#include <math.h>

// OLED SSD1306 via U8g2 (sans rotation)
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

// Grove 16x2 LCD I2C
#define LCD_ADDR 0x3E     // Adresse I2C du Grove LCD
#define COMMAND 0x00      // Mode commande
#define DATA 0x40         // Mode données

const int analogPin = A0;
const float B = 3975;
const float R0 = 10000;
const float T0 = 298.15;

// Fonctions pour Grove LCD
void sendCommand(uint8_t cmd) {
  Wire.beginTransmission(LCD_ADDR);
  Wire.write(COMMAND);
  Wire.write(cmd);
  Wire.endTransmission();
  delay(2);
}

void sendData(uint8_t data) {
  Wire.beginTransmission(LCD_ADDR);
  Wire.write(DATA);
  Wire.write(data);
  Wire.endTransmission();
  delay(2);
}

void clearLCD() {
  sendCommand(0x01); // Clear display
  delay(2);
}

void setCursor(uint8_t col, uint8_t row) {
  uint8_t pos = (row == 0) ? 0x80 + col : 0xC0 + col;
  sendCommand(pos);
}

void printText(const char* text) {
  while (*text) {
    sendData(*text++);
  }
}

void printCentered(const char* text, uint8_t row) {
  int len = strlen(text);
  int col = (16 - len) / 2;
  if (col < 0) col = 0;
  setCursor(col, row);
  printText(text);
}

void initLCD() {
  delay(50);
  sendCommand(0x38); // Fonction: 2 lignes, 8 bits
  sendCommand(0x39); // Fonction étendue
  sendCommand(0x14); // Oscillateur
  sendCommand(0x70); // Contraste
  sendCommand(0x56); // Puissance + icône + contraste
  sendCommand(0x6C); // Activation du booster
  delay(200);
  sendCommand(0x38); // Retour mode normal
  sendCommand(0x0C); // Affichage ON, curseur OFF
  clearLCD();
}

void setup() {
  Wire.begin();
  initLCD();

  u8g2.begin();
  Serial.begin(115200);
}

void loop() {
  int raw = analogRead(analogPin);
  if (raw == 0) {
    Serial.println("Erreur : lecture analogique nulle");
    delay(1000);
    return;
  }

  float resistance = (4095.0 - raw) * R0 / raw;
  float temperatureK = 1.0 / (log(resistance / R0) / B + 1.0 / T0);
  float temperatureC = temperatureK - 273.15;

  // Formatage du texte sans symbole °, avec 2 décimales
  char buffer[20];
  snprintf(buffer, sizeof(buffer), "T = %.2f C", temperatureC);

  // OLED : affichage centré
  u8g2.setFont(u8g2_font_ncenB14_tr);
  int textWidth = u8g2.getStrWidth(buffer);
  int textHeight = u8g2.getMaxCharHeight();
  int x = (128 - textWidth) / 2;
  int y = (64 + textHeight) / 2;
  u8g2.clearBuffer();
  u8g2.drawStr(x, y, buffer);
  u8g2.sendBuffer();

  // Grove LCD : affichage centré sur la ligne 1
  clearLCD();
  printCentered(buffer, 0);

  // Série
  Serial.print("Température : ");
  Serial.print(temperatureC, 2);
  Serial.println(" °C");

  delay(1000);
}

Liens internes

Main page

Liens externes

www.seeedstudio.com/category/Grove-Temperature-Sensor-p-774.html shop
github.com/SeeedDocument/Seeed-WiKi/blob/master/docs/Grove-Temperature_Sensor.mdgithub
wiki.seeedstudio.com/Grove-Temperature_Sensor_V1. wiki