Arduino Workshop for Teachers @ EMU

Presented by SIGCS and The Department of Computer Science at Eastern Michigan University

This workshop is intended for teachers who are interested in learning to wire and program the Arduino. Arduinos will be supplied for use during the workshop. We are using kits purchased from Amazon and Parallax – Arduino robots.

Introduction:

I’ve been teaching a one semester class with Arduino for ten year. I learned how to use Arduino along with my students and my course has continuously evolved over time. My complete course is posted on this website.

From the Arduino website:

Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino boards are able to read inputs – light on a sensor, a finger on a button, or a Twitter message – and turn it into an output – activating a motor, turning on an LED, publishing something online. You can tell your board what to do by sending a set of instructions to the microcontroller on the board. To do so you use the Arduino programming language (based on Wiring), and the Arduino Software (IDE), based on Processing.

Blink:
Lets make sure the boards will communicate and take a quick look over the Arduino IDE. We are going to cause an LED on the Arduino to flash at different rates.

Paste this Code into the Arduino IDE:
Here’s the complete code:

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

If you have programming experience this should look very familiar. If you are new to programming, this page will explain all the code. Play a bit, make the LED flash at different rates.

Now build the circuit shown below (need more help?). If you’ve done it correctly the LED on the Breadboard will flash along with the LED on the Arduino board.

Breadboard with Arduino and LED

Add on a couple more LEDs (don’t forget the resistors). Then make all the LEDs flash together and/or in sequence.

Digital Input:

Next we’ll add in a push button. Build this circuit:

Arduino wired to LEDs on Pins ( and 10 and a pushbutton on pin2

Try this Code. You won’t see anything unless you open the Serial Monitor:

int buttonPin = 2;
int buttonState = 0;
int led = 10;

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  delay(10);
  buttonState = digitalRead(buttonPin);
 
  if (buttonState == HIGH)
  {
    digitalWrite(led, HIGH);
    Serial.println("Button Pressed");
  }
  else
  {
    digitalWrite(led, LOW);
    Serial.println("Button Released");
  }
}

Now, do something with the second LED. Doesn’t really matter what. You should also check out the Serial Monitor. You should notice that “Button Pressed” and “Button Released” print over and over again. This code will stop that from happening:

int buttonPin = 2;
int buttonState = 0;
int buttonPressed = 0;

void setup() {
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);
}

void loop() {
  delay(100);
  buttonState = digitalRead(buttonPin);
  
  if (buttonState == HIGH && buttonPressed == 0)
  {
    Serial.println("Button Pressed");
    buttonPressed = 1;
  }
  
  if (buttonState == LOW && buttonPressed == 1)
  {
    Serial.println("Button Released");
    buttonPressed = 0;
  }
}

This should print Button Pressed only one time when the button is pressed. This idea can be built upon to create a toggle. The code below will turn an LED on when the button is pressed and the LED will stay on until the button is pressed again.

HIGH, true, and 1 are Synonymous:

int buttonPin = 2;
int buttonState = 0;
int buttonPressed = 0;
int ledPin = 10;
bool ledState = false;

void setup() {
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  delay(100);
  buttonState = digitalRead(buttonPin);
  
  if (buttonState && !buttonPressed)
  {
    Serial.println("Button Pressed");
    buttonPressed = 1;
    ledState = !ledState;
  }
  
  if (!buttonState && buttonPressed)
  {
    Serial.println("Button Released");
    buttonPressed = 0;
  }

  digitalWrite(ledPin, ledState);  
}

Analog Read and Write:

Time to explore the Example Sketches. In the Arduino IDE open:

File->Examples->Analog->Fading

Wire an LED (with resistor) up to Pin 9 and upload the code. You should see your LED pulsing on and off. Can you make it faster? Slower?

Things to know:

    • analogWrite is 8 bit (0-255)
    • overflow – 256 is the same as 0
    • Only certain pins support analogWrite. Marked with either PWM or a ~

Next load up:

File->Examples->Analog->AnalogInput

Potentiometer wired to pin A0 LED wired to pin 10

Change the cod to light up the LED plugged into pin 10. The turn the knob to see the flash rate change. Then try this code:

int sensorPin = A0;    
int ledPin = 10;
int sensorValue = 0;
int val = 0;

void setup() {
  pinMode(ledPin, OUTPUT);

}

void loop() {
  sensorValue = analogRead(sensorPin);
  val = map(sensorValue, 0, 1023, 0, 255);
  analogWrite(ledPin, val);
}

