Go Down

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

#### g_lubenov

##### Mar 19, 2014, 09:43 pm
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?

#1
Hi, try this:

#### g_lubenov

#2
##### Mar 20, 2014, 09:40 pm

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 9int analogPin = 0;   // potentiometer connected to analog pin 3int val = 0;         // variable to store the read valuevoid 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)  ); } `

#### PaulRB

#3
##### Mar 20, 2014, 10:44 pm
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.

Paul

Go Up