Teaching with Arduino

arduino

I’ve decided to use the Arduino in my electronics class this fall. The Arduino is an “open-source electronics prototyping platform based on flexible, easy-to-use hardware and software.” Even from the description it sounds like just what an electronics course needs. I finally had some time to tinker with it today, and after a few minutes I had it’s LED blinking away, and then after another few minutes it was an oscilloscope. A few minutes later it was playing a pulse-width-modulated (PWM) melody. Not bad for an hour’s work.

With a little inspiration, and my new-found confidence, I took to my first project in hopes of having a little demo to show the intro students to recruit them for my class in the fall. An hour and a half later (including fielding questions about homework and our exam tomorrow) I had a photo-resistor theramin up and running. The basic idea is to use a photoresistor as half of a voltage divider and tell the Arduino to read the voltage and output a PWM tone whose frequency depends on the voltage. This way the pitch can be controlled by blocking or unblocking the light at the photoresistor.

int speakerOut = 9;

void setup() {
  pinMode(speakerOut, OUTPUT);
}

int tone = 0;
long input = 0;
int maximum = 500;
int minimum = 400;
float range = 100;

void loop() {
    input = analogRead(0);
    if (input > maximum) maximum = input;
    if (input < minimum) minimum = input;
    range = maximum-minimum;
    tone = 9090*float(1-float((input-minimum)/range));
    //tone is the period, so large means high frequency.
    // when using analogRead, this means a high voltage gives a low sound.

    digitalWrite(speakerOut,HIGH);
    delayMicroseconds(tone / 2);

    // DOWN
    digitalWrite(speakerOut, LOW);
    delayMicroseconds(tone / 2);
}

Enjoy!

About these ads

4 thoughts on “Teaching with Arduino

    • This group of students are in college and taking an introductory electronics class. I think the large arduino would be cool, especially if there was a way to make everything larger. My four year old son doesn’t have trouble plugging wires into the breadboard, but I do have trouble explaining where to put them. I can see how it may help to have a blown-up version to point at when you describe things.

      Reply
  1. Pingback: Arduino for Quantum Optics, Anyone? « QuantumBlah

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s