Introduction: Poti PWM Control

About: "Give me a problem, I'll solve it!" is my favorit saying. I try to solve any problem I find and improve nearly everything around me -reinventing things is my thing. So why shouldn't we show it to the…

This article will show you how to build a PWM Controller for e.g. motors / fans that will set the PWM-Value with a poti.

Note: You have to program an Attiny85 (other 8-Pin Attinys like Attiny13 should work too) in this project!
I will not go into this process since it is very well explained in many other instructables ;-)

Beside this, this project is considered as an easy project. It took me about 2h to develop, so you should be much faster.

Bill of materials:

- Attiny85 or similar microcontroller
- Potentiometer (I use an 50kOhm)
- Voltage regulator if the motor voltage is over 5V: We will use a L7805.
- 1x5 Male Pin Header
- Breadboard or PCB (if you want to solder it)

Step 1: Step 1: Schematic

As seen the schematic is really easy.

Some notes:

- I am using a socket for the Attiny! If you don't use a socket, make shure to program the Attiny before soldering it! Programming takes place in Step 2.

You might have noticed, that we don't have capacitors in our power circuit. This design is not recommended since these capacitors are important for a stable voltage. So yes, you can add a capacitors between V_in -> GND and V_out -> GND of the L7805 but since we are only talking about some milliamps that we need to power the microcontroller, we can use the L7805 without any capacitors in this case.

We connect V_out (L7805) to V_in (Attiny) and the Pin 1 of the poti.
Wire all GND together, then connect Pin 2 (Poti) to A1 / PB2 / Pin 7 (Attiny).

Pinheader (left to right):
Short Pin 1 and Pin 2, connect them to GND.
Short Pin 3 and Pind 4, connect them to V_in of the L7805 (NOT V_in of the Attiny!)
Connect Pin 5 to PB0 / Pin 5 of the Attiny.


That's it!

Step 2: Step 2: Programming

The code is simple as well.

I use the Arduino IDE to programm the Attiny.

The code is seen in the picture. You can also download the .ino-File.


What's happening in the code?

Line 1-3: Init pin for reading out the poti, init pin for PWM-Output, init variable for read value from the poti
Line 6-7: Set PWM-pin as output and poti-pin as input.
Line 11: Read out poti and save value in variable.
Line 12-14: If read value is greater zero we devide it be 4* and use result as PWM-value that we set on our PWM-pin.
Line 15-17: If read value zero** we set the PWM-value on our pin to zero as well.

*With the poti we canget values between 0 and 1023. The PWM-value has a range between 0 and 255. So we devide the poti-value by 4 so that we can not get over 255 with the PWM-value.

**It can not be less than zero because we can't read negative