0

I want to get a low voltage on output pin of Arduino mega. I have connected Pin 46 to A3, and wrote 120 value to 46 port. Expected was to get 2-3v on A3 input pin. Instead I always get 1023 values as input. Am I doing something wrong ?

void setup(){
  Serial.begin(9600);
  pinMode(46, OUTPUT);
  pinMode(A3,INPUT);
  }

void loop(){
  analogWrite(46,120);
  Serial.println(analogRead(A3));
  }
1
  • You could substitute an Arduino Due and connect to pin DAC1 or DAC2 (located between A11 and CANRX), 12-bit-resolution DAC's :) Commented Sep 20, 2015 at 21:49

1 Answer 1

1

The analog outputs aren't real analog outputs, they are PWM.

That means that they rapidly switch from OFF to ON and back to OFF again. The analog value is the ration of OFF time to ON time, known as the Duty Cycle.

You can convert that rapid switching to a real voltage by passing the signal through a low pass filter. The simplest form is the RC filter:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.