Arduino IDE Examples


Let’s start with the first sketches


Included in the Arduino Software you will find built-in Examples (sketches). These simple programs contain all basic Arduino commands. To open them click on the toolbar menu: File > Examples. 


  Reads an analog input on pin 0, prints the result to the serial monitor.
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

 This example code is in the public domain.

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  delay(1);        // delay in between reads for stability

Extend the power of the IDE through the libraries


Just like most programming platforms, The Arduino Software (IDE) can be extended through the use of libraries to provide extra functionality to your sketches. With these tutorials you will be able to go through the examples of a number of the various libraries that are provided with the IDE. To open them click on the toolbar menu: File > Examples.


  Time Check

 Gets the time from Linux via Bridge then parses out hours,
 minutes and seconds for the Arduino using an Arduino Yún.

 created  27 May 2013
 modified 21 June 2013
 By Tom Igoe

 This example code is in the public domain.



Process date;                 // process used to get the date
int hours, minutes, seconds;  // for the results
int lastSecond = -1;          // need an impossible value for comparison

void setup() {
  Bridge.begin();        // initialize Bridge
  Serial.begin(9600);    // initialize serial

  while (!Serial);              // wait for Serial Monitor to open
  Serial.println("Time Check");  // Title of sketch

  // run an initial date process. Should return:
  // hh:mm:ss :
  if (!date.running()) {

void loop() {

  if (lastSecond != seconds) { // if a second has passed
    // print the time:
    if (hours <= 9) Serial.print("0");    // adjust for 0-9
    if (minutes <= 9) Serial.print("0");  // adjust for 0-9
    if (seconds <= 9) Serial.print("0");  // adjust for 0-9

    // restart the date process:
    if (!date.running()) {

  //if there's a result from the date process, parse it:
  while (date.available() > 0) {
    // get the result of the date process (should be hh:mm:ss):
    String timeString = date.readString();

    // find the colons:
    int firstColon = timeString.indexOf(":");
    int secondColon = timeString.lastIndexOf(":");

    // get the substrings for hour, minute second:
    String hourString = timeString.substring(0, firstColon);
    String minString = timeString.substring(firstColon + 1, secondColon);
    String secString = timeString.substring(secondColon + 1);

    // convert to ints,saving the previous second:
    hours = hourString.toInt();
    minutes = minString.toInt();
    lastSecond = seconds;          // save to do a time comparison
    seconds = secString.toInt();


non cancellare {module [341]} {module [343]}