analogRead returns a 10 bit number (0 – 1023), so we use the map() function to adjust it to use with analogWrite. If you are feeling ambitious you can swap your potentiometer out for a light sensitive resistor (Note: the code example on this page is incomplete. You will need to fix it).

Make things Move
Next dig out the Servo motor and wire it as shown below:

Servo wired to pin 9 and potentiometer wired to A0

Open: File->Examples->Servo->Knob

Note: Standard servo motors adjust from 0 to 180°. Here we use map() to adjust our analogRead values to this range.

Arduino Robot

We are using the NICERC Shield Bot with Arduino Kit. The kit comes with a complete guide, but I don’t know that I’d use it as more than a general reference. I should note that I am not a classically trained coder. So I might be wrong in this.

Here are a couple of my general recommendations:

  • Do not use Pins 12 and 13 for the servos as recommended. When an Arduino is powered up or reset it hits pin 13 briefly. If you use Pin 13 for one of your servos the robot will move slightly when this happens. Instead use the other set of headers, which are wired to pins 10 & 11.
  • You might want to use servo.write() instead of servo.writeMicroseconds(). Most of the example Arduino servo code you (or your students) will find on the net uses servo.write(). Additionally if you add a standard servo to the robot later you will probably use this function as well.

I will be using servo.write() in this workshop. The servo motors on our robots have been modified to be continuous rotation servos. Wire your potentiometer (from the Arduino Kit) to your robot as shown:

Use the Servo example sketch we used earlier: File->Examples->Servo->Knob

Change the servo pin to one of the pins attached to our robot’s servos. Note how the wheel responds as you adjust the servo. For continuous rotation servos, 90° should cause the servo to stop, 0° is maximum speed in one direction and 180° is max speed in the other direction.

Be sure the robot’s servo motors are attached to pins 10 & 11 (or change the code) and try this:

#include <Servo.h>

Servo left;  // Creates an instance of Servo for the left motor
Servo right; // Creates an instance of Servo for the left motor

void setup() {
  right.attach(10); // attach right servo to pin 10
  left.attach(11);  // attach left servo to pin 11

  forward(1000);
  turnRight(900);
  forward(1000);
  turnLeft(900);
  stop();
}

void loop() {

}

void stop(){
  right.write(90);  // setting servos to 90 degrees
  left.write(90);   // stops them from turning
}

void forward(int driveTime){
  // Both just as far from 90 degrees means both motors
  // should be turning the same speed. Opposite directions
  // becuase motors are oriented in different directions.
  right.write(60);
  left.write(120);
  delay(driveTime);
}

void backwards(int driveTime){
  right.write(120);
  left.write(60);
  delay(driveTime);
}

void turnRight(int turnTime){
  right.write(90);
  left.write(120);
  delay(turnTime);
}

void turnLeft(int turnTime){
  right.write(60);
  left.write(90);
  delay(turnTime);
}

void disableServos(){  
  right.detach(); // disconnect servos
  left.detach();
}

Challenge: Write code to navigate the course taped out on the floor.

Add simple sensors to your robot:
Flip to page 148 in the guide and add the Whiskers to your robot.

The Whiskers act as push buttons. In their current configuration they will read as HIGH when the whisker is not touching anything. When the whisker is pushed back into the headers, this will “close” the button and the digitalRead() will return LOW.

Here’s some quick code I put together to read the whiskers:

#include <Servo.h>

Servo left;  // Creates an instance of Servo for the left motor
Servo right; // Creates an instance of Servo for the left motor

bool rightWhisker;
bool leftWhisker;

void setup() {
  pinMode(7, INPUT);
  pinMode(5, INPUT);

  
  right.attach(10);
  left.attach(11);

}

void loop() {
  
  forward(10);
  
  rightWhisker = digitalRead(7);
  leftWhisker = digitalRead(5);
  
  if(rightWhisker == LOW){
    backwards(500);
    turnLeft(900);
  }else if(leftWhisker == LOW){
    backwards(500);
    turnRight(900);
  }
}

void halt(){
  right.write(90);  // setting servos to 90 degrees
  left.write(90);   // stops them from turning
}

void forward(int driveTime){
  right.write(60);
  left.write(120);
  delay(driveTime);
}

void backwards(int driveTime){
  right.write(120);
  left.write(60);
  delay(driveTime);
}

void turnRight(int turnTime){
  right.write(90);
  left.write(120);
  delay(turnTime);
}

