Friday, December 12, 2014

ETEC 597: Course Retrospective



Final Course Retrospective
 
What was the build that you are most proud of and why?

The build that I am most proud of is the musical circuit that plays Jingle Bells.  That build took the most research to successfully complete and I was able to involve my students and family.  I was impressed by the resemblance to the actual tune of Jingle Bells.

Go back to your first week and read each week’s submission with an eye for personal growth. Where were you when you started and where did you end up?

I gained an appreciation for hardware programmers after taking this course.  My skills as a CS teacher and developer were pushed beyond what I was accustomed to doing.  After the last project, I discovered that I had a yearning for more projects.  I am hoping to be able to pick up on Arduino development as a hobby.

What did you learn that you didn’t know before?

I was aware of some C++ syntax before the course but I didn’t know exactly how the programs were implements (especially how OOP came into play with C++.)  I learned how to write functions with C++ and my previous Java knowledge enabled me to make the connection on how to call those programs in the main loop.

How did you actually come to learn this new knowledge?

I learned this knowledge by building on my previous programming knowledge and learning through the Arduino reference site and tutorials.

What did you learn about yourself?

I learned that I enjoy experiential learning more than following prescribed instructions.  I have always felt that I did not really think outside of the box but this course made me more astute to the fact that I enjoy a challenge.  I feel better about challenging  my students more now that I have been challenged myself.

Look at your words for each week and see how they might read if one of your students turned in that submission. What were you telling yourself about yourself?

I feel that I was a little brief in some of my responses although I completed the challenges.  I am sure that this was because of my busy schedule and having so much on my plate.  I now feel the way that most of my seniors do at any point during the week; having a lot to do doesn’t excuse me from having to do the work, though.

Where did you say your challenges where?

My biggest challenge was managing my time effectively.  Having 6 preps, graduate school, and a 2-year old at home causes some serious issues when trying to find the time to test and build a circuit.

Did these challenges change over the time of the class?

The main challenge did not change but my ability to adjust did.  I started setting aside some time at the end of each school day to work on Arduino projects and the students that I had in my room for extra help or Computer Science club began to get into the testing process as well.

As you entered the world of the maker, what do you see as your next adventure in the world of making? Is it to expand your abilities to work with microprocessor and move from prototype to the production of something fun and useful? Is it to see what you can learn about the world of 3D design and printing? Is it to see what aspects of making can be used with the younger children? It is to see what you need to do to bring your vision of a maker space to life in the real world? It can be anything.

My next adventure is going to be to actually implement the maker space into my school.  Given the technology support that my district gives, it will be a process where I will have to do the majority of the leg work.  This course gave me the background knowledge to rationalize the maker space and a couple of my colleagues have agreed to help me with this process.

What are your next steps?

My next steps will be to start the Education Foundation grant process for my maker space and keep tinkering with the Arduino.  I plan on purchasing several kits for my Engineering Design and Computer Programming classes to use in the spring.

Sunday, December 7, 2014

ETEC 597: Maker Movement - Week 6

We made it!  After several weeks of tinkering and making, we are finally in the home stretch.  I, for one, have enjoyed working on these projects and coming up with solutions to each week's Maker Challenge.  This week's challenge was a culmination of outputs and inputs with our circuit having to consist of an electric motor connected to a sensor.  I chose to work with the light sensor rather than the thermal sensor because it is easier to make fast changes to light intensity when testing than making fast changes in temperature.  This decision worked out well once I was able to adjust the code and make the motor respond to changes in the photo resistor instantaneously.  The first code that I am posting is the original code for the motor control; the second set of code is the working copy of the code with the photo resistor.

Code
// Motor Controller Code

const int motorPin = 9;

void setup()
{
  // Set up the motor pin to be an output:

  pinMode(motorPin, OUTPUT);

  // Set up the serial port:

  Serial.begin(9600);
}


void loop()
{

  // motorOnThenOff();
  // motorOnThenOffWithSpeed();
  // motorAcceleration();
  // serialSpeed();
}


void motorOnThenOff()
{
  int onTime = 3000;  // milliseconds to turn the motor on
  int offTime = 3000; // milliseconds to turn the motor off
  
  digitalWrite(motorPin, HIGH); // turn the motor on (full speed)
  delay(onTime);                // delay for onTime milliseconds
  digitalWrite(motorPin, LOW);  // turn the motor off
  delay(offTime);               // delay for offTime milliseconds
}

