// James Rutter | 2021.05.13 // Networking and Communications // ATtiny412 Tempature Sensor // Reference: https://create.arduino.cc/projecthub/iasonas-christoulakis/make-an-arduino-temperature-sensor-thermistor-tutorial-b26ed3 #include SoftwareSerial mySerial(2,3); //RX, TX const int sensorPin = 4; int Vo; // voltage across thermistor and 10K resister (R1) float R1 = 10000; // fixed value resistor float R2; // resistance of thermistor (variable) float logR2, T; float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07; int Tf; // display units in farenheight void setup() { mySerial.begin(115200); pinMode(sensorPin, INPUT); } void loop() { Vo = analogRead(sensorPin); R2 = R1 * (1023.0 / (float)Vo - 1.0); // steinhart-hart equation logR2 = log(R2); T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2)); T = T - 273.15; T = (T * 9.0)/ 5.0 + 32.0; // convert to farenheight unit degrees T = Tf = (int)T; // convert to integer for saving memory (warning: will round to the nearest whole number). mySerial.print("Tempature (F): "); mySerial.println(Tf); }