Monday, January 26, 2015

Robot Club - third session completed

Link to Preparing post details in the parts in the kits.:

Link to First session;

Yes, I didn't do a post on the second session so here's a summary.
More time building the robots Added the L298N h-bridge to control the motors, put batteries in and touched wires to make the wheels spin.

On to the 3rd session.
Today was a bit different in that 6 of the kids couldn't make it. 5 were at an event in the O2 while the sixth had something else to do, so there were only 4 in the club today.
The great ICT Tech at the school had installed the necessary drivers to allow the Arduino Nano compatibles to work with the school computers.  As you'd expect for a school these computers are quite locked down, so very grateful for the work the school tech did.

As there were only 4 kids in the club each of them had their own Arduino robot to work with.
I explained the pins on the Arduino that we were using and why I selected pins 3, 5, 6 and 9 because these are the PWM lines. A bit sketching on the whiteboard and it looked like they understand the principle of using PWM which would be a project for another day.

Rather than beginning with a blank project we opened the example blink sketch and discussed what it did and how it worked.
Setting up the variable 'led' to equal 13
Setting 'led' to an OUTPUT

How the loop sets 'led' to HIGH turning the LED on
Waits one second
sets 'led' to LOW turning the LED off
Wait one second

We then discussed how the principles of turning an LED on and off is the same principle as making the motors spin.

Explained we had to set up 4 variables for the 4 pins controlling the 2 motors.
I asked them what the variables should be called.
One suggestion was variable1, variable2, variable3, variable4.  Following a few more questions and answers it became clear that these variable names wouldn't help is to remember what each variable was meant for.

We settled on.

Then set them all as OUTPUT

Added extra code to the loop to set one pin for each motor high and the other low causing the wheel to spin.

I was delighted when one of the kids who was new to the club asked if he could make the other wheel spin and explained how he would do it using the other pair of variables.
After this his robot started to spin and he wanted it to go straight so he changed the polarity of one of the motors and the the robot when whizzing off across the floor.

What a great session.  The kids did some real programming.Improved their understanding of variables and modifying the code.

Even learning how to use the keyboard to copy and paste to make it easy to do the 4 variable lines and the digitalWrite() commands without having to type every character manually.
Simple skills that make a big difference.

Next week the kids who didn't make today will be back so there will have to be a bit of a recap and then the first challenge.  Program the robot to go around the centre island of the  ICT Suite.
This will require them to figure out how to turn and with some trial and error work out the timing needed to navigate the course.
If they  get this done quickly I will add a slalom path as well requiring finer control.

Roll on next week and more fun.