Arduino Analog Output

ArduinoWorld
0

The PWM feature on the Arduino enables you to simulate an analog output voltage on specific digital

interfaces. The function to use the PWM feature is the analogWrite

analogWrite(pin, dutycycle);

Example Code


int analogInPin = A0;

int analogOutPin = 9;               // Analog output pin that the LED is attached to

int analogValue = 0;                 // value output to the PWM (analog out)


void setup() {

  Serial.begin(9600);                 // initialize serial communications at 9600 bps:

}


void loop() {

  analogValue = map(analogRead(A0), 0, 1023, 0, 255);       // read the analog in value with map

  Serial.print("analogValue = ");                                            // print the results to the Serial Monitor:

  Serial.println(analogValue);

  analogWrite(analogOutPin, analogValue);                          // change the analog out value:

  delay(1000);                                                                         // wait 1 seconds

}





 

Post a Comment

0 Comments

Post a Comment (0)
3/related/default