makernestOrigins · all chapters

Origins · Chapter 03 · Act

The Noisemaker

Loud enough that somebody does something.

Sketch 03 The Noisemaker

Copy it, open File, New Sketch, select everything in the new window and paste over it. Check Tools, Board says Arduino Uno and Tools, Port shows your board, then press Upload.

Download .ino
// 03 The Noisemaker
// The Maker's Book of Origins, chapter 03. Upload it, then turn back to the book.
// makernest.com/origins/03
// MakerNest Origins is a brand of Innointel Global Private Limited.

#include <MakerNestOrigins.h>

void setup() {
  machine.begin(3, "03|NOISE-|MAKER");
  machine.homeShows(SHOW_A | SHOW_LINE);
  machine.useScreen(SCR_NORMAL_COLOUR);      // the first screen
  machine.useScreen(SCR_WHEN_COLD);          // the second screen: RING, BUZZER, BOTH or ALWAYS
  machine.useScreen(SCR_COLD_LINE);
  machine.useScreen(SCR_TEST);
}

void loop() {
  machine.update();
  bool cold = machine.settings.coldLine != NOT_SET && machine.temperatureA() < machine.settings.coldLine;
  uint8_t w = machine.settings.whenCold;

  if (cold && (w == WHEN_RING || w == WHEN_BOTH)) machine.ring(RED); else machine.ringNormal();
  if (w == WHEN_ALWAYS) machine.buzzer(true);                  // ALWAYS: the sensor is still there. It has stopped asking.
  else { machine.buzzer(false); machine.buzzerBeep(cold && (w == WHEN_BUZZER || w == WHEN_BOTH)); }
}

Your settings and your notebook stay saved on the board when you upload.

Wiring

Red is power, black is the way back, and every signal has its own colour. On the shield, black goes to G, red to V, the signal to S. Every time.

New this chapter

BUZZERUNDER THE BASE−+SROW 6GVSTHE SHIELD2345678910111213A4A5USEDTODAY

The whole shield, by the end of the book

GVSROW 2SENSOR AROW 3DIALROW 4DIALROW 5DIALROW 6BUZZERROW 7SENSOR BROW 8DOOR SWITCHROW 9SWITCH BOARDROW 11LIGHT RINGA4DISPLAYA5DISPLAYPOWER 3V3DISPLAY

On the bench: Make a buzzer sing two notes

Your machine's buzzer can only beep. This one is passive: it makes whatever pitch the board sends it. A note is just a number of vibrations every second.

You need

Build it

  1. Find the S and − pins on the passive buzzer board. The middle pin is not used.
  2. Female-to-female jumpers straight from the shield, no breadboard: row 12 S to the buzzer's S, row 12 G to the buzzer's −.
  3. Upload bench sketch 03.
Download .ino
// MakerNest Origins · bench 03 · a buzzer that sings two notes
// A passive buzzer plays whatever pitch the board sends it.

const int BUZZER_PIN = 12;   // the buzzer's S pin is on row 12

const int NOTE_ONE = 523;    // C, in hertz: vibrations every second
const int NOTE_TWO = 659;    // E
const int LENGTH = 300;      // how long each note lasts, in milliseconds

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

void loop() {
  tone(BUZZER_PIN, NOTE_ONE, LENGTH);
  delay(LENGTH + 50);
  tone(BUZZER_PIN, NOTE_TWO, LENGTH);
  delay(LENGTH + 50);
  delay(2000);               // quiet for two seconds, then again
}
What you'll see

Two notes, then quiet, then again.

Break it on purpose

Move the S wire to the middle pin. Silence. The right part, the wrong pin.

Then try

Change NOTE_TWO to 784. Then try making the first three notes of a tune everyone at home knows.

How the bench works

Bench sketches replace your chapter sketch while you use them. Your settings and your notebook stay saved on the board. When you finish, upload the chapter's sketch again and your machine is back exactly as it was.

While a bench sketch runs, the display and the ring freeze on whatever they last showed. That is normal.

If the light ring is still lit from your chapter sketch, switch everything off and on again before you start. It goes dark and stops using power the bench needs.

The breadboard has 17 numbered columns and two halves, top and bottom. The five holes in one column of one half are joined underneath. Nothing joins across the gap in the middle.

Every jumper from the shield has a female end: push it onto a shield pin. The male end goes into the breadboard. G, V and S are the same three pins you have used all book: ground, power, signal.

Never put a wire straight from V to G. That is a short circuit.

Ask Milo

Stuck, curious, or something looks wrong? Tell me what you see.

You can paste your code or an error message here too.

← The TripwireThe Chatterbox →