Pages: [1]   Go Down
Author Topic: PWM, different analog values?  (Read 291 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

West Yorkshire, UK
Offline Offline
Edison Member
*
Karma: 41
Posts: 1237
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, try this:



* 1395335472750.jpg (149.57 KB, 1280x720 - viewed 22 times.)
« Last Edit: March 20, 2014, 12:03:37 pm by PaulRB » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
 
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)  );

}

 
Logged

West Yorkshire, UK
Offline Offline
Edison Member
*
Karma: 41
Posts: 1237
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: