A temperature based fan using REES52 KY-013

Hey there, this is my first post on here, and one of my first projects ever using Arduino or any sort of electrical engineering at all, but with the help of some teachers and everyone on this website, I was able to figure it out.
The project is based around a greenhouse, and I wanted to create a temperature based fan system that would only turn on when it got over a certain temperature, I tried to just copy someone's project and i melted my DHT11 (a temp and humid sensor). After this I figured I needed to really do it on my own and learned about how to code in arduino and how circuits worked and all that. Before this I didn't know what a transistor did, and now, I know what a transistor does, but I have no idea why or how.
All that to say, I'm proud of myself for having finally figured it out and getting it working, and for anyone who is also in my situation in the future heres my code and wiring if I can figure out how to make that diagram thing.

 // Define the analog pin connected to the KY-013
const int thermistorPin = A0;

// Define the value of the fixed resistor (10kΩ)
const float fixedResistor = 10000.0;

// Steinhart-Hart coefficients for the thermistor
const float c1 = 0.001129148;
const float c2 = 0.000234125;
const float c3 = 0.0000000876741;

#define Motorpin 6

void setup() {
  Serial.begin(9600); // Initialize serial communication
pinMode(Motorpin, OUTPUT); 
}

void loop() {
  // Read the analog value from the thermistor pin
  int rawValue = analogRead(thermistorPin);

  // Calculate the resistance of the thermistor
  float voltage = rawValue * (5.0 / 1023.0); // Assuming 5V Arduino
  float thermistorResistance = fixedResistor * (1023.0 / rawValue - 1.0);

  // Calculate the temperature using the Steinhart-Hart equation
  float logR = log(thermistorResistance);
  float temperatureKelvin = 1.0 / (c1 + c2 * logR + c3 * logR * logR * logR);
  float temperatureCelsius = temperatureKelvin - 273.15;

  // Print the temperature to the serial monitor
  Serial.print("Temperature: ");
  Serial.print(temperatureCelsius);
  Serial.println(" °C");

  delay(1000); // Delay for stability

// if-then statements for controlling the fan on and off, you can easily change the numbers, I just chose room temp in celsius
  if(temperatureCelsius < 22)
{
  digitalWrite(Motorpin, LOW);
}

if(temperatureCelsius > 22)
{
  digitalWrite(Motorpin, HIGH);
  }

}

btw I used a laser diode board in place of the temp sensor bc the website I used didn't have my sensor and this one looked most alike.

I get this when I click on your Circuit Canvas project

This book will learn you all you need for quite some time

If you are serious about electronics which it appears you are, you will someday want to make a printed circuit board. I highly recommend KiCad (https://www.kicad.org/), it is a full feature CAD (Computer Aided Design) package available for free with versions for most popular operating systems such as Linux, Mac, windoz and possible other. With that you can make your schematics, and everything else needed.

hey sorry Im not really sure how the website works, it is still saying saving and idk why. heres a pic of it

No problem, we all started the same way. It takes time to understand it as it is not a simple subject. Another great book would be the Arduino Cookbook, it has lots of projects with code and explanations. Most of your project will be in there.

There is a high probability you will damage your Arduino by Powering your motor with it. Hope the following helps:

Gil's Crispy Critter Rules for Processor Hardware:

  1. Rule #1: An Arduino is NOT a Power Supply!
  2. Rule #2: Never connect anything inductive (motors, speakers) directly to an Arduino!
  3. Rule #3: Avoid connecting or disconnecting wires while the power is on.
  4. Rule #4: Do not apply power to any pin unless you are certain of what you're doing.
  5. Rule #5: Do not exceed the maximum voltage ratings.
  6. Rule #6: Many Arduinos cannot power transmitters directly.
  7. Rule #7: Before powering your project, take a break and double-check the wiring.

LaryD’s Corollaries:

  1. Coro #1: When starting out, add a 220Ω resistor in series with both input and output pins to protect against shorts.
  2. Coro #2: Invest in a Digital Multi-Meter (DMM) to measure voltages, currents, and resistance.

Note: Violating these rules can turn your Arduinos into crispy critters. For optimal performance, keep your wires under 25 cm (10 inches).

Additional Tips:

  • The L293 motor driver, though common, is inefficient as it can lose around 3V as heat when driving both legs of a motor. Consider using a motor driver with MOSFET outputs to reduce heat loss and conserve battery power.
  • For more on powering Arduino boards, explore this guide: Powering Alternatives for Arduino

Are you using a thermistor and a resistor as your code indicates?
Or are you using a DHT11 for temperature?

thank you so much! this is really helpful, and I am actually using a different motor than the one in the diagram, but i'm not sure of the name.

I'm using a thermistor but not a resistor, I though it was included in the thermistor, is it? and no, I was using a DHT11 but I melted it by accident while trying to figure this project out :frowning:

Yes, on the KY-013 it is included.

I think you have 5V and GND on the KY-013 reversed. The middle pin is +5V
Remove the transistor and see if the correct temperature is printed.