page11
An Arduino Blink Program
1) Connect your Arduino to the host computer using a USB lead.
2) Run the Arduino software on your computer.
3) From the File menu choose Examples → 01.Basics → Blink. The simple Blink sketch should load.
4) Click the Verify button to check the Sketch is OK. In the text area at the bottom of the screen a message like “Binary sketch size: 1008 bytes (of a 14336 byte maximum)” should appear once the verification is complete.
Verify Button
5) Click the Upload button to upload the sketch on to the Arduino. During the upload the LEDs labelled “Rx and Tx” will flash to show the transmission of data. Once the sketch is uploaded you will get a message “Done Uploading” and the sketch will start to run. The pin 13 LED should flash.
Upload Button
6) Try changing the values in brackets in the “delay” function call in the “loop” function. Repeat steps 4 and 5 and see if you notice a difference.
/*
Blink
Turns on an LED on for one second,
then off for one second, repeatedly.
This example code is in the public domain.
*/
void setup() {
// initialize the digital pin as an output:
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // set the LED off
delay(1000); // wait for a second
}
Comment: Everything between a /* and a */ is a comment to help the reader understand the sketch. It is ignored by the Arduino
Comment: Everything on a line after a “//” is also a comment
Setup function: Every sketch must have a setup function. This is run when the Arduino is reset to prepare for the rest of the program
Loop function: Every sketch must have a loop function. After the setup the Arduino repeatedly performs the actions in the loop function
Function call: This is a piece of program that triggers a function to perform a required action. In this case the function tells the Arduino to use digital pin number “LED_BUILTIN” as an output.