Looking for example code for pwm fan control

I am trying to figure out how to control the speed of a 12-volt fan with 2 digital pushbuttons. one will speed up the fan and the other slows it down. I am thinking of 5 steps, the fan starts off, pushing one button and fan turns on, each push of the first button makes the fan speed up. after 5 pushes the button no longer does anything. then pushing the other button the fan slows down until 5 pushes and fan is off.

Needing links to the code to better understand how to do this. I am still learning code.

I have a potentially new and exciting link for you: https://www.google.com

Just enter your search terms and it will search the internet for you. I'm sure you will find at least a dozen projects doing what you asked for.

Here is another link that should help you with your project.

What do you need help with, and how far did you get?

Can you control the fan speed with PWM? Do you have a transistor/MOSFET driver circuit?

Can you read the buttons?

Is this a 4-wire fan with speed-feedback or are you just using 5 different PWM levels?

pylon:
I have a potentially new and exciting link for you: https://www.google.com

Just enter your search terms and it will search the internet for you. I’m sure you will find at least a dozen projects doing what you asked for.

I have spent 4 days on google, I have found a couple of things but no real answers. I can read buttons, and able to run the fan with a fixed PWM, and its a 2 wire fan.

stilgarhammer:
I can read buttons, and able to run the fan with a fixed PWM, and its a 2 wire fan.

So, create a counting variable. When the increment button *becomes *pressed (IDE -> file/examples/digital/state change detection) add one to the variable, when decrement is pressed subtract. Use the constrain() function to keep the count variable within your limits. Prove it out using the serial monitor.

If count variable is equal to X, analog write the value for that position. Or, get fancy and use count variable to index into an array which holds the analog write values.

Sounds like a good starting point, thanks