Workshop (English)
For this Arduino workshop you need a sensor actor shield. This is rather uncommon so it's rather difficult to reproduce it at home. You can catch up with the german version of this workshop the german is very basic, it's full of links to circuits and running code. Or you go directly to the homepage of the Arduino project where you find tons of ressources, tutorials, documentation and examples.
Of course you need an Arduino board and a minimum of parts. You can find all this at selectronic, 11 Place de la Nation, 75011 Paris.
0. Hello World: Blink
Open, upload and run the following sketch:
File >> Examples >> 01.Basic >> Blink
1. Breadboard: LED
//Image created with Fritzing. The Resistor for the LED is 150 Ohm, color coded brown-green-brown (+ gold)
int ledPin; void setup() { ledPin = 9; pinMode(ledPin, OUTPUT); } void loop() { digitalWrite(ledPin, HIGH); // LED on delay(1000); // wait a second digitalWrite(ledPin, LOW); // LED off delay(1000); // wait another second }
2. Digital Out: LED
from here we need the sensor-actor-shield.
int ledPin; void setup() { ledPin = 5; //3, 5 or 6 on sensor actor shield pinMode(ledPin, OUTPUT); } void loop() { digitalWrite(ledPin, HIGH); // LED on delay(1000); // wait a Second (1000 Milliseconds) digitalWrite(ledPin, LOW); // LED off delay(1000); // wait another second }
3. Analog In: Pot
int potPin = 5; int potValue = 0;
void setup() { Serial.begin(9600); }
void loop() { potValue = analogRead(potPin); Serial.println(potValue); }
4. Analog Out: LED on PWM
Combine sketch 2 with sketch 3 to dim the light of a LED with the pot.
You might also adapt the sketch
File >> Examples >> 3.Analog >> AnalogInOutSerial
The technique behind this is called pulse width modulation.
5. Digital In: Micro Switch
int switchPin = A2; //A1, A2 or A3 on sensor-actor-shield int ledPin = 6; ///3, 5 or 6 on sensor-actor-shield int switchState = 0;
void setup() { pinMode(ledPin, OUTPUT); pinMode(switchPin, INPUT_PULLUP); }
void loop(){ switchState = digitalRead(switchPin); if (switchState == HIGH) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } }
Change the code in order to turn on the LED by pressing the switch.
6. Sensor
Adapt Sketch 3 to read a sensor value on A0.
7. Library: Servo
Without Sensor Actor Shield
File >> Examples >> Servo >> Sweep
8. Keyboard
//Arduino Leonardo can emulate a Keyboard and a Mouse.
#include <Keyboard.h>
int switchPin1 = A1; int switchPin2 = A2; int switchPin3 = A3; int switchState1 = 0; int switchState2 = 0; int switchState3 = 0; int ledPin1 = 3; int ledPin2 = 5; int ledPin3 = 6; void setup() { pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); pinMode(ledPin3, OUTPUT); pinMode(switchPin1, INPUT_PULLUP); pinMode(switchPin2, INPUT_PULLUP); pinMode(switchPin3, INPUT_PULLUP); Keyboard.begin(); } void loop(){ switchState1 = digitalRead(switchPin1); if (switchState1 == HIGH) { digitalWrite(ledPin1, LOW); Keyboard.release('w'); } else { digitalWrite(ledPin1, HIGH); Keyboard.press('w'); } switchState2 = digitalRead(switchPin2); if (switchState2 == HIGH) { digitalWrite(ledPin2, LOW); Keyboard.release('a'); } else { digitalWrite(ledPin2, HIGH); Keyboard.press('a'); } switchState3 = digitalRead(switchPin3); if (switchState3 == HIGH) { digitalWrite(ledPin3, LOW); Keyboard.release('d'); } else { digitalWrite(ledPin3, HIGH); Keyboard.press('d'); } }
Appendix: Inspirations
Piano Legends
https://www.youtube.com/watch?v=FyGy3f51h3c
Energy Race
https://www.youtube.com/watch?v=Az-v0T5VoEk
Reverse Geocashing
http://arduiniana.org/projects/the-reverse-geo-cache-puzzle/
Electronic Board Game
http://www.instructables.com/id/How-To-Make-A-Board-Game-Using-Arduino/
Game-Controller
http://arduino.cc/blog/category/controllers/game-controllers/
Step Sequencer
https://www.youtube.com/watch?v=3CD1Df6DOBM
Wearable Computing
http://arduino.cc/blog/category/wearable-computing/