/*________________________________________ * U C I S T U D Y G R O U P * Lesson 2: MOSFETS * Ron Kessler * Created 5/7/2021 * * RAMPUP & DOWN DEMO * _______________________________________ * This shows how to slowly increase motor RPM to maximum and * then slowly reduce RPM to 0. This runs for ever. * * Be sure to connect a 10K resistor (brn-blk-orange) between the * Gate and Source (ground on the Arduino). This pulls the Gate to gnd * should the yellow wire (Gate) get pulled loose. * * When you hold the transistor so you can view the label, the pins are * from left to right: Gate | Drain | Source * * Wiring: * IRF540 Arduino Motor * Gate Yellow Pin 11 * Source Green GND * VIN (on Arduino) Motor (+) * Drain Orange Motor (-) * * */ //---define our controller pin const int motorPin = 11; void setup() { pinMode(motorPin, OUTPUT); //we are sending power out } //---ramp the motor RPM up to max then back to 0 //---Our range of values is 0-255 because we are using 1 byte of data void loop() { for(int x = 0; x< 255; x++) //increase motor speed from 0-255 { analogWrite(motorPin, x); delay(20); } for(int x = 255; x > 0; x--) //decrease motor speed fro 255-0 { analogWrite(motorPin, x); delay(20); } }