void motorOnThenOffWithSpeed()
{
  int Speed1 = 200;  // between 0 (stopped) and 255 (full speed)
  int Time1 = 3000;  // milliseconds for speed 1
  
  int Speed2 = 50;   // between 0 (stopped) and 255 (full speed)
  int Time2 = 3000;  // milliseconds to turn the motor off
  
  analogWrite(motorPin, Speed1);  // turns the motor On
  delay(Time1);                   // delay for onTime milliseconds
  analogWrite(motorPin, Speed2);  // turns the motor Off
  delay(Time2);                   // delay for offTime milliseconds
}

void motorAcceleration()
{
  int speed;
  int delayTime = 20; // milliseconds between each speed step
  
  // accelerate the motor

  for(speed = 0; speed <= 255; speed++)
  {
    analogWrite(motorPin,speed); // set the new speed
    delay(delayTime);           // delay between speed steps
  }
  
  // decelerate the motor

  for(speed = 255; speed >= 0; speed--)
  {
    analogWrite(motorPin,speed); // set the new speed
    delay(delayTime);           // delay between speed steps
  }
}

void serialSpeed()
{
  int speed;
  
  Serial.println("Type a speed (0-255) into the box above,");
  Serial.println("then click [send] or press [return]");
  Serial.println();  // Print a blank line

  // In order to type out the above message only once,
  // we'll run the rest of this function in an infinite loop:

  while(true)  // "true" is always true, so this will loop forever.
  {
    // First we check to see if incoming data is available:
  
    while (Serial.available() > 0)
    {
      // If it is, we'll use parseInt() to pull out any numbers:
      
      speed = Serial.parseInt();
  
      // Because analogWrite() only works with numbers from
      // 0 to 255, we'll be sure the input is in that range:
  
      speed = constrain(speed, 0, 255);
      
      // We'll print out a message to let you know that the
      // number was received:
      
      Serial.print("Setting speed to ");
      Serial.println(speed);
  
      // And finally, we'll set the speed of the motor!
      
      analogWrite(motorPin, speed);
    }
  }
}

Picture of the Circuit without the Photo Resistor















Code with the Photo Resistor
// Motor Controller Code

const int sensorPin = 0;

const int motorPin = 9;

int lightLevel, high = 0, low = 1023;

void setup()
{
  // Set up the motor pin to be an output:

  pinMode(motorPin, OUTPUT);

  // Set up the serial port:

  Serial.begin(9600);
}


void loop()
{
  int lightSensor = analogRead(sensorPin/4);
  
  // motorOnThenOff();
  // motorOnThenOffWithSpeed();
  // motorAcceleration();
  // serialSpeed();
  motorSpeedwithLight();
}


void motorOnThenOff()
{
  int onTime = 3000;  // milliseconds to turn the motor on
  int offTime = 3000; // milliseconds to turn the motor off
  
  digitalWrite(motorPin, HIGH); // turn the motor on (full speed)
  delay(onTime);                // delay for onTime milliseconds
  digitalWrite(motorPin, LOW);  // turn the motor off
  delay(offTime);               // delay for offTime milliseconds
}

void motorOnThenOffWithSpeed()
{
  int Speed1 = 200;  // between 0 (stopped) and 255 (full speed)
  int Time1 = 3000;  // milliseconds for speed 1
  
  int Speed2 = 50;   // between 0 (stopped) and 255 (full speed)
  int Time2 = 3000;  // milliseconds to turn the motor off
  
  analogWrite(motorPin, Speed1);  // turns the motor On
  delay(Time1);                   // delay for onTime milliseconds
  analogWrite(motorPin, Speed2);  // turns the motor Off
  delay(Time2);                   // delay for offTime milliseconds
}

void motorAcceleration()
{
  int speed;
  int delayTime = 20; // milliseconds between each speed step
  
  // accelerate the motor

  for(speed = 0; speed <= 255; speed++)
  {
    analogWrite(motorPin,speed); // set the new speed
    delay(delayTime);           // delay between speed steps
  }
  
  // decelerate the motor

  for(speed = 255; speed >= 0; speed--)
  {
    analogWrite(motorPin,speed); // set the new speed
    delay(delayTime);           // delay between speed steps
  }
}

void motorSpeedwithLight()
{
  int speed;
  int lightSensor = analogRead(sensorPin);
  
    while(true)
    {
    speed = lightSensor/4; //Limits motor speed to 255
    analogWrite(motorPin, speed);
   }
}

