user15187: As Arduino Uno has a 16 MHz oscillator but while running program it has less frequency because some of the processing power is used for running the program.
I have used the delay(1) but it is giving me around 500 Hz. 
My questions:

Is there any way to achieve more than 500 Hz?
What would be the maximum frequency of digital signal for below program?

void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);          
  digitalWrite(13, LOW);         
}


user16725: Also, don't forget that there are alternative methods of toggling outputs.
You can use PORTS to do the job. 
Here's a good example. And another here.
And this code is the idea behind it:
void setup()
{
  DDRD = B11111111; // set PORTD (digital 7~0) to outputs
}

void loop()
{
  PORTD = B11111111; // set PORTD pins (digital 7~0) high
  PORTD = B00000000; // set PORTD pins (digital 7~0) low
}

P.S. Don't forget that the port numbering is in reference to the chip pins and not the Arduino pins/legs.

user58549: Nick Gammon's code worked fine for me. Here is an oscilloscope picture of the waveform I've got from his code:

His code above (from Nick Gammon, on Jan 25 '16 at 20:33) worked excellent for me. I used his code on Arduino UNO and got about 7.9 MHz of output frequency on an approximately 1 V amplitude (peak-to-peak, with spikes making it go to about 2 V peak-to-peak amplitude).
The image above was obtained with my 40 MHz Oscilloscope from ICEL Manaus (manufacturer) at pin 9 (I used the Arduino UNO), with a LED and a resistor as a load at pin 9: 

a green LED of about 1.79 V voltage drop
and a 4.7 Ohms resistor with 5% tolerance

The oscilloscope probe (Channel 2, with fall slope trigger detect) is on the 4.7 Ohms resistor. It follows the connection order out of the pin 9 from Arduino UNO:
PIN 9 > green LED > 4.7 Ohms resistor >  GROUND.
The green LED keeps blinking at a normal luminescence, as compared when used at other output frequencies.
I used a external 5 V DC power supply, along with the USB connection on my PC.
If you have any questions just put them here. Thanks and thanks Nick Gammon

user10794: 
Yes, use the hardware timers.
You can achieve 8 MHz.

Example sketch which outputs 8 MHz on pin 9 on a Uno:
#ifdef __AVR_ATmega2560__
  const byte CLOCKOUT = 11;  // Mega 2560
#else
  const byte CLOCKOUT = 9;   // Uno, Duemilanove, etc.
#endif

void setup ()
  {
  // set up 8 MHz timer on CLOCKOUT (OC1A)
  pinMode (CLOCKOUT, OUTPUT); 
  // set up Timer 1
  TCCR1A = bit (COM1A0);  // toggle OC1A on Compare Match
  TCCR1B = bit (WGM12) | bit (CS10);   // CTC, no prescaling
  OCR1A =  0;       // output every cycle
  }  // end of setup

void loop ()
  {
  // whatever 
  }  // end of loop

If you change OCR1A you can get lower frequencies. If you change the prescaler you can get lower frequencies again.
See my page about timers for more details.

15187: <p>As Arduino Uno has a 16 MHz oscillator but while running program it has less frequency because some of the processing power is used for running the program.
I have used the <code>delay(1)</code> but it is giving me around 500 Hz. </p>

<p><strong>My questions:</strong></p>

<ol>
<li>Is there any way to achieve more than 500 Hz?</li>
<li>What would be the maximum frequency of digital signal for below program?</li>
</ol>

<pre class="lang-cpp prettyprint-override"><code>void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);          
  digitalWrite(13, LOW);         
}
</code></pre>
 16725: <p>Also, don't forget that there are alternative methods of toggling outputs.</p>

<p>You can use PORTS to do the job. </p>

<p>Here's a good <a href="http://www.billporter.info/2010/08/18/ready-set-oscillate-the-fastest-way-to-change-arduino-pins/" rel="nofollow">example</a>. And another <a href="http://tronixstuff.com/2011/10/22/tutorial-arduino-port-manipulation/" rel="nofollow">here</a>.</p>

<p>And this code is the idea behind it:</p>

<pre><code>void setup()
{
  DDRD = B11111111; // set PORTD (digital 7~0) to outputs
}

void loop()
{
  PORTD = B11111111; // set PORTD pins (digital 7~0) high
  PORTD = B00000000; // set PORTD pins (digital 7~0) low
}
</code></pre>

<p>P.S. Don't forget that the port numbering is in reference to the chip pins and not the Arduino pins/legs.</p>
 58549: <p><strong>Nick Gammon's</strong> code worked fine for me. Here is an <strong>oscilloscope picture</strong> of the waveform I've got from <strong>his code</strong>:</p>

<p><a href="https://i.stack.imgur.com/8NWfq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8NWfq.png" alt="Output of Arduino UNO pin 9, approximately 1 V peak-to-peak Amplitude with spikes"></a></p>

<p>His code above (<em>from Nick Gammon, on Jan 25 '16 at 20:33</em>) worked excellent for me. I used his code on Arduino UNO and got about <strong>7.9 MHz</strong> of output frequency on an approximately <strong>1 V amplitude</strong> (peak-to-peak, with spikes making it go to about <strong>2 V peak-to-peak amplitude</strong>).</p>

<p>The image above was obtained with my 40 MHz Oscilloscope from <em>ICEL Manaus</em> (manufacturer) at pin 9 (I used the Arduino UNO), with a LED and a resistor as a load at pin 9: </p>

<ul>
<li>a green LED of about 1.79 V voltage drop</li>
<li>and a 4.7 Ohms resistor with 5% tolerance</li>
</ul>

<p>The oscilloscope probe (<em>Channel 2, with fall slope trigger detect</em>) is on the 4.7 Ohms resistor. It follows the connection order out of the pin 9 from Arduino UNO:
<em>PIN 9</em> > <em>green LED</em> > <em>4.7 Ohms resistor</em> >  <em>GROUND</em>.</p>

<p>The green LED keeps blinking at a normal luminescence, as compared when used at other output frequencies.</p>

<p>I used a external 5 V DC power supply, along with the USB connection on my PC.</p>

<p>If you have any questions just put them here. Thanks and thanks <a href="https://arduino.stackexchange.com/users/10794/nick-gammon">Nick Gammon</a></p>
 10794: <ol>
<li><p>Yes, use the hardware timers.</p></li>
<li><p>You can achieve 8 MHz.</p></li>
</ol>



<p>Example sketch which outputs 8 MHz on pin 9 on a Uno:</p>

<pre class="lang-C++ prettyprint-override"><code>#ifdef __AVR_ATmega2560__
  const byte CLOCKOUT = 11;  // Mega 2560
#else
  const byte CLOCKOUT = 9;   // Uno, Duemilanove, etc.
#endif

void setup ()
  {
  // set up 8 MHz timer on CLOCKOUT (OC1A)
  pinMode (CLOCKOUT, OUTPUT); 
  // set up Timer 1
  TCCR1A = bit (COM1A0);  // toggle OC1A on Compare Match
  TCCR1B = bit (WGM12) | bit (CS10);   // CTC, no prescaling
  OCR1A =  0;       // output every cycle
  }  // end of setup

void loop ()
  {
  // whatever 
  }  // end of loop
</code></pre>

<p>If you change OCR1A you can get lower frequencies. If you change the prescaler you can get lower frequencies again.</p>

<p>See <a href="http://www.gammon.com.au/timers" rel="noreferrer">my page about timers</a> for more details.</p>
