From charlesreid1

No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Blink LED=
=Blink LED=


==Overview==
==Overview==  


In this article, we go over a simple blink program using the Arduino Micro. This is the same as the [[Hello World Arduino Micro]] circuit, but with the Arduino controlling the voltage of the circuit to make it blink.
In this article, we go over a simple blink program using the Arduino Micro. This is the same as the [[Hello World Arduino Micro]] circuit, but with the Arduino controlling the voltage of the circuit to make it blink.
Line 29: Line 29:
==The Arduino Sketch Code==
==The Arduino Sketch Code==


The first half is changing the circuit; the other half is changing the logic. The built-in Arduino blink program is useful, but not particularly graceful. It shows us how to toggle the voltage, but it's a bit clunky in how it implements the library. Here it is:
The following Arduino sketch will make the LED blink:


''Built-in Arduino Blink Program:''
{{Scroll box|
<source lang="C">
<source lang="C">


Line 43: Line 40:




// the loop function runs over and over again forever
// this sends SOS forever
 
void loop() {
void loop() {
   digitalWrite(13, HIGH);  // turn the LED on (HIGH is the voltage level)
   digitalWrite(13, HIGH);  // turn the LED on (HIGH is the voltage level)
   delay(200);             // wait for a second
   delay(200);
   digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
   digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
   delay(200);             // wait for a second
   delay(200);
  digitalWrite(13, HIGH);  // turn the LED on (HIGH is the voltage level)
</source>
  delay(200);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(200);              // wait for a second
  digitalWrite(13, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(200);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(200);              // wait for a second


  delay(1000);              // wait for a second
Now, we can make the LED blink "SOS" with some very clunky code:


  digitalWrite(13, HIGH);  // turn the LED on (HIGH is the voltage level)
{{Scrollbox|
  delay(500);              // wait for a second
<source lang="C">
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(200);              // wait for a second


  digitalWrite(13, HIGH);  // turn the LED on (HIGH is the voltage level)
// the setup function runs once when you press reset or power the board
   delay(500);              // wait for a second
void setup() {
   digitalWrite(13, LOW);   // turn the LED off by making the voltage LOW
   // initialize digital pin 13 as an output.
  delay(200);              // wait for a second
   pinMode(13, OUTPUT);
}


  digitalWrite(13, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(500);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(200);              // wait for a second


  delay(1000);              // wait for a second
// this sends SOS forever


void loop() {
   digitalWrite(13, HIGH);  // turn the LED on (HIGH is the voltage level)
   digitalWrite(13, HIGH);  // turn the LED on (HIGH is the voltage level)
   delay(200);             // wait for a second
   delay(200);
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(200);              // wait for a second
  digitalWrite(13, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(200);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(200);              // wait for a second
  digitalWrite(13, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(200);              // wait for a second
   digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
   digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
   delay(200);             // wait for a second
   delay(200);
  digitalWrite(13, HIGH);
  delay(200);
  digitalWrite(13, LOW);
  delay(200);
  digitalWrite(13, HIGH);
  delay(200);
  digitalWrite(13, LOW);
  delay(200);


   delay(1000);             // wait for a second
   delay(1000);
 
}
</source>
}}


We'd rather have a more graceful Morse Code library.
  digitalWrite(13, HIGH);
  delay(500);
  digitalWrite(13, LOW);
  delay(200);


==Installing the Arduinomorse Library==
  digitalWrite(13, HIGH);
  delay(500);
  digitalWrite(13, LOW);
  delay(200);


On to the next part of the project: getting Arduino to run Morse Code! See the [[Arduinomorse Library]] page.
  digitalWrite(13, HIGH);
  delay(500);
  digitalWrite(13, LOW);
  delay(200);


==An Arduinomorse Sketch==
  delay(1000);


Now we can rewrite our sketch to use the arduinomorse library. NOTE THAT IT MUST BE LOWERCASE:
  digitalWrite(13, HIGH);
  delay(200);
  digitalWrite(13, LOW);
  delay(200);
  digitalWrite(13, HIGH);
  delay(200);
  digitalWrite(13, LOW);
  delay(200);
  digitalWrite(13, HIGH);
  delay(200);
  digitalWrite(13, LOW);
  delay(200);


<source lang="c">
  delay(1000);
#define PIN_STATUS 12
#include <morse.h>
LEDMorseSender sender(PIN_STATUS);
//SpeakerMorseSender sender(PIN_STATUS);


void setup() {
    sender.setup();
    sender.setWPM(20);
    sender.setMessage(String("v v v de kc7dbu ar"));
    sender.startSending();
}
void loop() {
    sender.continueSending();
}
}
</source>
</source>
}}


How does this bad boy work? Well, the morse library contains encodings of letters into dots and dashes. These dots and dashes are then encoded into voltage signals that are dits or dashes. When the voltage is applied, the LED lights up.
This works, for demonstrating how a blink circuit works, but it'd sure be nice to have a Morse Code library and make that code more compact and graceful.
 
=Blink Speaker=
 
The next part of the project is to connect a speaker in lieu of an LED, so that we can use that same voltage to generate morse code tones from a speaker.
 
The speaker I used was a 3 - 28 V DC piezoelectric speaker. No resistors were needed, since I was using 5 volts, which was in the range of the speaker.
 
==The Circuit==
 
===Breadboard Diagram===
 
Here is a breadboard layout using Fritzing:
 
[[Image:bb_BlinkSpeaker.png|500px]]
 
As mentioned, pretty straightforward: we're powering the positive and negative buses with the red and black cables, connected to the Arduino's 12 pin and ground, respectively. We then route power from the positive bus to the piezo speaker's red wire, then the voltage passes through the speaker (generating sound), and the remaining voltage passes through the black wire to ground.
 
===Breadboard Photo===
 
Here is a photo of the above circuit, constructed on a breadboard:
 
[[Image:photo_BlinkSpeaker2.jpg|500px]]
 
==The Arduino Sketch Code==
 
Finally, we can use the Arduinomorse library to generate our morse code tones, by switching from a <code>LEDMorseSender</code> object to a <code>SpeakerMorseSender</code> object:


<source lang="c">
==Using a Morse Code Library==
#define PIN_STATUS 12
#include <morse.h>
//LEDMorseSender sender(PIN_STATUS);
SpeakerMorseSender sender(PIN_STATUS);


void setup() {
Here is a link to an article describing a blink circuit using a morse code library:
    sender.setup();
    sender.setWPM(20);
    sender.setMessage(String("v v v de kc7dbu ar"));
    sender.startSending();
}
void loop() {
    sender.continueSending();
}
 
</source>


[[Morse Code Blink Arduino Micro]]




=Flags=


[[Category:Arduino]]
{{ArduinoFlag}}
[[Category:Arduino Micro]]

Latest revision as of 09:38, 16 April 2017

Blink LED

Overview

In this article, we go over a simple blink program using the Arduino Micro. This is the same as the Hello World Arduino Micro circuit, but with the Arduino controlling the voltage of the circuit to make it blink.

In the simple Hello World example, we wanted a constant source of potential, 5 volts, to keep the LED light continuously lit. Now, we want to control the voltage so that we can shut the light on and off. The program we load onto the Arduino microcontroller will allow us to create a logical program to control the voltage.

The Circuit

Breadboard Diagram

The circuit for our blink program is almost exactly the same as for the Hello World program, except now we plug it into a numbered pin on the Arduino board:

Bb Blink1.png

Instead of plugging into the 5V pin, we plug it into the D12 pin.

NOTE: Don't use the D13 pin. It starts with a pulse on-off routine.

Breadboard Photo

The final breadboard arrangement:

Photo Blink1.jpg

Note that we've added three resistors, instead of two. It doesn't particularly matter - as long as the resistance is not too low! (Otherwise we'll burn out our LED.)

The Arduino Sketch Code

The following Arduino sketch will make the LED blink:

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}


// this sends SOS forever

void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(200);
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(200);

Now, we can make the LED blink "SOS" with some very clunky code:

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}


// this sends SOS forever

void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(200);
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(200);
  digitalWrite(13, HIGH);
  delay(200);
  digitalWrite(13, LOW);
  delay(200);
  digitalWrite(13, HIGH);
  delay(200);
  digitalWrite(13, LOW);
  delay(200);

  delay(1000);

  digitalWrite(13, HIGH);
  delay(500);
  digitalWrite(13, LOW);
  delay(200);

  digitalWrite(13, HIGH);
  delay(500);
  digitalWrite(13, LOW);
  delay(200);

  digitalWrite(13, HIGH);
  delay(500);
  digitalWrite(13, LOW);
  delay(200);

  delay(1000);

  digitalWrite(13, HIGH);
  delay(200);
  digitalWrite(13, LOW);
  delay(200);
  digitalWrite(13, HIGH);
  delay(200);
  digitalWrite(13, LOW);
  delay(200);
  digitalWrite(13, HIGH);
  delay(200);
  digitalWrite(13, LOW);
  delay(200);

  delay(1000);

}

This works, for demonstrating how a blink circuit works, but it'd sure be nice to have a Morse Code library and make that code more compact and graceful.

Using a Morse Code Library

Here is a link to an article describing a blink circuit using a morse code library:

Morse Code Blink Arduino Micro


Flags