Tinkercad simulation shows that it should work, but when I try it on breadboard, the potentiometer seems to not respond correctly. Only when I turn it all the way to right, the motor suddenly start spinning, a slight turn to the left and it stops.
Note: This circuit will need to be externally powered.
Yes the voltage between A0 and GND goes from 0 to 5 when I turn the knob.
BUT
Only when I power the Arduino from the barrel plug.
When I try it using external power supply, it does not work
Mosfet is: P30N06LE
Here is the code:
int analogValue = 0;
int pot = A0;
int motor = 3;
void setup()
{
pinMode(pot, INPUT);
pinMode(motor, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
}
void loop()
{
Serial.println(analogRead(pot));
analogValue = analogRead(pot);
analogWrite(motor, map(analogValue, 0, 1023, 0, 255));
delay(10); // Delay a little bit to improve simulation performance
}
Pins default to INPUT, which is what you specified. If you don't specify an OUTPUT pin you get in trouble.
But I must admit I usually specify the mode for all the pins I'm using. It's makes it easier for people who don't remember what the default is to work out what's intended when they're reading the program.
Would you say that this can perform the task of what I am trying to achieve with Arduino here?
The overall project cost could drastically reduce if so.
It's able to handle voltage up to 15V and current up to 2A.