makernestOrigins · all chapters

Origins · Chapter 02 · Decide

The Tripwire

Give it an opinion, and a way to show it.

Sketch 02 The Tripwire

This one is printed on page 22 of your book. Type it in yourself: copying it letter by letter is part of the chapter. If it won't upload, compare yours with this one, line by line.

Download .ino
// 02 The Tripwire
// The Maker's Book of Origins, chapter 02. Type it from page 22, or copy it from here.
// makernest.com/origins/02
// MakerNest Origins is a brand of Innointel Global Private Limited.

#include <MakerNestOrigins.h>
void setup() {
  machine.begin(2, "02|THE|TRIPWIRE");
  machine.homeShows(SHOW_A | SHOW_LINE);
  machine.useScreen(SCR_COLD_LINE);
  machine.useScreen(SCR_NORMAL_COLOUR);
  if (machine.settings.coldLine == NOT_SET)
    machine.edit(SCR_COLD_LINE);
}
void loop() {
  machine.update();
  if (machine.temperatureA() < machine.settings.coldLine)
    machine.ring(RED);
  else
    machine.ringNormal();
}

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

LIGHT RINGUNDER THE BASEGND5VDI330 ΩROW 11GVSTHE SHIELD2345678910111213A4A5USEDTODAY

New this chapter

DIALUNDER THE BASEGND+SWDTCLKROW 3GVSROW 4SROW 5STHE 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 an LED switch on below a number

A light sensor and a resistor share the power between them. More light, bigger number. The board compares the number with your line, exactly like the Tripwire.

You need

On the breadboard

TOPBOTTOMLDR10k+LED220A0 VA0 SA0 G12 S12 G1234567891011121314151617

Build it

  1. Put the light sensor in the top half, one leg in column 3 and the other in column 6.
  2. Put the 10 kΩ resistor from column 6 to column 10, top half.
  3. Put the LED in the top half: long leg in column 13, short leg in column 14.
  4. Put a 220 Ω resistor from column 14 to column 17, top half.
  5. Jumpers from the shield: A0 V to column 3, A0 S to column 6, A0 G to column 10.
  6. More jumpers: row 12 S to column 13, row 12 G to column 17.
  7. Upload bench sketch 02 and open Tools, Serial Monitor at 9600.
Download .ino
// MakerNest Origins · bench 02 · an LED that switches on below a number
// The light sensor on A0 gives a number. Below LINE, the LED on row 12 comes on.
// Open Tools, Serial Monitor (9600) to watch the number.

const int SENSOR_PIN = A0;   // light sensor and 10k resistor meet here
const int LED_PIN = 12;      // the LED's long leg is wired to row 12
const int LINE = 300;        // your number: below this, the LED comes on

void setup() {
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int light = analogRead(SENSOR_PIN);   // 0 is black dark, 1023 is very bright
  Serial.println(light);

  if (light < LINE) {
    digitalWrite(LED_PIN, HIGH);
  } else {
    digitalWrite(LED_PIN, LOW);
  }
  delay(500);
}
What you'll see

Cover the sensor with your hand. Watch the number fall in the Serial Monitor. When it goes under LINE, the LED comes on.

Break it on purpose

Pull the 10 kΩ out. The number sits near the top and hardly moves, and the LED never comes on. The sensor needs a partner to share the power with, or there is nothing to compare.

Then try

Change LINE to the number your room shows at dusk. Now it comes on when it gets dark.

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.

← First LightThe Noisemaker →