I am having trouble with this circuit(Look at the pic i have attached). I also attached my code
I have a fan that is controlled by temp. The fan is powered by a 9V battery. So the problem is that the temp sensor im using (TMP36 from my kit) stops reading temp and just goes to 0C or 200 C causing my LED and fan to go crazy with it. This usually happens after the fan runs good for 30 sec but then goes back to normal afterwards. Here ill post the jump:
voltage: 0.71 FANS: 46 deg C: 21.29 deg F: 70.32
voltage: 0.70 FANS: 42 deg C: 19.82 deg F: 67.68
voltage: 0.55 FANS: 11 deg C: 5.18 deg F: 41.32
voltage: 0.64 FANS: 31 deg C: 14.45 deg F: 58.02
voltage: 0.50 FANS: 0 deg C: 0.29 deg F: 32.53 <--- like right here it just stops reading the correct temp i dont know why and this makes my fan turn off and my led to go blue
voltage: 0.71 FANS: 46 deg C: 21.29 deg F: 70.32
voltage: 0.59 FANS: 17 deg C: 8.59 deg F: 47.47
voltage: 0.71 FANS: 46 deg C: 21.29 deg F: 70.32
voltage: 0.69 FANS: 40 deg C: 18.85 deg F: 65.93
Does the circuit work without the fan motor connected?
A 9V transistor battery won't run a motor very long, but a low batt. shouldn't cause what you describe.
alright i got it to work. i replaced the motor with a 12v fan and got a 12v battery to supply it. but now the fans making a weird humming noise. So i added that diode (1N4148) and its still making the noise
You are controlling the motor speed with PWM at around 470 cycles per second, thats where the noise comes from, not much way around it. You might try pin 5 or 6 instead of 11, PWM is twice the frequency and may make a more pleasant squeal but your motor may run hotter.