void turnLeft(int turnTime){
  right.write(60);
  left.write(90);
  delay(turnTime);
}

It could probably use some additional tweaking and maybe an extra function or two to make it work better. This one will get stuck in a corner pretty easily. Can you change the code to keep that from happening?

Where Steve Buys stuff:

Mercy Tech Talk Presentation – 3D Printing in Education

3D Printing in Education (Mercy 2017)

Curious about 3D printing? We will walk through the basics of 3D printing and introduce simple programs for creating 3D models suitable for printing. No previous 3D modeling experience is needed. We will also look at how existing lessons can be enhanced by a dash of 3D printing.

My Presentation PDF

Software I use for 3D Design:
Projects:
My Physics Models:

AAPT Summer 2017 – PIRA Session on 3D Printing

3D Printing Allows for the Investigation of Real World Problems

Physics is one area that should be immune to the sentiment of, “When am I going to use this?” Yet I’ve heard this voiced in my class and to be fair I doubt many of my former students have ever needed to determine the flight time of a projectile launched in a vacuum or the speed of a hoop rolling down a ramp in their careers. 3D printing gives you the opportunity to either create or help your students create equipment to address engaging problems that go beyond the textbook. These problems might be the subject of national news or maybe just viral videos. In this presentation, I will share projects done by and with my students that benefited from the inclusion of 3D printing.

My Presentation as a PDF

Software I use for 3D Design:
Projects:
My Physics Models:

 

Tinkercad – More useful than you might think

For years my goto CAD solution for designing parts to be 3D printed has been Tinkercad. It really is the fastest way to get students designing their own 3D parts. The basics of Tinkercad can be taught with less than five minutes of instruction. Best of all, it is totally free and you don’t need admin rights to install any software..

The basic idea is that you create objects by combining primitives and then using other primitives to create holes or take away materials. The other thing to know is that once a shape has been added you can stretch or squish it in the x, y, or z dimension or rotate it around the x, y, or z axis.

Using this very simple paradigm you really can create some very complex objects. Creation of these objects often involves a lot of critical thinking and problem solving for students to figure out the best way to get to their desired final part.

Below is my take on the Spill-Not. A similar product is sold by science suppliers as the Greek Waiter’s Tray. This was created totally in Tinkercad in less than ten minutes. You can find my version on the Thingiverse.

Centripetal Motion Demonstrator

You can easily modify my version to suit what ever cup you might have. It currently will accommodate a standard coffee cup. To play with my design goto: https://tinkercad.com/things/i02pOyl5X81 and click on “Tinker this” (you must be signed in to Tinkercad first). Then click on Ungroup to reveal the underlying shapes. You might need to do this multiple times to see all the shapes. The order in which you group things has a huge effect on your final design.

The Centripetal Force Demonstrator was created from:
    • A “Cylinder” (orange) as the base with a squished “Torus thin” (red) to make a lip to keep something from sliding off.
    • A “Torus” (green) to swing it by. This was placed above the center of the base floating in space. It is important that this be centered above the base at the desired height. Then group it with the base so it will stay centered.
    • A “Torus Thin” (blue) was stretched and then rotated slightly to attach the base to the ring. “Box” holes were used to remove the un-needed bits.
    • A stretched “Half Sphere” was tacked on to the flat surface of the half torus in order to make the ring attachment more attractive. This is can’t be seen in the picture below.

Image showing the sales necessary to use in Tinkercad to create the Centripetal Force Demonstrator

TPACK and 3D Printing

Over the last several months I’ve been spending a lot of time thinking about 3D printing and learning. This was spurred on by the #MakerEDChallenge2 on the Thingiverse. The basic goal was to either create new designs that could be used as projects in an educational setting or to re-purpose old designs. In either case you were supposed to include a lesson description that goes with your thing.

Some of my entries were brand new things, but many were not. I realized that almost all of the things I’ve posted to the Thingiverse were created for some educational purpose. Many of these were for student centered labs or projects. However, I’ve only done a couple projects where I’ve had students designing and printing their own things (Wind Turbines, Phone Holder). So I thought about how I could turn some of my other designs into student centered 3D design projects and got a couple more entries together (Solve a Problem, Create a Device to Teach Physics).

Then I had a realization. Not all projects that involve a 3D printer need to be 3D printing projects. This revelation reminded me of TPACK.

Reproduced by permission of the publisher, © 2012 by tpack.org
Reproduced by permission of the publisher, © 2012 by tpack.org

TPACK is Technological, Pedagogical, and Content Knowledge. One of the main take aways is that we, in education, often look for ways to “Integrate Technology” into the curriculum. At best, this is sloppy thinking. At worst it can lead to lower outcomes. TPACK offers a different way of thinking.

Some of my education professors often said things like, “Content is King,” and, “Good teaching is good teaching. What works well in one area will work in any content area.” I believe thinking this way is just as sloppy as, “Integrate Technology.”

For me, TPACK starts with the idea of Pedagogical Content Knowledge. The idea behind PCK is that it is important to know the best techniques to use to teach your particular content. Basically, different ways of teaching will be better suited for different types of content. This seems obvious, but we often seem to forget it.

Specific pedagogies work better for specific content. I wouldn’t, for example, teach my electronics class the same way I teach physics. The content has some overlap, but all in all it is different enough that my entire approach needs to be different in each course in order to be maximally effective.

When we toss in the “T”, we’re saying the technology tools we have available give us new ways of teaching that simply weren’t available before. So rather than integrating technology for the sake of technology ask, “How does having a 3D printer in my room allow me to enhance old lessons or create new ones that would not have been possible before?”

With a 3D printer in my room, I as the teacher can create things that make it easier for students to ask and investigate questions that would have been:
My printer also gives me the ability to do projects with my students that let them:

Never ask the question, “How can I incorporate a 3D printer into my curriculum?” Instead you should think about, “What is possible now that a 3D pinter is in my classroom?” The distinction is subtle, but it is also powerful.

Fidget Spinners and the 3D Printed Rotational Motion Apparatus

Many years ago I saw a really cool apparatus invented by Steve Rea, a local physics teacher, for experimenting with concepts of rotational motion. It was a simple system of stacked pulleys of decreasing diameters. Metal rods with weights allowed the moment of inertia to be easily varied. The device was elegant in its simplicity and offered the opportunity for incredibly rich investigations and discussions.

As it turns out, Steve’s brother owns Arbor Scientific. Arbor adopted Steve’s design and they now sell it. Arbor’s Rotational Inertia Demonstrator works amazingly well and is very repeatable. I highly recommend it. At $160 cost really is quite reasonable for such a well built piece of lab equipment.

When I saw it for the first time I wondered aloud if I might be able to 3D print one. Steve told me I would have difficulty reproducing it because it was nearly impossible to find bearings that lacked grease. Grease is added to bearings to protect the metal bits from corrosion and increase the life of the bearing in high load/high speed operation. The viscosity of the grease in most bearings is too high for this sort of application. It would not allow for a good transfer of gravitational energy to rotational energy. Steve told me the hardest part of creating his prototype was finding suitable bearings. At the time I wasn’t interested enough to try to source acceptable bearings so I let the idea lay fallow.

Then, last year, the fidget spinner craze happened. Several months ago I was having a conversation about 3D printing with Andy Mann. He told me how his son designs and prints his own fidget spinners. Andy also related how his son is so into this he found a YouTube video showing him how to degrease his bearings to make them spin longer.

It took a day for the light bulb to turn on.  Two days after that I had a set of bearings from Amazon (I love Prime) and my prototype of a 3D printed fidget spinner. I started with this to make sure the degreasing worked and that I had dialed in the perfect size to hold the bearing.

With that done I knocked out a quick prototype, which failed utterly. Two versions later and I had it done. You can find my design on the Thingiverse and if you’re interested you can tweak it however you’d like in Tinkercad.

There are three different pulleys to provide different amounts of torque. With an extra set of hex nuts the washers can be positioned different distances from the center of rotation changing the moment of inertia. There are a lot of experiments that students can do to investigate rotational motion and the transfer of energy.

Rotation Demonstrator Side View

Diameters of the three pulleys:
    • 24.5 mm
    • 49 mm
    • 73.5 mm
Parts List: (about $10 in parts/device)
    • 2 each Skateboard Bearings, 608ZZ 8x22x7
    • 4 each 6″ long 1/4″ bolts
    • 12 each 1/4″ hex nuts
    • 40 each Fender washers, 1/4″ hole 1.25″ diameter (the number of fender washers can be varied)

Detail showing assembly

