I am working on a entertainment cabinet fan. The idea is to use a DROK 10k thermistor and a 10k resistor as a voltage divider connected to AO. The project will be connected to 12v DC and vary the speed of fans according to the internal temperature, with a 16x2 display for feedback. On USB power, the display works and shows relatively accurate temperatures. The Arduino is supposed to be fed by a daughter board with the transistors, voltage divider and a 12v to 5v DC to DC converter. The voltage divider draws 5v from the output of the DC to DC converter, tied directly to the wire going to the Arduino's VCC. When plugged into the wall, the display shows a high temperature that actually decreases the reading when warming the sensor. I'm pretty sure it's something stupid I missed. Any ideas?
There's no way to clearly understand you description (at least for me). Make a drawing of your circuit and post it here.
What is "AO" here?
I am not sure what you are asking. When using ghe USB for power vs Vin or directly supplying 5V the system voltage will be different giving different readings. Without knowing your circuit I cannot give you an accurate answer. I suggest you post an annotated schematic showing exactly how you connected everything, power sources, grounds and note any lead over 10"/25cm. @kmin has also asked for similar information.
This is when the code expects the resistor/thermistor in the opposite position.
The voltage divider must also be powered from VCC of the (unspecified) Arduino, to keep ratiometric behavior.
Which Arduino.
Code.
Power diagram.
Leo..
There are two possible configurations for the voltage divider, and the code is different for those two.
If the program reports temperature changes opposite to the expected direction, change the code or swap the resistor and thermistor.
I hoped there was an obvious answer, but I was afraid more clarification would be needed. Here is the schematic, modeled as closely as possible to what I made.
Here is my code. I'm not quite done with it and I'm sure it's ugly. I was trying to test the hardware, then try to code any bugs out.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//source: https://www.electroschematics.com/9540/arduino-fan-speed-controlled-temperature/
LiquidCrystal_I2C lcd(0x27, 16, 2);
int ThermistorPin = 0;
int Vo;
float R1 = 10000;
float logR2, R2, T, F;
//float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07; // old values
float c1 = 1.303866579e-03, c2 = 2.019279251e-04, c3 = 2.326033351e-07;
// found values:
//30800 ohm @ 1C;
//9900 ohm @ 26C;
//685 ohm @ 99C;
const int fan1 = 9; // the pin where fan 1 is
const int fan2 = 10; // the pin where fan 2 is
const int fan1tempON = 25; // the temperature to start the fan
const int fan1tempOFF = 15;
const int fan2tempON = 30;
const int fan2tempOFF = 35;
int fan1Speed = 0;
int fan1LCD = 0;
int fan2Speed = 0;
int fan2LCD = 0;
double temp;
void toggleBacklight();
void setup() {
lcd.init();
lcd.backlight();
pinMode(fan1, OUTPUT);
pinMode(fan2, OUTPUT);
pinMode(ThermistorPin, INPUT);
lcd.setBacklight(HIGH);
lcd.setCursor(2,0);
lcd.print("Temperature");
lcd.setCursor(3,1);
lcd.print("Control V3");
delay(3000);
lcd.clear();
lcd.setBacklight(LOW);
}
void loop() {
Vo = analogRead(ThermistorPin);
R2 = R1 * (1023.0 / (float)Vo - 1.0);
logR2 = log(R2);
temp = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
temp = temp - 273.15;
temp = temp + 3;
F = (temp * 9.0)/ 5.0 + 32.0;
if ((temp > 25) && (temp < 40)) // Stage one cooling
{
lcd.setBacklight(HIGH);
fan1Speed = map(temp, fan1tempON, 40, 25, 255);
fan1LCD = map(temp, fan1tempON, 40, 0, 99);
analogWrite(fan1, fan1LCD);
fan2Speed = 0;
fan2LCD = 0;
analogWrite(fan2, 0);
}
else if ((temp > 40) && (temp < 65)) //Stage two cooling
{
lcd.setBacklight(HIGH);
fan1Speed = 255;
fan1LCD = 99;
analogWrite(fan1, 255);
fan2Speed = map(temp, fan2tempON, 65, 20, 255);
fan2LCD = map(temp, fan2tempON, 65, 0, 99);
analogWrite(fan2, fan2LCD);
}
else if (temp > 65) //High temps. Both fans at full speed, flash the backlight as a warning
{
lcd.setBacklight(HIGH);
fan1Speed = 255;
fan1LCD = 99;
analogWrite(fan1, 255);
fan2Speed = 255;
fan2LCD = 99;
analogWrite(fan2, 255);
delay(500);
lcd.setBacklight(LOW);
delay(500);
}
else //ambient temsp. Rest mode
{
lcd.setBacklight(LOW);
fan1Speed = 0;
fan1LCD = 0;
analogWrite(fan1, 0);
fan2Speed = 0;
fan2LCD = 0;
analogWrite(fan2, 0);
}
// if (temp < 25)
// {
// lcd.setBacklight(LOW);
// fan1LCD = 0;
// fan1LCD = 0;
// analogWrite(fan1, 0);
// analogWrite(fan2, 0);// spin the fan at the fanSpeed speed
// }
lcd.setCursor(0, 0);
lcd.print("Tmp:");
lcd.print(temp, 1); // display the temperature
lcd.print("C ");
lcd.setCursor(10, 0);
lcd.print(F,1);
lcd.print("F ");
lcd.setCursor(0, 1); // move cursor to next line
lcd.print("Fan1:");
lcd.print(fan1LCD); // display the fan speed
lcd.print("%");
lcd.setCursor(8, 1); // bottom right
lcd.print("Fan2:");
lcd.print(fan2LCD);
lcd.print("%");
delay(1000);
lcd.clear();
}
I took a second sensor and tested resistance in ice water (0 C), boiling water (100 C) and room temp (26 C). I found this site, which calculates the Steinhart-Hart coefficients. I commented out the old values and placed the new ones. That made it more accurate on USB power.
I assume it's an Arduino Uno R3, and 12volt is the power supply.
V-in has a voltage range of 7-12volt, so you're under-powering the Uno.
If you have a stable/reliable 5volt from that buck converter, then connect it to the 5volt pin.
Make sure you disconnect that when using the USB socket (for uploading new software etc.)
As said ,swap the thermistor and the resistor if temp display goes backwards (or change the code).
The IRF520 is not a logic level fet (not suitable for 5volt logic), and will only sort off work with low current loads.
A DS18B20 is easier to use and doesn't need calibration, like a thermistor does.
Leo..
Hi, @hotrodder247
Connect the DC-DC 5V output to the 5V pin of the controller.
What model Arduino are you using?
Tom....
![]()
PS. Do you have a DMM? (Digital MultiMeter) also labelling the MOSFET and LCD pins would have been good too.
I'm using a Keyestudio knockoff for this project.
Amazon Link
This is the DC-DC converter:
Amazon Link
And I'm using these temperature probes:
Amazon Link
Thank you all for your input. I really did not expect this level of feedback, so I quickly posted before we left for dinner after staring at my creation for about an hour, trying to troubleshoot in my head.
I started this project almost two years ago, shelving it because my son was born. Now my two year old is trying to pull my consoles off the shelves, so into the cabinet they go. But re-opening this project has been tedious. I can't remember how I found the IRF 510, and I'm not great at finding the correct components. I was trying to avoid a Darlington pair, because I tried making one in the past and it didn't work. I mean, I spent an entire toddler's nap break attempting to plug capacitors into my breadboard to smooth out the PWM to get rid of the fan noise with no success. Everything so far has been trial and error with Google on standby when something didn't work. Even my code is primarily Frankenstein'ed together from other's sketches, playing with it until it worked
I want to drive a set of PC case fans. Fan one is a 120x120 (12v 0.25A). Fan two is actually two 40x40 fans (12v 0.36A each)wired in parallel. The project would be powered by a 12v 2a wall wart. I have found people referred to proper logic level MOSFET's but they are for higher current applications.
Again, thank you all. I know just enough to know I don't know what I'm doing ![]()
PS: original image replaced with slightly more annotation
It appears the way you have the thermsistor wired it will not work. Here is a simple circuit I found:
If the voltage is going the wrong way swap the +5 and Ground. This may help
Would these be a better idea? The datasheet lists Rds as 5v, and claims it's logic level.
Mosfet
Yes, these should work better with 5volt-logic, even with 3.3volt-logic.
See the figure7 graph in the datasheet.
Your current IRF520 fets might be ok for a 250mA 3-pin fan. Just try.
If you use 4-pin fans (with a PWM input), then you don't need mosfets.
Noisy fans?
The PWM pins you're using for the fans default to ~490 Hz.
You could try pin 5,6 which default to 980 Hz.
Caps across the fans could be a bad thing.
Leo..
I rebuilt the daughter board, using the new mosfets in almost the same way, except for being careful to change my layout for the different pinout and adding an IN4004 diode between the mosfet drain and the fan. I then set up another voltage divider with a 10k pot and 10k resistor for testing. I discovered something odd to me; when powered by USB power, the 5v pin has 5v. When powered by my DC-DC converter through the Vin pin, the 5v pin has 3.2v. If I remove the Arduino and supply 9v to Vin, the 5v pin works.
So, I figure my options are:
- Adjust the DC-DC converter to output 9v, and let the Arduino convert that to 5v for the display and voltage divider
- Power the display, voltage divider and Arduino directly from the DC-DC converter
- Remove the 5v regulator on the Arduino and bypass it
- Figure out why the Arduino provides 5v on USB power but not Vin and fix that
Thank you all for your input. It really means a lot!
?
A kickback diode goes between drain and 12volt.
As explained in post#9.
Vin is the input of the built-in 5volt regulator and needs 7volt minimum to do it's job.
You can also power the Uno directly with 12volt on the DC socket, as long as you draw less than 100mA from any pin.
Leo..
This is what I came up with. Examples that I googled said I needed limiting resistor on the D9 and D10 lines and a diode to prevent damage to the mosfet. Will this suffice? I can flip the diode around to the 12 volt rail, this is just what I got to work on my breadboard. Other examples placed a 0.1 cap connecting drain and 12 volt. Do I need this? I want this project to last.
Also, I finally understood what you meant about the 5v output, with the regulator needing headroom. Will my situation require some call to Aref in my code or some other modification for accuracy when reading the output from the voltage divider?
First diagram here is the best configuration. You only use a cap across the diode for bare brushed DC motors, to kill RF brush (spark) noise. Don't use with a PC fan.
No call to Aref.
Leo..
Hi, @hotrodder247
I have re-drawn your schematic, this is the usual layout.
Thanks for your diagram, I would have hand drawn the schematic, but neuropathy would make me draw a mud map.
Feel free to edit any errors.
Can you verify the MOSFET part number and is it a logic MOSFET?
Tom....
![]()
Tom, as always, amazing and clear.
Leo..





