OK so I set up the MOSFET circuit and loaded up some PWM code. (Power source is a cell phone charger sized AC-DC converter that I stripped down and tapped into with alligator clips. Running at 4.5 volts and 1 amp)
However, no sign of any PWM whatsoever. The resistor just heats up and stays there.
I had programmed the loop to gradually heat up to 100/255 heat, then hold for 10 seconds, then cool down all the way and hold that for 10 minutes. What I got instead was a resistor that heated up to the maximum, and stayed that way the entire time. No drop to zero.
I'm at a loss for what I did wrong. It must be a rookie mistake with the breadboard wiring or the code. Not sure which
I pasted some pictures below.
This is the circuit drawing again
Here's the code I used
int heaterPin = 3; // heating resistor connected to digital pin 3
void setup() {
}
void loop() {
// fade in from min to max in increments of 5 points:
for (int fadeValue = 0 ; fadeValue <= 100; fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(heaterPin, fadeValue);
// wait for 10 secs to see the dimming effect
delay(10000);
}
// fade out from max to min in increments of 5 points:
for (int fadeValue = 100 ; fadeValue >= 0; fadeValue -= 5) {
// sets the value (range from 0 to 255):
analogWrite(heaterPin, fadeValue);
// wait for 10 minutes to see the dimming effect
delay(600000);
}
}