Picture of the Circuit with the Photo Resistor



















Schematic Diagram



















Video of Working Circuit


Extension
Photo resistors are used in many devices around our homes and workplaces.  I recently installed a set of motion-sensitive security lights and the photo resistor made me think of those devices.  The photo resistors in the security light respond to changes in the amount of light that they detect; if this change is too drastic, then they send a signal to the controller to switch on the lights.

Although the photo resistor in a security light isn't directly related to the electric motor in this circuit, there are some similar analogues in our world.  Backup sensors on our can work by detecting distance or work by detecting light; those that detect light and stop the car are working in a similar way to the one in my circuit.  The photo resistor and motor circuit could also be used for automatic blinds in your house; if the sun is beaming too brightly, the motor can automatically lower the blinds in your window.

Monday, December 1, 2014

ETEC 597: Maker Movement - Week 5

This week's build allowed me to get my family involved in the process.  Typically, my wife walks in the office, sees me working on the electronics "thingy," turns around, and leaves.  With the addition of the piezo speaker, though, she could actually get some sensory feedback (besides flashy lights) that she could connect to electronics in her life.

It was enjoyable playing around with the code and making the piezo speaker play certain notes and tones.  I am not (nor have I ever been) a music person, so I enlisted the help of some of my band students to help me extrapolate some music to have my speaker output.  I ultimately decided on a Christmas classic, Jingle Bells, as the tune for my Arduino.  The addition of the push button was a little more challenging but definitely doable since we started working with control structures in the programming language.

Code

const int buttonPin = 2;     // pushbutton
const int ledPin =  13;      // on-board LED
const int buzzerPin = 12;    // buzzer

const int songLength = 18;
char notes[] = "cdfda ag cdfdg gf "; // a space represents a rest
int beats[] = {1,1,1,1,1,1,4,4,2,1,1,1,1,1,1,4,4,2};
int tempo = 100;

int buttonState = 0;         // variable for reading the pushbutton status

void setup() {

  pinMode(ledPin, OUTPUT); 
  pinMode(buzzerPin, OUTPUT);  

  pinMode(buttonPin, INPUT);    
}

void loop(){

  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH) {    
    digitalWrite(ledPin, HIGH);

    int i, duration;
  
    for (i = 0; i < songLength; i++) // step through the song arrays
    {
        duration = beats[i] * tempo;  // length of note/rest in ms
        if (notes[i] == ' ')          // is this a rest? 
        {
           delay(duration);            // then pause for a moment
        }
        else                          // otherwise, play the note
        {
           tone(buzzerPin, frequency(notes[i]), duration);
           delay(duration);            // wait for tone to finish
        }
        delay(tempo/10);              // brief pause between notes
     }
  
     // We only want to play the song once, so we'll pause forever:
     while(true){}

  }   
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
    noTone(12);
  }
}

int frequency(char note) 
{
  // This function takes a note character (a-g), and returns the
  // corresponding frequency in Hz for the tone() function.
  
  int i;
  const int numNotes = 8;  // number of notes we're storing
  
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523};
  
  // Now we'll search through the letters in the array, and if
  // we find it, we'll return the frequency for that note.
  
  for (i = 0; i < numNotes; i++)  // Step through the notes
  {
    if (names[i] == note)         // Is this the one?
    {
      return(frequencies[i]);     // Yes! Return the frequency
    }
  }
  return(0);  // We looked through everything and didn't find it,
              // but we still need to return a value, so return 0.

}

Code Snippet of Song Change

The notes and beats arrays were the biggest changes when going from the original song to Jingle Bells.

const int songLength = 26;
char notes[] = "eeeeeeegcde fffffeeeeddedg";     //Jingle Bells
int beats[] = {1,1,2,1,1,2,1,1,1,1,4,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2};

int tempo = 300;

Circuit Picture



Circuit Schematics


Sorry for the orientation; I could not get this particular picture to flip.

Videos


Original Tune


Jingle Bells

Extension

I remember my fascination with computer-generated sounds from the time that I started with my first computer (a Tandy RL-1000 at a whopping 8MHz!)  I didn't know exactly how they worked but I was very curious and spent hours upon hours playing around with the MIDI editor that I had installed.  Although sounds are now much more complex (with many more channels and higher bit rates,) the principle is the same.  Sounds are composed of bits of data that control the vibrations of the speaker.  I would like to try this same experiment in the future with a full-size speaker rather than the piezo to see if the vibrations of the speaker can be seen.