#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
// Wokwi ONLY!!!
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
void setup() {
ADCSRA |= ((1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0)); // Set the ADC clock to 16 MHz / 128 = 125 kHz
ADMUX |= (1 << REFS0); // Set the ref. voltage to Vcc (5V)
ADCSRA |= (1 << ADEN); // Activate the ADC
ADCSRA |= (1 << ADSC);
lcd.begin(16,2);
}
void loop() {
int val = read_adc(0); // Read the value
lcd.setCursor(0,0);
lcd.print("Raw: ");
lcd.print(val);
// Wokwi ONLY!!!
// lcd.setCursor(0,1);
// lcd.print("Calc: ");
// float calc_val = 1 / (log(1 / (1023. / val - 1)) / BETA + 1.0 / 298.15) - 273.15;
// lcd.print(calc_val);
}
uint16_t read_adc(uint8_t channel) {
ADMUX &= 0xE0; // Delete MUX0-4 bits
ADMUX |= channel & 0x07; // Sets in MUX0-2 the value of the new channel to be read
ADCSRB = channel & (1 << 3); // Set MUX5 value
ADCSRA |= (1 << ADSC); // Start conversion
while (ADCSRA & (1 << ADSC)); // Wait for the conversion to finish
return ADCW;
}