Hi, this is how you post code on this forum:
const int redPin = 11;
const int greenPin = 10;
const int bluePin = 9;
void setup() {
// Start off with the LED off.
setColourRgb(0,0,0);
}
void loop() {
unsigned int rgbColour[3];
// Start off with red.
rgbColour[0] = 255;
rgbColour[1] = 0;
rgbColour[2] = 0;
// Choose the colours to increment and decrement.
for (int decColour = 0; decColour < 3; decColour += 1) {
int incColour = decColour == 2 ? 0 : decColour + 1;
// cross-fade the two colours.
for(int i = 0; i < 255; i += 1) {
rgbColour[decColour] -= 1;
rgbColour[incColour] += 1;
setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]);
delay(5);
}
}
}
void setColourRgb(unsigned int red, unsigned int green, unsigned int blue) {
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
And images are better posted like this:
Can I just check something. When you say "base" or "base tab" you really mean the gate pin of the MOSFET? And when you say "connecting the LED pins to the gate of the FET" you mean the Arduino pins referred to as "redPin" etc. in the code?
When the Arduino is not switched on, and before you code starts running, the output pins are floating, so the mosfet gate is also floating. This can cause it to switch on or off or, more likely, part way between the two states at random. Attach a 10K between the MOSFET gate and either 5V or ground to stop it floating. Once the code is executing, the Arduino pin will be either high or low and the 10K will have no significant effect and can be left in place permanently. The 10K value is not critical and anything between 1K and 100K will do.
I am surprised that the MOSFET got warm, given that only a few mA could have been flowing. If it continues to get warm, it could be faulty/damaged, so try replacing it. Also check you have correctly identified the gate, source & drain pins for that model of MOSFET.
