/*
NTC Temperature Sensor using Franzininho, NTC and SSD1306
by Anderson Costa with ❤ for the Wokwi community
Modify by Leko 7-seg with 74hc595
Visit https://wokwi.com to learn about the Wokwi Simulator
Visit https://franzininho.com.br to learn about the Franzininho
*/
#include <ShiftDisplay.h>
const int DISPLAY_SIZE = 5; // number of digits on display
#define latchPin PB0
#define clockPin PB1
#define dataPin PB2
ShiftDisplay display(latchPin, clockPin, dataPin, COMMON_ANODE, 3);
#define NTC_PIN A3
const float BETA = 3950.0; // Deve corresponder ao coeficiente beta do termistor
void setup() {
}
void loop() {
static unsigned long startTime = 0;
unsigned long currentTime;
// Retorna o número de milissegundos passados
// desde que começou a executar o programa atual
currentTime = millis();
// Verifica se passou 1 segundo
if ((currentTime - startTime) >= 1000) {
// Reseta o temporizador
startTime = currentTime;
// Atualiza o display
updateDisplay();
}
}
void updateDisplay()
{
// Atualiza a temperatura
float temperature = getTemperature();
//display.set(temperature, 1); // float with one decimal place
display.show(temperature, 1000, 1, ALIGN_CENTER);
}
float getTemperature()
{
int analogValue = analogRead(NTC_PIN);
//float celsius = 1 / (log(1 / ((1023.0 / analogValue) - 1)) / BETA + 0.003354) - 273.15;
float celsius = BETA / (13.2483-log(1023.0 / analogValue -1)) - 273.15;
return celsius;
}