Go Down

Topic: PWM, different analog values? (Read 631 times) previous topic - next topic


Hey guys, i have a small problem, i need a pwm but my analog values are not a 0-5V, my lowest value are 2 volts and highest is 3 volts.For 2 volts i must have a 0% duty cycle, for 3 volts full 100% duty cycle, i don't have any idea how to make it?


Mar 20, 2014, 05:54 pm Last Edit: Mar 20, 2014, 06:03 pm by PaulRB Reason: 1
Hi, try this:


Hi, try this:

Hi Paul, but i have opposite problem, voltage which control arduino is between 2 and 3 volts , for 2 volts  on a  analog in must have a 0% duty cycle  for 3 volts on a analog in must be 100% duty cycle. For example this work perfekt but vrom 0 to 1 volts
Code: [Select]

int ledPin = 3;      // LED connected to digital pin 9

int analogPin = 0;   // potentiometer connected to analog pin 3

int val = 0;         // variable to store the read value

void setup()


  pinMode(ledPin, OUTPUT);   // sets the pin as output


void loop()


  val = analogRead(analogPin) / 4 ;   // read the input pin
if (val < 50)

analogWrite (ledPin, LOW);

if (val > 55)
analogWrite (ledPin,  (val / 2)  );



I'm sorry but I am finding your question, and your sketch very difficult to understand.

can I suggest you take a look at the map () function.


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131