1

I am trying to create an AC voltage in Arduino. Until now I have only managed to get a square wave. How can this be achieved with Arduino?

If I try:

int up;
int down;
int out = 11;
void setup() {
 pinMode(out, OUTPUT);
 Serial.begin(9600);
}
void loop() {
 for (up = 0; up <= 255; up++) {
 analogWrite(out, up);
 delay(1);
 }
 for (down = 255; down >= 0; down--) {
 analogWrite(out, down);
 delay(1);
 }
}

is it still pulsed DC?

dda
1,5951 gold badge12 silver badges17 bronze badges
asked Feb 7, 2018 at 14:21
3
  • 1
    Yes, it is still a square wave, varying between 0V and 5V. You need some extra hardware to do that. Commented Feb 7, 2018 at 14:32
  • 1
    What kind of frequency are you looking for? Do you want a sinewave, triangle wave, saw-tooth wave ... ? Commented Feb 7, 2018 at 14:42
  • just use an opamp to turn your square wave into a sine wave with a few caps and resistors Commented Feb 7, 2018 at 20:44

1 Answer 1

3

You have a few options:

  • Use a low-pass filter to round the square wave's edges some so they look more AC-ish.

  • Use a low-pass filter and have your code create steps of voltage that look AC-ish by varying the PWM widths.

  • Use an external SPI DAC chip that you can control with more discrete levels to make smoother looking AC.

  • Look into Direct Digital Synthesis (DDC) to learn more. Google "analog via ddS", lots of hits.

dda
1,5951 gold badge12 silver badges17 bronze badges
answered Feb 7, 2018 at 17:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.