The Experimenters Kit for Arduino comes with a guide with many example projects you can build, including example sketches. To save you typing them in you can copy and paste them from here into the Arduino IDE.
Project 1: Controlling An LED
This project uses the "Blink" example included with the IDE so you can open it by selecting File -> Examples -> 01.Basics -> Blink. The code is also provided here for reference:
/* Blink Turns on an LED on for one second, then off for one second, repeatedly. This example code is in the public domain. */ // Pin 13 has an LED connected on most Arduino boards. // give it a name: int led = 13; // the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an output. pinMode(led, OUTPUT); } // the loop routine runs over and over again forever: void loop() { digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(led, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second }
Project 2: Controlling 8 LEDs
Example 1:
int ledCount = 8; int ledPins[] = { 6, 7, 8, 9, 10, 11, 12, 13 }; int ledDelay = 300; void setup() { for (int thisLed = 0; thisLed < ledCount; thisLed++) { pinMode(ledPins[thisLed], OUTPUT); } } void loop() { for (int thisLed = 0; thisLed < ledCount-1; thisLed++) { digitalWrite(ledPins[thisLed], HIGH); delay(ledDelay); digitalWrite(ledPins[thisLed], LOW); } for (int thisLed = ledCount-1; thisLed > 0; thisLed--) { digitalWrite(ledPins[thisLed], HIGH); delay(ledDelay); digitalWrite(ledPins[thisLed], LOW); } }
Example 2:
int ledCount = 14; int ledPins[] = { 6, 7, 8, 9, 10, 11, 12, 13, 12, 11, 10, 9, 8, 7 }; int ledDelay = 300; void setup() { for (int thisLed = 0; thisLed < ledCount; thisLed++) { pinMode(ledPins[thisLed], OUTPUT); } } void loop() { for (int thisLed = 0; thisLed < ledCount-1; thisLed++) { digitalWrite(ledPins[thisLed], HIGH); delay(ledDelay); digitalWrite(ledPins[thisLed], LOW); } }
Project 3: Reading Digital (On/Off) Input
int ledCount = 14; int ledPins[] = { 6, 7, 8, 9, 10, 11, 12, 13, 12, 11, 10, 9, 8, 7 }; int ledDelay = 300; int buttonPin = 2; void setup() { for (int thisLed = 0; thisLed < ledCount; thisLed++) { pinMode(ledPins[thisLed], OUTPUT); } pinMode(buttonPin, INPUT); } void loop() { for (int thisLed = 0; thisLed < ledCount-1; thisLed++) { digitalWrite(ledPins[thisLed], HIGH); delay(ledDelay); while(digitalRead(buttonPin) == HIGH) { delay(10); } digitalWrite(ledPins[thisLed], LOW); } }
Project 4: Reading Analog (Variable) Input
int led = 11; int lightLevel; void setup() { Serial.begin(38400); pinMode(led, OUTPUT); } void loop() { lightLevel = analogRead(A0); Serial.print("Light level: "); Serial.println(lightLevel, DEC); digitalWrite(led, HIGH); delay(lightLevel); digitalWrite(led, LOW); delay(lightLevel); }
Project 5: Dimming LEDs Using PWM
Example 1:
int led = 11; int brightness = 0; int delayTime = 10; void setup() { pinMode(led, OUTPUT); } void loop() { while(brightness < 255) { analogWrite(led, brightness); delay(delayTime); brightness = brightness + 1; } while(brightness > 0) { analogWrite(led, brightness); delay(delayTime); brightness = brightness - 1; } }
Example 2:
int led = 11; int lightLevel; int ledLevel; void setup() { Serial.begin(38400); pinMode(led, OUTPUT); } void loop() { lightLevel = analogRead(A0); ledLevel = lightLevel / 4; Serial.print("Light level: "); Serial.println(lightLevel, DEC); analogWrite(led, ledLevel); delay(100); }
Project 6: Making Things Move With Servos
int delaytime=10;
int angle=0; #include <Servo.h> Servo myservo; void setup() { myservo.attach(11); } void loop() { while (angle <=180) { myservo.write(angle); delay(delaytime); angle = angle + 1; } while (angle > 0) { myservo.write(angle); delay(delaytime); angle = angle - 1; } }
Project 7: RGB LED
int redLedPin = 9; int greenLedPin = 10; int blueLedPin = 11; void setup() { pinMode(redLedPin, OUTPUT); pinMode(greenLedPin, OUTPUT); pinMode(blueLedPin, OUTPUT); } void loop() { analogWrite(blueLedPin, random(0, 255)); analogWrite(greenLedPin, random(0, 255)); analogWrite(redLedPin, random(0, 255)); delay(500); }
Project 8: Drive More Outputs With A Shift Register
int dataPin = 2; int latchPin = 3; int clockPin = 4; void setup() { pinMode(dataPin, OUTPUT); pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); } void loop() { for (int currentValue = 0; currentValue < 256; currentValue++) { // Disable the latch while we clock in data digitalWrite(latchPin, LOW); // Send the value as a binary sequence to the module shiftOut(dataPin, clockPin, MSBFIRST, currentValue); // Enable the latch again to set the output states digitalWrite(latchPin, HIGH); delay(200); } }
Project 9: Making Sounds
int piezo = 8; int duration = 250; int notes[] = {261, 293, 329, 349, 392, 440, 493, 523, 587, 659, 698, 783, 880}; // frequencies for musical notes - from middle C, D, E, F, G, A, B, C, D, E, F, G, A void setup() { pinMode(piezo, OUTPUT); } void loop() { for (int i = 0; i < 13; i++) { tone(piezo, notes[i], duration); delay(duration); } for (int i = 11; i > 0; --i) { tone(piezo, notes[i], duration); delay(duration); } }
Project 10: Detecting Vibration and Knocks
Example 1:
int knock = 0; void setup() { Serial.begin(38400); } void loop() { knock = analogRead(0); Serial.println(knock); }
Example 2:
int knock = 0; void setup() { pinMode(13, OUTPUT); } void loop() { knock = analogRead(0); if (knock > 10) { digitalWrite(13, HIGH); delay(500); digitalWrite(13, LOW); } }
Project 11: Light Input Controlling Sound Output
int lightLevel; int piezo = 8; int duration = 300; void setup() { pinMode(piezo, OUTPUT); } void loop() { lightLevel = analogRead(A0); tone(piezo, lightLevel, duration); delay(duration); }