Egg hunt finder on an Arduino Uno
A hot and cold finder for glowing eggs hidden in a dim room: a light sensor measures the change, five WS2812B LEDs warm from blue to red and a piezo beeps faster as you get close. The whole build, an Arduino Uno and 4 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner Runs in your browser. Free, and no account needed.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Egg hunt finder: a hot and cold beeper for an egg hunt in a dim room. Each
// hidden egg has a small light inside, and the finder beeps faster and glows
// warmer the closer you point it to one.
//
// light sensor module AO -> A0, VCC -> 5 V, GND -> GND (in a short tube)
// piezo pin 8 -> piezo -> GND
// meter 5 WS2812B LEDs, DIN <- 330 ohms <- pin 6
//
// The eggs are plastic eggs with a coin-cell LED tea light inside, hidden
// around a room with the curtains drawn. Put the light sensor at the end of a
// short cardboard tube, so it sees where it points and not the whole room.
//
// When it starts, the finder reads the room for two seconds and keeps that as
// "cold". The module's reading drops as the light grows, so the further the
// reading falls below the room's, the closer the egg. The meter goes from one
// blue LED (cold) through green and yellow to five red ones (hot!), and the
// beeps come faster as it warms, until it sings one steady note.
//
// It works in daylight too, pointed at a bright window, which makes it a fun
// way to show how a light sensor sees the room.
//
// Things to try. Drag the light sensor's slider up toward an egg. Turn the
// room darker first, then start: the finder only measures the change.
#include <Adafruit_NeoPixel.h>
const int PIEZO_PIN = 8;
const int LEDS = 5;
Adafruit_NeoPixel meter(LEDS, 6, NEO_GRB + NEO_KHZ800);
const uint32_t WARMTH[LEDS] = {0x0040FF, 0x00C080, 0xC0C000, 0xFF6000, 0xFF0000};
const char *WORDS[LEDS + 1] = {"Cold", "Cool", "Warm", "Warmer", "Hot", "Hot! You found it!"};
int room = 0;
int lastLevel = -1;
unsigned long nextBeep = 0;
void setup() {
Serial.begin(9600);
meter.begin();
meter.setBrightness(120);
long sum = 0;
for (int i = 0; i < 20; i++) {
sum += analogRead(A0);
delay(100);
}
room = sum / 20;
Serial.print("Egg finder ready. The room reads ");
Serial.println(room);
}
void loop() {
int closer = room - analogRead(A0); // brighter light reads lower
int level = constrain(closer / 60, 0, LEDS);
meter.clear();
for (int i = 0; i < (level == 0 ? 1 : level); i++) meter.setPixelColor(i, WARMTH[level == 0 ? 0 : level - 1]);
meter.show();
if (level != lastLevel) {
lastLevel = level;
Serial.println(WORDS[level]);
}
unsigned long now = millis();
if (level == LEDS) {
tone(PIEZO_PIN, 1568); // found it: one steady note
} else if (now >= nextBeep) {
// From a beep every second when cold to five a second when warm.
tone(PIEZO_PIN, 880 + level * 150, 40);
nextBeep = now + 1000 - level * 180;
}
delay(20);
}
Parts list
6 parts, plus the jumper wires. Every one is in the editor's parts bin.
How it is wired
6 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Arduino Uno R3 pin 8; Piezo speaker pin 1
- Arduino Uno R3 pin 6; Resistor, 330 Ω pin 1
- Arduino Uno R3 pin 5V; Photoresistor sensor module pin VCC; Addressable RGB LEDs pin VDD
- Ground: Arduino Uno R3 pin GND; Photoresistor sensor module pin GND; Addressable RGB LEDs pin VSS; Piezo speaker pin 2
- Arduino Uno R3 pin A0; Photoresistor sensor module pin AO
- Resistor, 330 Ω pin 2; Addressable RGB LEDs pin DIN
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.