Give three LEDs a personality using a 120-year-old piece of mathematics, the same idea that, scaled up a few trillion times, powers modern AI. This one's on us: the complete GAMERIFT mission format, free.
Machines follow rules. But what if the rule is a roll of the dice? Today you build a robot with three moods, calm, curious, alarmed, that drifts between them unpredictably, yet with unmistakable personality. One robot might be chilled and hard to startle; another might be a nervous wreck. The difference is nine numbers you choose. Those nine numbers are called a Markov chain, and by the end of this mission you'll understand a real piece of the mathematics behind weather forecasts, Google's original search ranking, and the AI chatbots everyone's talking about.
Time: 50 minutes · Difficulty: 2/5 · You need to know: how to wire an LED and upload a sketch (covered in Beginner Kit Lessons 01–02, but the wiring table below is enough to follow along).
A Markov chain is a system that hops between states (our moods), where the chance of each next state depends only on the current one, not on the whole history. A calm robot doesn't care that it was alarmed an hour ago; only now decides next. Mathematician Andrey Markov worked this out around 1906, using the letters in a Russian poem. Today the same idea forecasts weather, models queues at the bank, and ranked the early web.
Nine numbers, arranged three-by-three: each row says "when I'm in this mood, here's my percentage chance of each mood next." Row CALM might read 70–25–5: mostly stays calm, sometimes gets curious, rarely panics. Change the numbers, change the character. Personality is just probabilities, that's the whole secret.
A modern language model answers one question, billions of times per sentence: "given where I am now, what's the probability of each thing that could come next?" That is a Markov chain's question, asked with vastly more states and a much longer memory. When your robot picks its next mood from a probability table, it is doing, in miniature, honestly, what the world's biggest AI systems do. You're not playing with a toy version of the idea. You're playing with the idea.
USB unplugged while you wire. Three LEDs, each with its resistor bodyguard, sharing one ground rail:
| From | To | Meaning |
|---|---|---|
| R3 GND | Blue (−) rail | Shared ground for all three |
| Pin 11 | Resistor → LED long leg | CALM (green if you have it) |
| Pin 12 | Resistor → LED long leg | CURIOUS (yellow) |
| Pin 13 | Resistor → LED long leg | ALARMED (red) |
| Each LED short leg | Blue (−) rail | Three loops complete |
// GAMERIFT free mission, The Mood Machine // A three-state Markov chain with an attitude. const int calmLED = 11, curiousLED = 12, alarmedLED = 13; // The personality: each row is a mood, each number a % chance. // Row order: CALM, CURIOUS, ALARMED. Rows must add up to 100. int personality[3][3] = { { 70, 25, 5 }, // from CALM: mostly stays calm { 40, 40, 20 }, // from CURIOUS: could go either way { 10, 10, 80 } // from ALARMED: hard to calm down }; int mood = 0; // 0 = calm, 1 = curious, 2 = alarmed, start calm void setup() { pinMode(calmLED, OUTPUT); pinMode(curiousLED, OUTPUT); pinMode(alarmedLED, OUTPUT); randomSeed(analogRead(A0)); // real randomness: electrical noise from an empty pin } void loop() { // 1. show the current mood (only the matching LED burns) digitalWrite(calmLED, mood == 0 ? HIGH : LOW); digitalWrite(curiousLED, mood == 1 ? HIGH : LOW); digitalWrite(alarmedLED, mood == 2 ? HIGH : LOW); delay(1000); // hold each mood for a second // 2. roll the dice (0–99) and let the current row decide what's next int roll = random(100); if (roll < personality[mood][0]) mood = 0; else if (roll < personality[mood][0] + personality[mood][1]) mood = 1; else mood = 2; }
(The ? : lines are shorthand for if/else: "if the mood matches, HIGH, otherwise LOW.") Upload it and just… watch for a minute. Long calm stretches. A flicker of curiosity. And occasionally, a panic that takes ages to settle, because row three makes alarm sticky. Nobody scripted that behaviour. It emerged from nine numbers and a dice roll. That feeling of watching something decide is why this maths conquered the world.
This is the full GAMERIFT mission format, brief, concepts, build, code, break-it, remix, exactly what Beginner Kit owners get twelve more of, from their very first blinking LED to a desk guardian that senses when someone comes near, ending in a certificate of completion you can verify online. The kit ships with every component this lesson used, and the course assumes nothing.