Potentiometer as MOSFET control + Arduino

From ESE205 Wiki
Jump to: navigation, search

In this tutorial we will show the steps in circuitry and code on an Arduino needed to control a MOSFET with a potentiometer

Materials: Arduino board, MOSFET (provide line), 10kΩ resistor, potentiometer (provide link), resistor-based PWM device (optional)

Step 1: First, lets set up the circuit. The first thing to note is that this will require two separate circuits on a breadboard. Another thing to note is that the MOSFET can be hooked up to many power users. Some examples include a lightbulb (non LED), a DC motor, and/or a heating pad.

Step 2: For the potentiometer circuit, connect two wires from 5V and GRND on the Arduino to the negative and positive power strips on one side of your breadboard.

Step 3: Next, connect the left pin on the potentiometer to the positive power strip, and the right pin to the negative power strip. The middle pin on the potentiometer can be connected to any analog port on the Arduino (but mark down which port used because it will be useful for the code later)

Step 4: Now set up the MOSFET, as show in the circuit diagram. Set this up on the other side of the breadboard. Connect your battery to the positive and negative power strips on the bread board.

How To mosfet.png

Step 5: The easiest way to ensure your MOSFET circuit is correct is to follow the flow of power. Start by tracing the positive wire leaving the battery. Make sure that flow of power goes straight to the positive port on your power user. Next follow the current as it exits your power user from the negative port. It should flow right into the middle port of the MOSFET. From there, make sure the left pin of the MOSFET is connected to a digital port on the Arduino, and the right pin on the MOSFET is connected to the negative power strip on the breadboard. The negative power strip on the breadboard is then grounded via the Arduino.

Step 6: Next up is the code. It follows a similar line of logic as controlling the LEDs with the potentiometer, with utilizing the map() function on the potentiometer value, except instead of using digitalWrite(), we will be using analogWrite() on the MOSFET. See the [code] for more detailed instructions.

Step 7: There you go! Although the potValue is printed onto the Serial monitor, and is theoretically written onto the MOSFET, it’s difficult to actually visualize this. Feel free to connect the positive and negative pins of the MOSFET out to a resistor-based device, such as a lightbulb (it will fade in and out) or a heat pad like we did, to actually see/feel the MOSFET delivering variable current to the device.

  • However, if you do connect a device, don’t forget a diode! When the current leaves the device, the diode absorbs it so that it does not all rush back to the MOSFET and potentially break it.