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
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?
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
/* 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);
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
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);
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);
Lesson 4 Light Theremin (video 12 min) https://www.youtube.com/watch?v=57s3dylfw3i Estimated time: 20-30 minutes
/* 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);
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.
#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);