I am trying to control a DC voltage using pulse width modulation (PWM) and an N-channel MOSFET. The way I have set up the circuit is as follows:
However, instead of the motor I have a 100K resistor, in parallel with a 100microfarad (25V) capacitor in order to smooth out the voltage. I am measuring the voltage across this resistor to check if it is being regulated or not:
I am powering the load from the same Arduino (for the time being. I will power it with an external battery once I get PWM working). I have the following code running on the Arduino:
int pwmPin = 3; // connected to the MOSFET's gate
int val = 128; // set between 0 and 255
void setup() {
pinMode(pwmPin, OUTPUT);
}
void loop() {
analogWrite(pwmPin, val);
}
However no matter what I set the value to, I see the output voltage to be the same value of 4.99V instead of being proportional to the duty cycle. This changes as I get very close to 0 (when val=10, V_out = 4.33V and when val=0, V_out = 0V).
Why is this happening? Is the transistor not fast enough? Is the capacitor not big enough? What am I doing wrong? Below are the datasheets for the components:
Sorry if the post has become wordy. I have been downvoted in the past for not including enough details with my post (because I wanted to be concise) and now I am being cautious.
Any help is much appreciated!
Edit: Please disregard the values on the diagram. I have wired my circuit as shown but for the values, as explained in my post I am using the Arduino to power the load. Meaning that the positive pin of the load is connected to Arduino's 5V and the black line in the diagram is connected to the ground of the Arduino. (I did not make the diagram myself and I was myself confused about the 0-60V+ and 0-60- notation, I'm assuming it means the 10K resistor was chosen such that such a range of values would not damage the circuit) I have also included the datasheet to the specific transistor I am using. Thank you for the answers so far.