Arduino Robot

This summer I decided to have some fun with the various robotics we have at our school.  The first one I worked with was the Arduino microcontroller.  I bought a couple of different quicks from an offshore website (https://www.banggood.com/4WD-Smart-Robot-Car-Chassis-Kits-With-Strong-Magneto-Speed-Encoder-p-917007.html, https://www.banggood.com/2WD-Avoidance-Tracking-Smart-Robot-Car-Chassis-Kit-With-Speed-Encoder-Ultrasonic-For-Arduino-UNO-R3-p-1124282.html) that took a few weeks to arrive, but came with almost all the parts needed (extra wiring was not included, and for the second car I wanted the L298N Motor controller).

It was somewhat tricky to get started, I do not have a background in wiring and electrical work (have wired one Arduino before with a very detailed video) on microcontrollers but this one was not too difficult and has a lot of similar videos that can help.

The trickiest part of the build was linking up the motors to the motor controller and then linking that to the Arduino (or the motor shield, which I have done both now).  The kits do need additional power supplies (the only downside to using the motor control), so I am currently waiting for the 9V battery adapters from Amazon before I can let them drive around my garage freely.

I learned that the fear I had with wiring it wrong was not one I should worry about.  The forgiving part of the arduino is that as long as you identify it correctly in the code as a global variable to the correct pin it will work.  You will need to also connect the ground to the motor and the arduino board ground (on the port side).  The motor controller is beneficial because you can use it to combine motors, change speeds, and provide it with additional power to make it function correctly.  The first car I made had only one power supply to a breadboard and it was unable to work correctly.  Everytime it was connected to the PC is would drive at the right speed and then when connected to battery it would go much faster.

I found the one thing missing from the readings I found was that it did not explain the controllers on the motors easily, so I am labeling it here. Using L298N motor:
– ENA/b controls the speed
– IN1 right motor forward movement if set to high (IN2 must be set to low)
– IN2 right motor reverse movement if set high (IN1 must be set to low)
– IN1 left motor forward movement if set to high (IN4 must be set to low)
– IN2 left motor reverse movement if set high (IN3 must be set to low)
– setting all motors to low will turn it off (like using breaks)

here is the code I have used.

// motor one
int enA = 10;
int in1 = 9;//for
int in2 = 8;//rev
// motor two
int enB = 5;
int in3 = 7;//for
int in4 = 6;//rev

void setup()
{
// set all the motor control pins to outputs
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
}

void demoOne()
{
// this function will run the motors in both directions at a fixed speed
// turn on motor A
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
// set speed to 200 out of possible range 0~255
analogWrite(enA, 200);

// turn on motor B
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
// set speed to 200 out of possible range 0~255
analogWrite(enB, 200);

delay(2000);

// now change motor directions
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);

delay(2000);

// now turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}

void demoThree()
{
//left turn
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
analogWrite(enB, 200);
analogWrite(enA, 200);
delay(1000);

 

//right turn
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
analogWrite(enB, 200);
analogWrite(enA, 200);
}

void loop()
{
demoOne();
delay(1000);
demoThree();
delay(1000);
}

Attached are some photos as well of the designs.  I will post again on this when I have them moving freely.  And I will post about the utlrasonic sensor as well.

Advertisements

CS Teachers Conference at UWaterloo

I had the pleasure of attending this 3 day conference where I was able to learn some older and new technologies that are available from the university as well as things that other educators are doing in their classrooms daily.  For me, it was an amazing opportunity to learn because I have been focused on my math teaching for the past 3 years.   There were come key themes that I took away and some questions I have for the next steps.

The first thing that I continuously thought about (as well as something that I heard from others) was the desire from our students on instantaneous feedback.  Students want to know how they did, if they need to improve, and how they need to improve as soon as they complete a task.  Although this may sound like exciting news, it is not always as great because some students do not want to think about how they can improve, but rather want you to tell them how to improve.

One way the University of Waterloo and other websites provide a way for instantaneous feedback in coding is through “tutorials” where students do not have to download the IDE.  Some examples we looked at in the conference were CSCircles, Codingbat, and Websheets (this is a newer one where you create your own code).  All of these provide some information on the program, the elements you will be tested on, and then a space to code the program required.  When students “ran” the code, the sites would compile and run test cases against the solution code.  It would give error messages and give results based on the test cases.  I found the test cases very helpful because it allowed to student to see that you need a number of test cases and need to make sure that you test a lot to find subtle problems.  They do not all track the students progress as they are to complement the student learning rather than be the classroom they are in.

The other concept that a lot of teachers were implementing was the idea of using cloud services to submit files and to promote collaboration on code.  One industry tool that is constantly being used for coding and other services is Git and Github.  This is a neat tool that creates online repositories and then allows you to share the code with anyone you allow (free Github makes all code public).  In order to collaborate together, you need to give special permission to the other users.  In our session we were all able to access the code presented in an easy way as we didn’t have to download the files and then locate the package to open.  The only downside was that you needed an account and some boards block the use of Git and Github.  Once I get the handle on this, I will hope to use it in my own classes so that students are able to work together and learn skills that the workplace already uses.

The last take away was not the newest concept, but was something that I would like to practice in my classes (even math) and that was the idea of Genius Hour.  The one teacher took it a step forward and talked about how they implement aspects of project management into the genius hour sessions.  In order to work through their personal project they are required to complete the basic components involved in project management.  Every session also included a basic exit card that had key ideas, such as what they learned, what they did, where they need help, and what their next steps were.

As always it was great to go to a conference that stretched my thinking and made me reflect on where I could go next with my learning.