Trying to keep a dc fan motor on while a person is pushing the button and off

I am trying to make it so that when a person presses my button the fan would turn on and spin. When they let go the fan would turn off.

This is the fan in question: Fan Module with Propeller and L9110 Driver.

If there is a better fan thats easier to use and not too big please tell me aswell.

"My" Code:

#define Fan 3

const int buttonPin = 2;
int buttonState = 0;

void setup()
{

pinMode(buttonPin, INPUT);
pinMode(Fan,OUTPUT);
Serial.begin(9600); //Baudrate: 9600
}
void loop()
{
buttonState = digitalRead(buttonPin);

if(buttonState == HIGH) {
int value;
for(value = 0 ; value <= 255; value+=5)
{
analogWrite(Fan, value); //PWM
Serial.println(value);
delay(100000000000);} }
else{

}
}

While() loop would do the trick. So while the button is active the fan circuit is on.

something like this:

while (digitalRead(buttonPin) == HIGH){
int value;
for(value = 0 ; value <= 255; value+=5)
{
analogWrite(Fan, value); //PWM
Serial.println(value);
delay(100000000000);} } }

please use code tags per the how to use message in all the forums.

even easier:

while (digitalRead(buttonPin) == HIGH){

    analogWrite(Fan, value);   //PWM
    Serial.println(value);
    delay(100000000000);}

your issue is that value is not being updated correctly... just set a value for now and it will work... are you trying to increment value with the button push?

This looks like a mistake: you want it to wait like a billion seconds before the next time it's available? I would take it out completely.
delay(100000000000)

thank you for your help

youser123:
I am trying to make it so that when a person presses my button the fan would turn on and spin. When they let go the fan would turn off.

Common sense suggests that you wire the button in series with the fan and it does just that. An Arduino - or other microcontroller - is not involved.

Perhaps your requirement is not what you have just described and you want it to do something else? If so, explain what that is.

Paul__B:
Common sense suggests that you wire the button in series with the fan and it does just that. An Arduino - or other microcontroller - is not involved.

Perhaps your requirement is not what you have just described and you want it to do something else? If so, explain what that is.

I want the button to be separate from the arduino and bread board kind of like a remote control. When someones presses the button the fan would run until they let go kind of like a rc car or helicopter.

Add longer wires between the button and the fan.

If it's a high voltage thing (like mains voltage powered) use a relay near the fan and have the button activate the relay.

No Arduino or other microcontroller needed.

youser123:
I want the button to be separate from the arduino and bread board kind of like a remote control. When someones presses the button the fan would run until they let go kind of like a rc car or helicopter.

Then do like Paul_B suggests and use a momentary contact pushbutton of sufficient current ability.
Forget any Arduino.
Or is there more to this than you are saying............?????? :zipper_mouth_face: