T-622 / 25KHz-Arduino-Fan-PWM-Control

Arduino program that control individual timers OC1RA and ICR1. Allows for PWM control 0-100% and 8MHz.
22 stars 5 forks source link

Adding Pot? #2

Open slayernn021 opened 9 months ago

slayernn021 commented 9 months ago

Hello. This project is great in my setup, using 80mm server fan,work perfectly and thanx for it! I want to ask, is it posible to add potentiometer to control setPwmDuty cycle and how? Im arduino beginer, i know to handle and mod code but thats it. Thx

T-622 commented 9 months ago

For sure! You just need to adjust the duty cycle based on a "Mapped" analog value (IE: 0-1023, 0-100). The code in the main loop could be replaced by the following:

NOTE: This code assumes you use analog pin #0 for reading

int pwmDuty = analogRead(0); pwmDuty = map(pwmDuty, 0, 1023, 0, 100); setPwmDuty(pwmDuty);

Use the above indicated code snippet to replace the contents of void loop() from what they are now. Hook a potentiometer's pin to A0, and this should change duty based on the analog value (0-1023), which gets mapped to 0-100% duty cycle, which controls the PWM's duty cycle on the output.

Tell me if this works, Tyler

slayernn021 commented 9 months ago

I have some 10k pot, work perfect from start! Thanx very much!!