I am trying to use a thermistor to read temperature , and based on readings it runs motor with fan as needed :
i used an example code and i modified to get Arduino read temperature, and instead of just displaying it on LCD, its also control DC motor, i just would like you check the code and give me your opinion whether its correct or not also i am little bit confused about sending the power from Arduino to the motor, can be done like this? while Arduino also send power to the LCD ?
If I wanted to perfect it more, having the PWM range from 0-255, I would control the fan proportionally with temperature. But I guess that's overkill.
Look at the map() function, you can create a PWM value to use from the tempC directly, like this:
PWMtoUse = map(tempC, 25, 29, 0, 255);
anything below 25 can be truncated to 0% pwm, and 29 and above will max at 100%.
I would use integers though instead of floating numbers for the map(). That's all you need for the PWM and display%. You can convert them to integers but still have the original math for the temperatures as floating point numbers.
For the display, use another map function to convert that same 25-29 temperature range to a 0-100 value to show the fan %.
Thank you all for your replies, i will give it a try and revert, but i would like to confirm plugging the DC motor, is it going to get power from the same arduino ? i mean its already powering the LCD, also what should i place before the engine to avoid Arduino damage ? as i know connecting motor could produce power and damage arduino (Acting as a Dynamo)
I don't know how large or small that fan is, but unless it was extremely small I would drive it with a circuit to prevent problems. A quick internet search gave me this example:
Where it says +12V, it can be any voltage that the fan can use but don't get it from the arduino's 5v pin.
Where it shows a BC337 transistor, almost any transistor can work as long as the motor doesn't draw more than 100 mA or more. Heavier currents will require finding a transistor that can conduct more current without burning itself out.
The resistors shown are also non-critical. Any value around 10,000 will work for the resistor tied to ground, and the other one can range from about 100 to 600.
If this circuit or selecting components scare you, put the fan specs on here and you will have 100 volunteers willing to recommend driving circuits.
I would draw one up that will work, but I usually like to design around the components I can easily obtain, so let's see those fan motor specs!
Thank you so much,
I just would like to ask a silly question, and excuse me for this as i am totally new, when the motor get its power from outsourced power, how it can receive the control from Arduino ?
the fan motor just got two polls
i know signal sent through ```
so how the engine will receive orders?
Yes, what TomGeorge said is true. The awesome usefulness of a transistor is that a small current can control a larger current. Similarly, with a tube or FET a small voltage can control a larger current.
Think of it like you jumping into and pressing the gas pedal of a 40-ton gravel hauler in a gravel mine. Obviously the energy of your foot doesn't move 40 tons of rock. The gas powers the movement, but the truck amplifies your small motion of your foot and moves those rocks much more than you could do without the truck.
That same thing happens when a very weak radio signal is received by a powerful home receiver. That tiny voltage fluctuation radiating through space is amplified and some 100-Watt speakers can thump you good in the chest.
Amplification baby! Your tiny Arduino signal can be hooked up to control a 36" fan if we wanted to!