I have been asked by several people how I go about teaching young children computing and for the most part I have never written anything down. I keep it all in my head as it allows me to adapt to the situation quicker, different age students move at different rates and have different interests. I have learnt a lot from working at Springfield Junior School and just seeing the difference in ages between 6 and 10 years old. Today I worked with two 9-year-olds, one boy and one girl. We used (and you’ll need to re-create it) an Arduino (we used a MEGA), the usb cable for it, three 220 ohm resistors (although we didn’t use these today), one red, one green and one blue LED or just three different colour LEDs if you can’t find blue Yellow is fine too (that is what we used). I must point out that although nothing bad happened during our sessions you follow these instructions at your own risk.
So Install Arduino as per their instructions. The first thing we did was go through an adaptation of the “Blink” tutorial and gradually altered it. It very simple turns on a LED and back off again. I have annotated it here and then altered it below, my annotations are in blue. and changes to the code are in red. The comments after the “//” symbols are just comments and are ignored by the computer. The same is true of comments that occur between “/*” and “*/” symbols. Here is the hardware set up done using Fritzing.
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
//The set up area runs once at the beginning of the program.
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
}
//The loop area loops again and again.
void loop() {
digitalWrite(13, HIGH); // set the LED on //HIGH applies the current
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off //LOW removes the current
delay(1000); // wait for a second
}
//End of program
This program does exactly the same thing but is just slightly easier to read. Get the student to type in the changes. Changing the “13″ to “Red” They are gonna want to move on from this example pretty quickly it is after all just a flashing light. The good thing about it is that it introduces the use of variables in a meaningful way what is pin 13 to them? but red links the code to the red LED.
/*
Blink V2.0
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
//We are creating a variable called red and giving it the value of 13.
//This helps the younger kids grasp every time we are referring to 13 we actually mean the red LED.
int red =13;
//The set up area runs once at the beginning of the program.
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(red, OUTPUT);
}
//The loop area loops again and again.
void loop() {
digitalWrite(red, HIGH); // set the LED on //HIGH applies the current
delay(1000); // wait for a second
digitalWrite(red, LOW); // set the LED off //LOW removes the current
delay(1000); // wait for a second
}
//End of program
Ok so all we have done is remove the “13″ from being used so much and replaced it with the word “red”, it helps it really does. Especially when we begin to add the “green” and “yellow” or whatever colour LEDS you have. We have in this example used pins 9 and 11 and not 12 and 11 to allow space between the components for inexperienced users, giving them a bit of space so they don’t cross or short circuit. You can use whatever digital pins you like just change the code to reflect that. Get them to type in the changes, get them to re-arrange the chunks of code that turn on and off the light so they flash in a different order. Experiment. The LEDs all share a common Ground or GND, taken from the breadboard back to the Arduino. The kids will soon start to have their own ideas about what they might want to do next and again you’ll move on from this example quickly.
//This program adds two other colours.
/*
Blink V3.0
Turns on several LEDs on, then off.
*/
//We are creating a variable called red and giving it the value of 13.
//This helps the younger kids grasp every time we are referring to 13 we actually mean the red LED and the same is now true for 11 and 9 for green and yellow.
int red =13;
int green = 11;
int yellow = 9;
//The set up area runs once at the beginning of the program.
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(yellow, OUTPUT);
}
//The loop area loops again and again.
void loop() {
//This sequence will turn on the red, then turn it off, turn on the green, then off and then yellow, then off and back to the beginning again.
digitalWrite(red, HIGH); // set the LED on //HIGH applies the current
delay(1000); // wait for a second
digitalWrite(red, LOW); // set the LED off //LOW removes the current
delay(1000); // wait for a second
//These control the Green
digitalWrite(green, HIGH);
delay(1000);
digitalWrite(green, LOW);
delay(1000);
//These control the Yellow
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(1000);
}
//End of program
In this alteration we set up the variable time and set it to 1000, we also subsequently change all of the “1000″‘s in the code to “time”. As it is it will be exactly the same as the last example, however you can then get them to change the value of time try 100ms, try 10ms, try 1ms. We found we actually couldn’t notice the flashing until around 3ms. We also took this opportunity to swap out one of the LEDs with a infrared LED to look at it through the iPhone, which lead to a discussion about being able to transmit message secretly, by flashing morse code on the infrared LED that people couldn’t see with the naked eye. Again, Experiment.
/*
Blink V4.0
Turns on several LEDs on, then off and allows the easy change of time.
*/
//We are creating a variable called red and giving it the value of 13.
//This helps the younger kids grasp every time we are referring to 13 we actually mean the red LED and the same is now true for 11 and 9 for green and yellow.
int red =13;
int green = 11;
int yellow = 9;
int time =1000;
//The set up area runs once at the beginning of the program.
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(yellow, OUTPUT);
}
//The loop area loops again and again.
void loop() {
//This sequence will turn on the red, then turn it off, turn on the green, then off and then yellow, then off and back to the beginning again.
digitalWrite(red, HIGH); // set the LED on //HIGH applies the current
delay(time); // wait for a second
digitalWrite(red, LOW); // set the LED off //LOW removes the current
delay(time); // wait for a second
//These control the Green
digitalWrite(green, HIGH);
delay(time);
digitalWrite(green, LOW);
delay(time);
//These control the Yellow
digitalWrite(yellow, HIGH);
delay(time);
digitalWrite(yellow, LOW);
delay(time);
}
//End of program
I hope this helps, the key is to be willing and ready to change to keep their enthusiasm up. Sure it is just flashing a LED, but it soon becomes their LED, their choice of time to flash, their order of flashing and once they take ownership over the learning they begin to think about what they can change. They very quickly start to think about applications for flashing lights, how they can incorporate this new knowledge in to solving an existing problem. I really like working in small groups, I know it is an ideal situation but working with one or two students at a time means in just around 90 minutes we can cover this area pretty thoroughly and answer a lot of questions they might have. Any questions just tweet me on twitter @pixelh8. I am also running a Creative Computer Club in Ipswich fro 12 to16-year-olds more info here.