controling Arduino output voltage using a power supply

dl324

Joined Mar 30, 2015
16,846
I understand that from this code below , that i have already made the pin to work on 50% to produce a heater of 6v if the input is 12v
Technically, your driving the motor with 12V half of the time which gives an average voltage of 6V. The phrase "heater of 6V" makes no sense. You can speak of half power, but not half voltage.
but i don't understand how and where i should apply the potentiometer , to PWM the signal from the power source
Connect the pot across the Arduino power supply and read the wiper position with an analog input. Use that value to control the duty cycle in line 4.
 

djsfantasi

Joined Apr 11, 2010
9,156
Technically, your driving the motor with 12V half of the time which gives an average voltage of 6V. The phrase "heater of 6V" makes no sense. You can speak of half power, but not half voltage.
Connect the pot across the Arduino power supply and read the wiper position with an analog input. Use that value to control the duty cycle in line 4.
You’ll need to map the analog input value to the PWM value. The analog input is 0-1023. The PWM value is 0-254.

The map() function will do this for you. If Pot is the analog input and PWM is the desired PWM value, the following statement will work:

PWM = map(Pot, 0,1023, 0, 254);

will do this for you.
 
Top