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));
  }
  • You could substitute an Arduino Due and connect to pin DAC1 or DAC2 (located between A11 and CANRX), 12-bit-resolution DAC's :) – James Waldby - jwpat7 Sep 20 '15 at 21:49
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, privacy policy and cookie policy

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