user15187: I'm trying to make AC current (50Hz) with an Arduino Uno. It seems to be not working (or wrong code).
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);
  }
}

Update:

Now the code above is giving output voltage of 0-5V (getting increased from 0 to 5 and then decreased) not giving a negative cycle (-5V).
After setting the minimum delay of 1, the output wave is still half wave rectifier with frequency 2Hz.
Without delay LED is blinking so fast I don't know what's its frequency.

How do I make make 50Hz AC current a with negative cycle?

user-1: I ran your sketch and this is the output signal:

analogWrite produce a square wave.
As Majenko said, you have to add a low pass filter to get that sine wave.

15187: <p>I'm trying to make AC current (50Hz) with an Arduino Uno. It seems to be not working (or wrong code).</p>

<pre><code>int up;
int down;
int out = 11;
void setup() {
  pinMode(out, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  for (up = 0; up &lt;= 255; up++) {
    analogWrite(out, up);
    delay(1);
  }
  for (down = 255; down &gt;= 0; down--) {
    analogWrite(out, down);
    delay(1);
  }
}
</code></pre>

<p><strong>Update:</strong></p>

<ol>
<li><p>Now the code above is giving output voltage of 0-5V (getting increased from 0 to 5 and then decreased) not giving a negative cycle (-5V).</p></li>
<li><p>After setting the minimum delay of 1, the output wave is still half wave rectifier with frequency 2Hz.</p></li>
<li><p>Without delay LED is blinking so fast I don't know what's its frequency.</p></li>
</ol>

<p>How do I make make 50Hz AC current a with negative cycle?</p>
 -1: <p>I ran your sketch and this is the output signal:</p>

<p><a href="https://i.stack.imgur.com/oD0dc.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oD0dc.jpg" alt="square wave"></a></p>

<p><code>analogWrite</code> produce a square wave.</p>

<p>As Majenko said, you have to add a low pass filter to get that sine wave.</p>