As I mentioned above, the bearings need to be de-greased first. The grease protects the bearings from water and road grit, but it will keep the bearings from spinning freely. I used acetone since we had it in the chemistry supplies. I just dropped them in a small beaker for 20-30 minutes. I found I also had to take them out of the acetone and spin them a couple of times then drop them back in. A lot of the instructions on the net direct you to remove the metal shields. I’ve found you don’t need to do this. However, if you get “sealed” bearings you will need to remove the seals. You need two bearings, one in each end, for full support.

If you want to avoid using acetone do a little googeling for other ways to de-grease bearings. There’s lots of stuff related to fidget spinners kicking around right now.

Square One Autonomous Innovative Vehicle Design Competition

Square One Education Network hosts a number of events every year. These include high quality Professional Development as well as student competitions. For the last three years our students have been competing in their Autonomous Innovative Vehicle Design Competition. The goal is to turn a Power Wheels Jeep into an autonomous vehicle. For this competition Square One provides the Jeep and also gives teams money to buy parts and supplies.

I’ll be documenting some of what my students have done this year here in this post. I’ll be updating this post with pictures, more details on parts, and all of the code (that will likely be after the competition)

Parts and Sources:

Things to Know/What we used these parts for:

You need some sort of a motor controller to allow your Arduino to regulate the current from the battery to the drive motors. We’ve used the Monster Moto Shield from SparkFun every year and it works like a champ. This will let you run the motors forward/backwards and give you a measure of speed control. You’ll need to solder on header pins and screw terminals, so be sure to order those at the same time. One weird thing we just discovered. We ran into a motor control problem last night that could only be solved by disconnecting an ultrasonic sensor from pin A0.  So, we’re avoiding pin A0 altogether for now.

The wheel encoders we found didn’t fit at all. The hole was too small, so students used a soldering iron to melt the rubber bushing to enlarge the hole. They then used a little superglue to affix the encoders to the really short shaft sticking out of the motors. Maybe next year we’ll be able to find some encoders that actually fit, but these seem to work for now.


The steering servo works well. If you buy one from ServoCity they offer to assemble the servo for an additional $30. I highly recommend you take them up on this. It’s not just putting the gear box together. It includes taking apart the servo itself and doing some modifications involving soldering and cutting a bit off a gear. I’ve bought two of these over the three years. This year we paid the $30. Totally worth it!


Our code is still being written. It will all end up in this Google Drive Folder when we’re done.

Playing with Programming

I’m teaching AP Computer Science Principles this year following along with the CS50 AP from Harvard. I like it, but this curriculum is way too heavy on the coding end to really match the intent of APCSP.

My plan next year is to mix and match Code.org’s material with ideas from CS50, but instead of C we’ll use JavaScript. With this in mind I’ve been playing with p5.js. I like it a lot for two very important reasons. First it gets students to graphics right away. It’s a lot easier to get student excited about code when they can create cool pictures on the screen than it is when all the do is print text.

The other thing I really like about JavaScript is students can run their code on pretty much any device with a modern web browser. As an example, check out the sketch below. I created after watching a cool video by Dan Shiffman. I made this in Openprocessing, a cloud editor for p5.js. If you’re interested, Wikipedia has a great explanation of the math involved in my program.

Paper Circuits

I’ve been teaching a semester long electronics class every semester since I started teaching in 2000. It started as a basic circuits course, but several years ago I started teaching it with the Arduino micro-controller platform. It has undergone several transformations over the years and I’m changing it yet again this semester.

We’re starting with some basic circuit fundamentals. In the past I assumed they would learn these fundamentals as we worked with Arduino. It turns out I was wrong. One of the circuit building things we did this week involved making paper circuits. This worked out really well and gave students a chance to discover differences between series and parallel circuits. They also got to do some trouble shooting to figure out closed, open, and short circuits.

All in all it was a fun project to help set the tone for the semester while also giving us an activity we can refer back to as we move forward.

Parallel Paper Circuit

Recommended resources:

Conductivity Meter for Chemistry Class

We have a new chemistry teacher this year. At his old school he used these conductivity meters from Flinn Scientific. He said they work really well. He had students use them to make qualitative comparisons of the conductivity of different solutions. The only problem I saw was their price tag. They are $22 ea. This is not horrible, but there really isn’t much to them. So I decided to see if I could make them cheaper.

Turns out it was pretty easy to source the components to place the cost at no more than $1.50 ea. So, for the price of one of Flinn’s meters I can make a classroom set.

I created a set of instructions for making your own:  Conductivity Meter Tutorial (PDF)

I used Plasq’s ComicLife to create this. I’d forgotten how much I enjoy using this for making tutorials.

Parts: