duino for the classro Dr. Francisco Pérez García Institut Pompeu Fabra Asssociation of Science Education Annual Conference , 3rd January 2013 ASE2013 Dr.Pérez 1
Sep 05, 2014
ASE2013 Dr.Pérez 1
Arduino for the classroom
Dr. Francisco Pérez GarcíaInstitut Pompeu Fabra
Asssociation of Science Education Annual Conference, 3rd January 2013
ASE2013 Dr.Pérez 2
Previous experiences: Contemporary Sciences and Research
http://www.youtube.com/watch?v=F_xkHOpMA9s
ASE2013 Dr.Pérez 3
ASE2013 Dr.Pérez 4http://www.youtube.com/watch?v=O1MvwAw_MHk
ASE2013 Dr.Pérez 5
http://www.youtube.com/watch?v=FbuvE1n18ZE
ASE2013 Dr.Pérez 6
My experience with students (Technology branch):
Course 2011-2012Year 11: 16-17 years old4h per weekNumber of students: 12
Course 2012-2013 (Set 2012-Dec 2012)Year 11: 16-17 years old4h per weekNumber of students: 16(Also 2 students of year 12: 17-18 years old in their compulsory RESEARCH PROJECT)
First term: programming with CSecond term: simple projects with Arduino and preparing projectThird term: original project with Arduino
At Institut Pompeu Fabra (High School in Martorell near Barcelona, Catalonia)
ASE2013 Dr.Pérez 7
Student blogs 2011-2012 (Catalan language and part in English)http://cricardoromani.wordpress.comhttp://cdanielaparicio.wordpress.comhttp://cjordinieto.wordpress.comhttp://cjosepalemany.wordpress.comhttp://cadrianarrebola.wordpress.comhttp://calexdelrincon.wordpress.comhttp://ccristiansegovia.wordpress.com
Student blogs 2012-2013 (Only in English language)http://candreamasegosa.wordpress.comhttp://ckelianpordoy.wordpress.comhttp://civanroldan.wordpress.comhttp://cadriansanchez.wordpress.comhttp://cvictorsalvador.wordpress.comhttp://ccarlesdelaiglesia.wordpress.com
ASE2013 Dr.Pérez 8
ASE2013 Dr.Pérez 9
ASE2013 Dr.Pérez 10
WHY PROGRAMMING?
• Computer science is no more about computers than astronomy is about telescopes. Edsger Dijkstra
• The computer revolution hasn’t happened yet. Allan Kay
• Debugging is the essence of intellectual activity. Seymour Pappert
ASE2013 Dr.Pérez 11
TINKERING
ASE2013 Dr.Pérez 12
Tinkering, the “MacGyver” styleFrom the “Tinkering” exhibition at the Exploratorium,San Francisco:
“Tinkering is what happens when you try something youdon’t quite know how to do, guided by whim, imagination,and curiosity.When you tinker, there are no instructions - but thereare also no failures, no right or wrong ways of doingthings. It’s about figuring out how things work andreworking them.Contraptions, machines, wildly mismatched objectsworking in harmony - This the stuff of tinkering.”
ASE2013 Dr.Pérez 13
This definition says a lot about the Arduino way ofprototyping. Actually there is not a manual on how to do things but a reference collection of samples that people can modify and combine with other examples to learn about the logic of the programme and the board.It’s a “hands on” way of working in which even junkbecomes a source for learning and building prototypes.The reuse of material from other fields is an other bigknowledge and material source. Learning how to dothings by looking how other things work and can behacked.Circuit bending and patching are two key words in thislearning school.
ASE2013 Dr.Pérez 14
THE HACKER ATTITUDE FOR OUR STUDENTS
ASE2013 Dr.Pérez 15
The Hacker Attitude for our students
Five things taken from Eric S. Raymond’s How To Become a Hacker:1. The world is full of fascinating problems waiting to be solved.2. No problem should ever have to be solved twice.3. Boredom and drudgery are evil.4. Freedom is good.5. Attitude is no substitute for competence.
ASE2013 Dr.Pérez 16
What is Arduino
• Open Source Hardware, you can make your own board, or buy one.
• Cheap, easily available.• Open Source Software.• Very widespread, many projects openly
available.• Extra HW (shields) available (over 250 at
http://shieldlist.com.
ASE2013 Dr.Pérez 17
ESPLORA
LEONARDO
ASE2013 Dr.Pérez 18
Arduino Uno
ASE2013 Dr.Pérez 19
Arduino Language
• C like syntax, but simplified• Abstracts the pin naming to numbers• Trades efficience for ease of use• Easy to learn, yet powerful• Lots of example code • Easy to reuse C-code from other projects• Libraries can be written in C++• Lots of libraries available
ASE2013 Dr.Pérez 20
Console
Download Arduino software atwww.arduino.cc
ASE2013 Dr.Pérez 21
BOARD TYPE
ASE2013 Dr.Pérez 22
Sketch name or versionToolbar
Save
OpenNew
UploadVerify Code
ASE2013 Dr.Pérez 23
Comments about thecode
Setup codeDefine variables
Loop codeMain code
ASE2013 Dr.Pérez 24
/*BlinkTurns on an LED on for one second,then off for one second, repeatedly.This example code is based on example code that is in the public domain.*/const int LED = 13; /* LED connected to digital pin 13*/void setup() {// initialize the digital pin as an output./*Pin 13 has an LED connected on most Arduino boards: */pinMode(LED, OUTPUT);}void loop() {digitalWrite(LED, HIGH); // set the LED ondelay(1000); // wait for a seconddigitalWrite(LED, LOW); // set the LED off delay(1000); // wait for a second}
Blink code is the equivalent to a Hello world to test our Arduino board
ASE2013 Dr.Pérez 25
ASE2013 Dr.Pérez 26
Transistor IRF530DC motor
Diode 1N4001Resistor
Arduino Uno
ARDUINO AND A DC MOTOR
AND THISSOURCE CODE
ASE2013 Dr.Pérez 27
const int transistorPin = 9; // connected to transistor gate
void setup() {pinMode(transistorPin, OUTPUT);}
void loop() { // loop= repeat again and againdigitalWrite(transistorPin, HIGH); // switch the motor ondelay(50); // wait for 50 milisecondsdigitalWrite(transistorPin, LOW); // switch the motor offdelay(5000); // wait for 5 seconds
}
SOURCE CODE FOR ARDUINO MOTOR
ASE2013 Dr.Pérez 28
MOTOR TO IRRADIATE A SURFACE VERY SLOWLY
ASE2013 Dr.Pérez 29
ASE2013 Dr.Pérez 30
http://www.youtube.com/watch?v=UQEtOJE02wE
ASE2013 Dr.Pérez 31
http://www.youtube.com/watch?v=e1iUjelHC6w
ASE2013 Dr.Pérez 32
RGB LED BLINKING
ASE2013 Dr.Pérez 33
int Columns[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};int Rows[] = {12, 11, 10};int t=400;void setup(){int counter;for (int counter = 0; counter < 10; counter++){pinMode(Columns[counter], OUTPUT); }for (int counter = 0; counter < 4; counter++){pinMode(Rows[counter], OUTPUT); }}void loop(){digitalWrite(Rows[1], HIGH);digitalWrite(Columns[4], HIGH);delay(t);
Controlling LEDs cubes: Explosion example
/*For loop: if this conditional is true do the code insidethe curly brackets, if it’s false exists the for loop*/
ASE2013 Dr.Pérez 34
for(int i=0;i<t;i++){ if(i%2==0){ digitalWrite(Rows[0], LOW); digitalWrite(Rows[2], LOW); digitalWrite(Columns[1], HIGH); digitalWrite(Columns[3], HIGH); digitalWrite(Columns[5], HIGH); digitalWrite(Columns[7], HIGH); } else { digitalWrite(Columns[1], LOW); digitalWrite(Columns[3], LOW); digitalWrite(Columns[5], LOW); digitalWrite(Columns[7], LOW); digitalWrite(Rows[0], HIGH); digitalWrite(Rows[2], HIGH); } delay(1);} for(int j=0; j<t; j++){ if(j%2==0){ digitalWrite(Columns[0], LOW); digitalWrite(Columns[2], LOW); digitalWrite(Columns[8], LOW); digitalWrite(Columns[6], LOW);
} else { digitalWrite(Rows[0], LOW); digitalWrite(Rows[2], LOW); digitalWrite(Columns[0], HIGH); digitalWrite(Columns[2], HIGH); digitalWrite(Columns[8], HIGH); digitalWrite(Columns[6], HIGH); } delay(1); } digitalWrite(Rows[0], HIGH); digitalWrite(Rows[2], HIGH); delay(t); for (int counter = 0; counter < 10; counter++){digitalWrite(Columns[counter], LOW); }for (int counter = 0; counter < 4; counter++){digitalWrite(Rows[counter], LOW); }}
digitalWrite(Rows[0], HIGH); digitalWrite(Rows[2], HIGH); digitalWrite(Columns[1], HIGH); digitalWrite(Columns[3], HIGH); digitalWrite(Columns[5], HIGH); digitalWrite(Columns[7], HIGH);
ASE2013 Dr.Pérez 35
ASE2013 Dr.Pérez 36
ASE2013 Dr.Pérez 37
http://www.youtube.com/watch?v=z4Qo9NDDRco
ASE2013 Dr.Pérez 38
Materials forLDR and LED-RGB using Arduino
● -4 resistor 220 Ω
● -1 LDR sensor
● -1 RGB LED
● -1 potenciometer
● -1 Arduino Uno
● - Wire
● - Breadboard
● - USB wire AB type or microUSB for Arduino Leonardo
ASE2013 Dr.Pérez 39
LDR
ASE2013 Dr.Pérez 40
Pulse width modulation
ASE2013 Dr.Pérez 41
ASE2013 Dr.Pérez 42
Microcontroller ATMega328
Sensors(analog inputs)
Brain
Sight
Touch
Taste
SmellHearing
Muscles
Nerves Wires, Circuit
Heart
Actuators(analogoutputs)
ASE2013 Dr.Pérez 43
Analog to digital conversion
Analog sensor 0 to 5V
Sampling at Nyquist rate
Value of each sample transformed to binaryformat
ASE2013 Dr.Pérez 44
ASE2013 Dr.Pérez 45
ASE2013 Dr.Pérez 46
SOURCE CODE: RGB-LED colour change depending on light level
int valueLDR = 1;
int ledRed = 9;
int ledGreen=10;
int ledBlue=11;
int pinLDR = 1;
//3 outputs for each RGB colour: red, green and blue
void setup(){
pinMode(ledRed, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(ledBlue, OUTPUT);
analogReference(EXTERNAL);
}
/*First we define the variable name as integer and it is assigneda value*/
/*The setup function comes before the loop function, and everythinghappens inside the curly backets*/
/*Outputs are declared in setup, this is done by usingthe pinMode function, in this particular example we declare numbers 9, 10 and 11 as OUTPUT (in capital letters)*/
// or /*Comment*/ can be anywhere, do not affect code, help others
ASE2013 Dr.Pérez 47
void loop() {
valueLDR = analogRead(pinLDR);
if(valueLDR >= 1023){
digitalWrite(ledRed, 128);
digitalWrite(ledGreen, 0);
digitalWrite(ledBlue, 0);
// digitalWrite to obtain different colours
}
else if((valueLDR >= 959) & (valueLDR < 1023)){
digitalWrite(ledRed, 255);
digitalWrite(ledGreen, 0);
digitalWrite(ledBlue, 0);
}
The “void” in the header is what the function will return (or spit out) when it happens, in this case it returns nothing so it is void
ASE2013 Dr.Pérez 48
else if((valueLDR >= 895) & (valueLDR < 959)){
digitalWrite(ledRed, 255);
digitalWrite(ledGreen, 128);
digitalWrite(ledBlue, 0);}
else if((valueLDR >= 831) & (valueLDR < 895)){
digitalWrite(ledRed, 255);
digitalWrite(ledGreen, 255);
digitalWrite(ledBlue, 0);}
else if((valueLDR >= 767) & (valueLDR < 831)){
digitalWrite(ledRed, 255);
digitalWrite(ledGreen, 255);
digitalWrite(ledBlue, 128);}
else if((valueLDR >= 703) & (valueLDR < 767)){
digitalWrite(ledRed, 128);
digitalWrite(ledGreen, 255);
digitalWrite(ledBlue, 255);
}
else if((valueLDR >= 639) & (valueLDR < 703)){
digitalWrite(ledRed, 128);
digitalWrite(ledGreen, 128);
digitalWrite(ledBlue, 255);}
else if((valueLDR >= 575) & (valueLDR < 639)){
digitalWrite(ledRed, 0);
digitalWrite(ledGreen, 128);
digitalWrite(ledBlue, 255);}
else if((valueLDR >= 511) & (valueLDR < 575)){
digitalWrite(ledRed, 0);
digitalWrite(ledGreen, 0);
digitalWrite(ledBlue, 255);}
else if((valueLDR >= 447) & (valueLDR < 511)){
digitalWrite(ledRed, 0);
digitalWrite(ledGreen, 0);
digitalWrite(ledBlue, 128);
}
else if((valueLDR >= 383) & (valueLDR < 447)){
digitalWrite(ledRed, 0);
digitalWrite(ledGreen, 128);
digitalWrite(ledBlue, 0);}
else if((valueLDR >= 319) & (valueLDR < 383)){
digitalWrite(ledRed, 0);
digitalWrite(ledGreen, 255);
digitalWrite(ledBlue, 0);}
else if((valueLDR >= 255) & (valueLDR < 319)){
digitalWrite(ledRed, 128);
digitalWrite(ledGreen, 255);
digitalWrite(ledBlue, 0);}
else if((valueLDR >= 191) & (valueLDR < 255)){
digitalWrite(ledRed, 0);
digitalWrite(ledGreen, 255);
digitalWrite(ledBlue, 128);
}
ASE2013 Dr.Pérez 49
else if((valueLDR >= 127) & (valueLDR < 191))
{
digitalWrite(ledRed, 128);
digitalWrite(ledGreen, 255);
digitalWrite(ledBlue, 128);}
else if((valueLDR >= 63) & (valueLDR < 127))
{
digitalWrite(ledRed, 128);
digitalWrite(ledGreen, 128);
digitalWrite(ledBlue, 128);}
else if((valueLDR >=0) & (valueLDR < 63)){
digitalWrite(ledRed, 55);
digitalWrite(ledGreen, 55);
digitalWrite(ledBlue, 55); }
else
{
digitalWrite(ledRed, 0);
digitalWrite(ledGreen, 0);
digitalWrite(ledBlue, 0);
}
}
void color(int red, int green, int blue)
{
analogWrite(ledRed, 255-red);
analogWrite(ledGreen, 255-green);
analogWrite(ledBlue, 255-blue);
// PWM for every colour
ASE2013 Dr.Pérez 50
http://www.youtube.com/watch?v=hxkYNy4zTWc
ASE2013 Dr.Pérez 51
ASE2013 Dr.Pérez 52
Playing music with Arduinohttp://www.youtube.com/watch?v=YDL9WIVfS9w
ASE2013 Dr.Pérez 53
ASE2013 Dr.Pérez 54
ASE2013 Dr.Pérez 55
Spychip technology?
ASE2013 Dr.Pérez 56
ASE2013 Dr.Pérez 57
ASE2013 Dr.Pérez 58
SENSORS FOR ARDUINO
ASE2013 Dr.Pérez 59
Transistor: to amplify the signal of the sensor to the Arduino
ASE2013 Dr.Pérez 60
Sensors with 1kOhm resistor an NPN amplifier transistor and a 7805 regulator transitor and sensors from Sandbox Electronics, battery, LCD and Arduino Uno board
ASE2013 Dr.Pérez 61
LED RGB AS AN EMITTER AND NORMAL LED AS A SENSOR AND PROGRAM THE BRUNTON ALGORITHM TO TRANSFORM RGB EMISSION TO WAVELENGTH 350-700u
ASE2013 Dr.Pérez 62
Cloud internet of things platforms: www.cosm.comVisualize and store sensor data online www.nimbits.com
www.thingspeak.com
ASE2013 Dr.Pérez 63
ASE2013 Dr.Pérez 64
ASE2013 Dr.Pérez 66
Approximate pricing
• Arduino Leonardo €25• Resistors, LEDs, LDR around €5• Breadboard €10• MQ sensors (CO, CH4, etc) €5 each• MG811 (CO2 sensor) €50• Voice recognition shield €60• Arduino for Android €50Sometimes very high import taxes from China!
ASE2013 Dr.Pérez 67
Resources• www.arduino.cc• http://blocs.xtec.cat/mecanica• www.sparkfun.com• www.fritzing.org• www.buildinginternetofthings.com• www.atmel.com/avr• www.avrfreaks.net• www.mcselec.com• www.argentdata.com
ASE2013 Dr.Pérez 68
ACKNOWLEGMENTS
This project on Arduino for the classroom is part of a project entitled«Contemporary Sciences and Research» given to Institut Pompeu Fabrafrom 2012 to 2014 and includes a book edition on Contemporary Sciences
More information on Arduino and videos http://blocs.xtec.cat/mecanica
More information on the whole project at http://blocs.xtec.cat/pile
Book available on Nature magazine discoveries in 2012 supported by this project at http://www.formaciovirtual.com/cs