Fabrication d’un THERMOMÈTRE avec un ARDUINO

vidéo

Liste des composants

arduino pro mini + ftdi – Amazon

sonde ds18b20 – Amazon

écran oled – amazon

pcb – amazon

Le schéma

la résistance est de 4,7 KΩ

Les fichiers 3D

Trouver l'adresse i2c de l’écran oled

#include <Wire.h>

void setup()
{
  Wire.begin();
  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}
void loop()
{
  byte error, address;
  int nDevices;
  Serial.println("Scanning...");
  nDevices = 0;
  for (address = 1; address < 127; address++ )
  {
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.print(address, HEX);
      Serial.println("  !");
      nDevices++;
    }
    else if (error == 4)
    {
      Serial.print("Unknown error at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.println(address, HEX);
    }
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");
  delay(5000);           // wait 5 seconds for next scan
} 

Le code

//----------------------------------------------
//                 GammaTroniques
//                    By Xmow
//                    08/2020
//----------------------------------------------
//Library
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSansBold18pt7b.h>

//Taille de l'ecran OLED
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

#define OLED_RESET     -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define ONE_WIRE_BUS 2 //Pin de la sonde DS18B20

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress tempDeviceAddress;

double temp;
String d;

void setup(void)
{
  Serial.begin(9600);
  sensors.begin();
  sensors.setResolution(tempDeviceAddress, 12);

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { //i2c adress oled display
    Serial.println(F("SSD1306 allocation failed")); //Error display
  }
  display.clearDisplay();
  display.display();
}

void loop(void)
{
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures();
  Serial.println("DONE");
  Serial.print("Temperature: ");

  temp = sensors.getTempCByIndex(0);
  Serial.println(temp, 5);

  display.clearDisplay();
  display.setTextSize(1);
  display.setFont(&FreeSansBold18pt7b);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 46);

  d = temp;
  d.replace(".", ",");
  display.print(d);
  display.print(" C");
  display.drawCircle(90, 26, 4, SSD1306_WHITE);
  display.drawCircle(90, 26, 3, SSD1306_WHITE);
  display.display();
}