Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Najad
Published © GPL3+

Phone Thermometer Using Digispark Attiny85

In this tutorial, we are going to build a simple OTG Phone Thermometer using Digispark ATtiny85 that can connect to our mobile phone.

BeginnerFull instructions provided3,474

Things used in this project

Hardware components

DigiSpark
DigiSpark
×1
Resistor 10k ohm
Resistor 10k ohm
×1
10k Precision thermistor
×1
OTG Adaptor
×1

Software apps and online services

Serial USB Terminal

Story

Read more

Schematics

Circuit

Code

Arduino Code

Arduino
#include <DigiCDC.h>

// the value of the 'other' resistor
#define SERIESRESISTOR 10000
// What pin to connect the sensor to
#define THERMISTORPIN A1
#define THERMISTORNOMINAL 10000
// temp. for nominal resistance (almost always 25 C)
#define TEMPERATURENOMINAL 25
// how many samples to take and average, more takes longer
// but is more 'smooth'
#define NUMSAMPLES 5
// The beta coefficient of the thermistor (usually 3000-4000)
#define BCOEFFICIENT 3950

void setup() {
  SerialUSB.begin();
}

// the loop routine runs over and over again forever:
void loop()
{
  if (SerialUSB.available())
  {
    uint8_t i;
    float average;
    average = analogRead(THERMISTORPIN);

    // convert the value to resistance
    average = 1023 / average - 1;
    average = SERIESRESISTOR / average;
    //SerialUSB.print("Thermistor resistance ");
    //SerialUSB.println(average);

    float steinhart;
    float presteinhart;
    steinhart = average / THERMISTORNOMINAL;     // (R/Ro)
    steinhart = log(steinhart);                  // ln(R/Ro)
    steinhart /= BCOEFFICIENT;                   // 1/B * ln(R/Ro)
    steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
    steinhart = 1.0 / steinhart;                 // Invert
    steinhart -= 273.15;                         // convert absolute temp to C

    if (int(presteinhart) != int(steinhart))
    {
      SerialUSB.print("Temperature ");
      SerialUSB.print(steinhart);
      SerialUSB.println(" *C");
      presteinhart = steinhart;
    }
    SerialUSB.delay(1000);
  }
}

Credits

Najad
30 projects • 97 followers
Just crazy stuff​

Comments