Hackers Guild Resource Site

The Hackers Guild Resource Site

View on GitHub

Arduino Examples

Arduino Examples

Note In addition to all Components listed in examples below, you will need connecting wires, a Breadboard and an Arduino (Uno).

Digital Output

Components: Atleast 2 LEDs and 2 resistors (220 Ohms)

Single LED

Single LED

Code

  int led = 13;                   // integer variable led is declare
  void setup() {                  // the setup() method is executed only once
    pinMode(led, OUTPUT);         // the led PIN is declared as digital output
  }

  void loop() {                   // the loop() method is repeated
    digitalWrite(led, HIGH);      // switching on the led
    delay(1000);                  // stopping the program for 1000 milliseconds
    digitalWrite(led, LOW);       // switching off the led
    delay(1000);                  // stopping the program for 1000 milliseconds
  }  

Multiple LEDs in Series

LED in Series

Code Use the same code as the single LED example.

Multiple LEDs in Parallel

LED in Parallel

Code Use the same code as the single LED example.

Simple Traffic Light Simulation

Simple Traffic Light Simulation

Code

  int led1 = 11;                   // integer variable led is declared
  int led2 = 12;
  int led3 = 13;

  void setup() {                  // the setup() method is executed only once
    pinMode(led1, OUTPUT);         // the led PIN is declared as digital output
    pinMode(led2, OUTPUT);
	  pinMode(led3, OUTPUT);
  }

  void loop() {                   // the loop() method is repeated
    digitalWrite(led1, HIGH);      // switching on the led
    digitalWrite(led2, LOW);      // switching on the led
    digitalWrite(led3, LOW);      // switching on the led
    delay(4000);                  // stopping the program for 1000 milliseconds
    digitalWrite(led1, LOW);      // switching on the led
    digitalWrite(led2, HIGH);      // switching on the led
    digitalWrite(led3, LOW);      // switching on the led
    delay(2000);                  // stopping the program for 1000 milliseconds
    digitalWrite(led1, LOW);      // switching on the led
    digitalWrite(led2, LOW);      // switching on the led
    digitalWrite(led3, HIGH);      // switching on the led
    delay(5000);                  // stopping the program for 1000 milliseconds
  }

Digital Input

Analog Input

Analog Output