t
ARDUINO DRIVERS LICENCE
Lesson 1
Get to know the tools/Make a circuit (14 minute video) https://www.youtube.com/watch?v=2X8d_r0p92U
Estimated time: 20-30 minutes
Concepts
What is a circuit? Ground and power, transducers, circuits in series, current, parallel circuits
t
A simple Circuit that turns the light on when we push the button. Power runs from the 5V (5 volt) on the arduino to the positive (+) rail on the breadboard, up the wire to the pushbutton, when the pushbutton is pressed, it sends power to the LED, through the resistor, back down the wire to the negative rail (-) and back to the GND (ground) pin on the Arduino. Because the LED only needs 1.7 volts, we use the resistor to protect it from getting too much power and burning out.
Extra: Can you make Parallel and series circuits? A circuit in series needs every button to be pressed A circuit in parallel needs only one button to be pressed. When would you use each type of circuit?
t
Lesson 2 Spaceship Interface (7 minute Video)
https://www.youtube.com/watch?v=7JoQvT1oEdA Estimated time: 20-30 minutes
Concepts
Introduction to arduino programming, variables, loops, board setup, if then/else loop,
digitalread
t
/* Project 2 - Spaceship Interface
Created 13 September 2012
by Scott Fitzgerald
http://arduino.cc/starterKit
This example code is part of the public domain */
// Create a global variable to hold the
// state of the switch. This variable is persistent
// throughout the program. Whenever you refer to
// switchState, you’re talking about the number it holds
int switchstate = 0;
void setup(){
// declare the LED pins as outputs
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
// declare the switch pin as an input
pinMode(2,INPUT);
}
void loop(){
// read the value of the switch
// digitalRead() checks to see if there is voltage
// on the pin or not
switchstate = digitalRead(2);
// if the button is not pressed
// blink the red LEDs
if (switchstate == HIGH) {
digitalWrite(3, HIGH); // turn the green LED on pin 3 on
digitalWrite(4, LOW); // turn the red LED on pin 4 off
digitalWrite(5, LOW); // turn the red LED on pin 5 off
}
// this else is part of the above if() statement.
// if the switch is not LOW (the button is pressed)
// the code below will run
else {
digitalWrite(3, LOW); // turn the green LED on pin 3 off
digitalWrite(4, LOW); // turn the red LED on pin 4 off
digitalWrite(5, HIGH); // turn the red LED on pin 5 on
// wait for a quarter second before changing the light
delay(250);
digitalWrite(4, HIGH); // turn the red LED on pin 4 on
digitalWrite(5, LOW); // turn the red LED on pin 5 off
// wait for a quarter second before changing the light
delay(250);
}
}
t
Lesson 3 Love-o-meter (14 minute video)
https://www.youtube.com/watch?v=RJPKuGF4lRE Estimated time: 20-30 minutes
Concepts
Digital and Analog pins, input components,analog read, for loop, multiple if statements
t
by Scott Fitzgerald
// named constant for the pin the sensor is connected to
const int sensorPin = A0;
// room temperature in Celcius
const float baselineTemp = 20.0;
void setup(){
// open a serial connection to display values
Serial.begin(9600);
// set the LED pins as outputs
// the for() loop saves some extra coding
for(int pinNumber = 2; pinNumber<5; pinNumber++){
pinMode(pinNumber,OUTPUT);
t
digitalWrite(pinNumber, LOW);
}
}
void loop(){
// read the value on AnalogIn pin 0
// and store it in a variable
int sensorVal = analogRead(sensorPin);
// send the 10-bit sensor value out the serial port
Serial.print("sensor Value: ");
Serial.print(sensorVal);
// convert the ADC reading to voltage
float voltage = (sensorVal/1024.0) * 5.0;
// Send the voltage level out the Serial port
Serial.print(", Volts: ");
Serial.print(voltage);
// convert the voltage to temperature in degrees C
// the sensor changes 10 mV per degree
// the datasheet says there's a 500 mV offset
// ((volatge - 500mV) times 100)
Serial.print(", degrees C: ");
float temperature = (voltage - .5) * 100;
Serial.println(temperature);
// if the current temperature is lower than the baseline
// turn off all LEDs
if(temperature < baselineTemp){
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
} // if the temperature rises 2-4 degrees, turn an LED on
else if(temperature >= baselineTemp+2 && temperature < baselineTemp+4){
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
} // if the temperature rises 4-6 degrees, turn a second LED on
else if(temperature >= baselineTemp+4 && temperature < baselineTemp+6){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
} // if the temperature rises more than 6 degrees, turn all LEDs on
else if(temperature >= baselineTemp+6){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}
delay(1);
}
t
Lesson 4 Light Theremin (video 12 min)
https://www.youtube.com/watch?v=57S3dylfw3I Estimated time: 20-30 minutes
t
t
/*
Arduino Starter Kit example
Light Theremin
This sketch is written to accompany Project 6 in the
Arduino Starter Kit
Created 13 September 2012
by Scott Fitzgerald
http://arduino.cc/starterKit
This example code is part of the public domain
*/
// variable to hold sensor value
int sensorValue;
// variable to calibrate low value
int sensorLow = 1023;
// variable to calibrate high value
int sensorHigh = 0;
// LED pin
const int ledPin = 13;
void setup() {
// Make the LED pin an output and turn it on
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
// calibrate for the first five seconds after program runs
while (millis() < 5000) {
// record the maximum sensor value
sensorValue = analogRead(A5);
if (sensorValue > sensorHigh) {
sensorHigh = sensorValue;
}
// record the minimum sensor value
if (sensorValue < sensorLow) {
sensorLow = sensorValue;
}
}
// turn the LED off, signaling the end of the calibration period
digitalWrite(ledPin, LOW);
}
void loop() {
//read the input from A0 and store it in a variable
sensorValue = analogRead(A5);
// map the sensor values to a wide range of pitches
int pitch = map(sensorValue, sensorLow, sensorHigh, 50, 4000);
// play the tone for 20 ms on pin 8
tone(6, pitch, 20);
// wait for a moment
delay(10);
}
t
Lesson 5 Safecracker
https://www.youtube.com/watch?v=BQxAvhNnMeo Estimated time: 20-30 minutes
Concepts
Servos, if then statements/map function. Trimpot or potentiometer: This type of
component allows us to change the resistance on the component by turning the knob or
screw. A common use for these types of component are volume controls.
t
t
#include <Servo.h>
Servo myservo;
int potpin = 0;
int rawval;
int val;
const int Led1=6;
const int Piezo=4;
int combone=50;
void setup()
{
myservo.attach(9);
pinMode(Led1, OUTPUT);
pinMode(Piezo, OUTPUT);
pinMode(potpin, INPUT);
randomSeed(analogRead(potpin));
combone=random(0,180);
Serial.begin(9600);
}
void loop()
{
Serial.println(combone);
rawval = analogRead(potpin);
//Serial.print(rawval);
val = map(rawval, 0, 1023, 0, 179);
Serial.print(" ");
myservo.write(val);
Serial.println(val);
delay(15);
if (val == combone) {
digitalWrite(Led1,HIGH);
tone(4, 100, 25);
}
else
{
digitalWrite(Led1, LOW);
}
t