Exercise 13 - Input Devices

Temperature input reader

This week, I've decided to do something that will relate to my final project, a Temperature reader.
Based on Neil's design on the circuitry, I noticed there are some free pins.
I decided seek approval from my Guru, Mr Steven Chew to add a LED indicator which will indicate accordingly to the temperature.

Components List

- 5x 10k ohm Resistors
- 1x 499 ohm Resistor
- 1x 1uF Capacitor
- 1x Attiny85
- 1x AVRISPSMD
- 1x FTDI SMD Header
- 1x SMD LED
- 1x NTC (10k ohm)

I designed it in Eagle and got it milled out and soldered.

Programming

While programming, I found some road blocks and I've list them down below.

Problem 1

I noticed that there is only one RX for the board that I created. I was trying to figure out how can I only push out 1 information as the usual example of using Serial uses 1 TX and one RX.
I found out that the solution which would require to include this library called "SendOnlySoftwareSerial.h" and declare only 1 txPin.

	#include <SendOnlySoftwareSerial.h>
	#define txPin PB2;
	SendOnlySoftwareSerial mySerial(txPin);
	

Problem 2

I was looking at Neil's example, I want to translate the C code and Python code into Arduino Code to work in the IDE.
tried to translate it into a simplier code where I can understand and for the IDE to work effectively.
But I wasnt as well verse in C, therefore I found another code from Arduino Playground, that I can make use of and modify it.

		
#include <SoftwareSerial.h>
#include <math.h>

double Thermistor(int RawADC) {
 double Temp;
Temp = log(10000.0*((1024.0/RawADC-1))); 
//   Temp      =log(10000.0/(1024.0/RawADC-1)); // for pull-up configuration
 Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
 Temp = Temp - 273.15;            // Convert Kelvin to Celcius
 //Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
 return Temp;
}

void setup() {
 mySerial.begin(9600);
 
}

void loop() {
  int Temperature= (Thermistor(analogRead(Input)));
 Serial.println("Current Temp in C:");
 Serial.println(Temperature);  // display Celcius
 
 delay(100);

}

	
After adding in NTC input and Output of LED lights
#include <SendOnlySoftwareSerial.h>


#include <SoftwareSerial.h>


#define txPin PB2   // My Tx pin is on PB3 port


SendOnlySoftwareSerial mySerial(txPin); // Configure Serial Port

#include <math.h>

double Thermistor(int RawADC) {
 double Temp;
// Temp = log(10000.0*((1024.0/RawADC-1))); 
   Temp      =log(10000.0/(1024.0/RawADC-1)); // for pull-up configuration
 Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
 Temp = Temp - 273.15;            // Convert Kelvin to Celcius
 //Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
 return Temp;
}

void setup() {
 mySerial.begin(9600);
   pinMode(PB1, OUTPUT);
     pinMode(PB0, OUTPUT);
}

void loop() {
  int Temperature= (Thermistor(analogRead(PB3)));
 mySerial.println("Current Temp in C:");
 mySerial.println(Temperature);  // display Celcius
 
 delay(100);
 if (Temperature >=40)
    {
        digitalWrite(PB0, HIGH);
           
    }
 else if (Temperature >=35 && Temperature <40)
    {

    digitalWrite(PB0, HIGH);

    delay(100);
        digitalWrite(PB0, LOW);
    }
    else{
      digitalWrite(PB0, LOW); 
    }
}

	

Testing

I realised using my hands warmth couldnt reach high temperatures, therefore I had to use the hairdryer to simulate the increase of temperature.
So on my code, what I did was, to make the LED blink when temperature is slowly increasing to the sweet spot. And when it reaches 40 degrees celcius, it will turn on the light to indicate it is at its optimum temperature.

Downloads


Thermistor with LED: sch, brd

Arduino Code: ino