Thursday, February 19, 2015

Robot Club - fifth session completed

Full house this week.

Link to Fourth Session:

Full house and I  think everyone was ready for half-term.
A lot more boisterous and distracted than early on.

From the Preparing Blog post we were working with the line following sensor.

Line following sensor£1.195£5.95

The weekend before I did some work with this sensor and rather than reflecting different amounts of infra-red light depending on the colour of the surface it is more responsive to changes in effectiveness. So, a matt black surface to a shiny white surface gives the highest contrast and so gives the best reading.
The sensor also has a very limited analogue range and really is a digital switch. Meaning if the contrast is large enough it returns a HIGH signal.

With this knowledge we discussed inputs and how up until now we have only been doing outputs. Sending signals from the Arduino to the motors, with no information coming from the robot to the Arduino.  So, we have no idea if the robot is bumping into things.

Using the whiteboard we went through the operation of the sensor and how to wire it up. VCC, GND Out. We wired it to Digital Pin 2.

Modified the code to add a pinMode(2, INPUT) to the setup and an if statement in the loop() to read the pin and for this session using the Serial Monitor display a message on the computer.

It took a while to work through this as with 5 kits there was some fun with the wiring and understanding the change in the program.  

As mentioned before rather than just having the kids type in a piece of code I'm trying to worth through the logic with them so that the process is understand and not just have the ability to copy/paste.

By the end all 5 robots were reading the sensor from digital pin 2 and outputting a message to the Serial Monitor.

We now have a 3 week gap. 2 Mondays due to half-term and an inset day and I'm unavailable for the following Monday.

For the next session I will get all the code so far to the same place for each group and we will modify the code to make the robot turn around when it gets near an obstacle. It should be fun seeing 5 little robots running around the floor turning when they get near to obstacles. 

Wednesday, February 4, 2015

Robot Club - fourth session completed

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

Link to First session;

Note; I did not post for the second session. There is a short summary in the Third Session post.
Link to Third session:

This week we nearly had a full house.
Only 1 child missing due to illness.

The 4 who attended the previous week remember a lot of their work and code so were getting stuck into getting their robots to go around a corner.

I had a bit more fun getting drivers on enough school PCs to permit the Arduino Nano to be seen. It needs custom USB/Serial drivers that are not included by default.

The teacher who is ICT coordinator came in to see the session in full swing with robots spinning, or moving along the floor. With coding going on and due to plus and minus lines on the batteries being shorted a nice little display of black smoke and the lovely smell of burnt plastic.
No real harm done just a jumper wires plastic sleeving was melted.
I congratulated the child on making smoke as it's something we all do when we work with electronics.  They were kind of shocked.
It was great that the teacher had the same attitude so no harm done and no concern about burning down the school.
I tested their robot kit and Arduino. Nothing damaged, amazingly so did a little bit of rewiring and handed them back their robot to get working on again.

On of the kids who was in the previous session had a problem where their robot was pulling to the left.  These are small cheap kits so the motors aren't tuned and the wheels are small and have grip meaning they catch on the carpet.  Meaning they cannot reliably go straight.
We tried to fix it by turning the wheels in or our to change the resistance but no go so introduced that child to analogWrite.
A value of 235 seemed to make it all work perfectly. They had a nice straight running robot.

Once again the kids were not that eager to leave as they were perfecting their code and making it better.

At the end one of the girls who was being collected wanted to show her mother what she had done so she gave a great demonstration of her robot.  Holding down reset to stop it moving.
Set it up and let it go. She then explained the code she had made as well as giving details on some of the other parts we will be using.

Next week we will be using an input device. A small line following sensor. I will mark the edge of the room area with white paper providing a contrast with the blue flooring. The idea will be to detect the paper and make the robot turn.
This will be the first time the kids do inputs and will also require the introduction of the 'if' statement.

Looking forward to another productive session next Monday.

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.