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.
While programming, I found some road blocks and I've list them down below.
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);
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);
}
}