This Project is for my Bearded Dragon Ornstein. His tank uses light switches to control his ceramic heat lamp as well as his UV light which simulates the sun for him.
This Project aims to automate this process by using a thermistor to detect the temperature, and when the set parameter for the temperature is reached, the light bulbs will be switched off by a servo motor.
Temperature
This project uses an NTC thermistor to read out the temperature. In order to set up the thermistor to get actual temperature readings, the Steinhart-Hart equation will need to be used, which can be easily done from this link.
First we need to convert the ADC values to pure resistance in order to plug in values into this equation. You will also need some sort of thermometer for this part, I used a heat gun.
To calculate resistance, we can code
int ThermistorPin = 12;
float R1 = 10000; // Normal Resistance
int Vo,
void setup() {
Serial.begin(9600); // Serial output solely for debugging (Highly Reccomended)
}
void loop() {
Time.zone(-6); // Central Time Zone
Vo = analogRead(ThermistorPin); // Raw Thermistor ADC Value
R2 = R1 * (1023.0 / (float)Vo - 1.0);
Serial.print(R2);
This will print out resistance values into your serial monitor. Now with this you will be measuring the resistance of the thermistor in a hot, cold, and neutral setting, measure the temperature, and input the resistance at those temperatures as well as the temperatures into the equation to get your A B and C constants.
Now with this, we can revisit our old code and add the constants in as well as the rest of the equation to get meaningful temperature values.
We will also be using the Time() function to tell us the hour that it is in our current time zone. To set your time zone you will use Time.zone() with your time zone offset in the parenthesis, to find your time zone offset, click here.
int ThermistorPin = 12;
float R1 = 10000; // Normal Resistance
int Vo,
float logR2, R2, T, Tc, Tf;
float c1 = 16.59490821e-03, c2 = -23.35666205e-04, c3 = 103.1153499e-07; // SRS Thermistor Calculator Constants
void setup()
Serial.begin(9600); // Serial output solely for debugging (Highly Reccomended)
}
void loop() {
Time.zone(-6); // Central Time Zone
Vo = analogRead(ThermistorPin); // Raw Thermistor ADC Value
R2 = R1 * (1023.0 / (float)Vo - 1.0);
Serial.print(R2);
logR2 = log(R2);
T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2)); // Resistancee to Temperature Conversion (Kelvin)
Tc = T - 273.15; // Kelvin to Celsius
Tf = (Tc * 9.0)/ 5.0 + 32.0; // Celsius to Farenheit
Serial.print(R2); // Printing of Resistance (Debugging)
Serial.print("Time :"); // Printing of time (Debugging)
Serial.print(Time.hour());
Serial.print("Temperature: "); // Printing of Temperature in Farenheit (Debugging)
Serial.print(Tf);
Serial.print(" F; ");
Finally, with this, we can add in our servos to move when the parameters we want are met. This is done in the code below.
Servo myServo1;
Servo myServo2;
int ThermistorPin = 12; // digital pin for reading thermistor
int Vo;
float R1 = 10000; // Normal Resistance
float logR2, R2, T, Tc, Tf;
float c1 = 16.59490821e-03, c2 = -23.35666205e-04, c3 = 103.1153499e-07; // SRS Thermistor Calculator Constants
void setup() {
Serial.begin(9600); // Serial output solely for debugging (Highly Reccomended)
myServo1.attach(13); // Servo Pins
myServo2.attach(14);
myServo1.write(0);
myServo2.write(0);
}
void loop() {
Time.zone(-6); // Central Time Zone
Vo = analogRead(ThermistorPin); // Raw Thermistor ADC Value
R2 = R1 * (1023.0 / (float)Vo - 1.0); // Resistance read from Thermistor
logR2 = log(R2);
T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2)); // Resistancee to Temperature Conversion (Kelvin)
Tc = T - 273.15; // Kelvin to Celsius
Tf = (Tc * 9.0)/ 5.0 + 32.0; // Celsius to Farenheit
Serial.print(R2); // Printing of Resistance (Debugging)
Serial.print("Time :"); // Printing of time (Debugging)
Serial.print(Time.hour());
Serial.print("Temperature: "); // Printing of Temperature in Farenheit (Debugging)
Serial.print(Tf);
Serial.print(" F; ");
if (Tf < 80) // Temperature Parameters for Control
{
myServo1.write(80); // Turns On Heat Lamp
delay(3000);
}
else if (Tf > 100){
myServo1.write(0); // Turns Off Heat Lamp
}
if (Time.hour() == 6) // Time Parameters for Control
{
myServo2.write(100); // Turns On UV Light
}
if (Time.hour() == 18)
{
myServo2.write(0); // Turns Off UV Light
delay(3000);
}
delay(500);
}
Now, with everything complete, all that should need to be done is the actual installation, which I did with duct tape and blocks of wood, ensuring that the servos moved exactly in the right way.
To see this project in action, click the link down below:
Comments
Please log in or sign up to comment.