< < back home

week 11 - output devices


-individual assignment: add an output device to a microcontroller board you've designed and program it to do something
-group assignment: measure the power consumption of an output device



This week I chose the speaker as an output, since I will use it for my final project. I redesigned Neil's board in Eagle and generated the traces and outline PNG (also added a little personal touch on the traces)

Then generated the milling strategy in FabModules,milled the board with the Roland SRM-20 and soldered all the components (ok I admit it was not my best soldering)

Time to program the board. However, even though I am using the speaker, I'm not so interested in the sound but the movement of the speaker. This movement is what I will use in my final project to push out the smoke in the shape of smoke rings. After trying different arduino examples online, I found a very simple code for generating the movement:


  #include < SoftwareSerial.h >
int speakerPin = 1;

SoftwareSerial myTotem(0, 2); // RX, TX

char val;

void setup() {
  pinMode(speakerPin, OUTPUT);
  myTotem.begin(9600);
  myTotem.println("Hello, world?");
}

void loop() {
  if (myTotem.available())
  {
    val = myTotem.read();

    if (val == '1')
    {
      analogWrite(speakerPin, 255);  // S
      delay(20);
      analogWrite(speakerPin, 0);
      delay(20);
    }


  }
}

This code however generates the same movement strenght when the speaker moves up as when the speaker moves down. My idea was to get one beat for each smoke signal, which means I only want to hear the sound when the speaker goes up. In other words, right now this would be the movement of the speaker:

And this is what it should be, so the speaker goes up fast but it goes down slowly:

Thanks to Guillem, we managed to make it work with this code:


  int speakerPin = 1;

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

  void loop() {

    // fade in from min to max in increments of 5 points:
    for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 25) {
      // sets the value (range from 0 to 255):
      analogWrite(speakerPin, fadeValue);
      // wait for 30 milliseconds to see the dimming effect
      delayMicroseconds(30);
    }



     delayMicroseconds(50);


    // fade out from max to min in increments of 5 points:
    for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
      // sets the value (range from 0 to 255):
      analogWrite(speakerPin, fadeValue);
      // wait for 30 milliseconds to see the dimming effect
      delayMicroseconds(10);
    }

And here are the first tests with the speaker generating smoke rings!



download files


Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.