Remote-controlled RGB mood light
Warm, cool, rainbow or breathing: cycle lighting moods from your sofa.
Shop by category
Shop all componentsPlay a simplified Snake on the 8×8 LED matrix, steering with the joystick and growing each time you eat. The snake is two arrays, snakeX and snakeY, holding the coordinates of each segment. Moving is done by shifting every segment into the position of the one ahead of it, then placing the new head, no segment is ever really moved, the values simply cascade backwards. Everything on the board is addressed as a column and row pair, which is 2D coordinate mapping: the same idea behind every tile-based game ever written.
Every part for this build comes in the Geekobot Explorer Kit box, a Geekobot exclusive, together with the parts for all 61 projects, from a first blinking LED to a smart fan and a reaction game. The wiring below is the kit's own wiring.
Tick anything you already have and the total updates.
The brain of every Explorer Kit project
Male-to-female and female-to-female leads for the modules
Analog joystick: two potentiometers and a push switch
Nano I/O shield from the kit: every pin has its own S, V, G header, so modules plug in with jumpers
Follow the colours: red is power, dark grey is ground, blue is a signal.
explorer_kit_56_joystick_snake.inoVerify & upload in Electrolark#include <LedControl.h>
LedControl lc = LedControl(11, 13, 10, 1);
int xPin = A0;
int yPin = A1;
int buzzer = 8;
int snakeX[64];
int snakeY[64];
int length_ = 3;
int dirX = 1;
int dirY = 0;
int foodX;
int foodY;
int stepDelay = 400;
void placeFood()
{
bool onSnake = true;
while (onSnake)
{
foodX = random(0, 8);
foodY = random(0, 8);
onSnake = false;
for (int i = 0; i < length_; i++)
{
if (snakeX[i] == foodX && snakeY[i] == foodY)
{
onSnake = true;
}
}
}
}
void draw()
{
lc.clearDisplay(0);
for (int i = 0; i < length_; i++)
{
lc.setLed(0, snakeY[i], snakeX[i], true);
}
lc.setLed(0, foodY, foodX, true);
}
void readJoystick()
{
int x = analogRead(xPin) - 512;
int y = analogRead(yPin) - 512;
if (x > 300 && dirX == 0) { dirX = 1; dirY = 0; }
else if (x < -300 && dirX == 0){ dirX = -1; dirY = 0; }
else if (y > 300 && dirY == 0) { dirX = 0; dirY = -1; }
else if (y < -300 && dirY == 0){ dirX = 0; dirY = 1; }
}
void gameOver()
{
for (int i = 0; i < 3; i++)
{
tone(buzzer, 150, 200);
for (int r = 0; r < 8; r++)
{
lc.setRow(0, r, B11111111);
}
delay(200);
lc.clearDisplay(0);
delay(200);
}
length_ = 3;
dirX = 1;
dirY = 0;
stepDelay = 400;
for (int i = 0; i < length_; i++)
{
snakeX[i] = 3 - i;
snakeY[i] = 4;
}
placeFood();
delay(800);
}
void setup()
{
lc.shutdown(0, false);
lc.setIntensity(0, 4);
lc.clearDisplay(0);
pinMode(buzzer, OUTPUT);
randomSeed(analogRead(A2));
for (int i = 0; i < length_; i++)
{
snakeX[i] = 3 - i;
snakeY[i] = 4;
}
placeFood();
}
void loop()
{
// Read the stick several times while waiting, so turns feel responsive
for (int i = 0; i < 20; i++)
{
readJoystick();
delay(stepDelay / 20);
}
int newX = snakeX[0] + dirX;
int newY = snakeY[0] + dirY;
if (newX < 0 || newX > 7 || newY < 0 || newY > 7)
{
gameOver();
return;
}
for (int i = 0; i < length_; i++)
{
if (snakeX[i] == newX && snakeY[i] == newY)
{
gameOver();
return;
}
}
// Shift every segment back one place
for (int i = length_; i > 0; i--)
{
snakeX[i] = snakeX[i - 1];
snakeY[i] = snakeY[i - 1];
}
snakeX[0] = newX;
snakeY[0] = newY;
if (newX == foodX && newY == foodY)
{
length_ = length_ + 1;
tone(buzzer, 900, 80);
placeFood();
if (stepDelay > 150)
{
stepDelay = stepDelay - 20;
}
}
draw();
}
Use the kit's mini-USB cable, install the CH340 driver on Windows if no port appears, pick Tools > Board > Arduino Nano and try Tools > Processor > ATmega328P (Old Bootloader) if the upload times out.
This project needs the passive buzzer (the one that plays notes with tone()), not the active one.
Check DIN on D11, CS on D10 and CLK on D13, and that the module's IN side (not OUT) is used.
Read the centre value in the Serial Monitor and widen the dead zone numbers in the sketch.
The snake is two arrays, snakeX and snakeY, holding the coordinates of each segment. Moving is done by shifting every segment into the position of the one ahead of it, then placing the new head, no segment is ever really moved, the values simply cascade backwards. Everything on the board is addressed as a column and row pair, which is 2D coordinate mapping: the same idea behind every tile-based game ever written.
A three-dot snake starts moving right with one dot of food on the board. Push the joystick to steer; the snake cannot reverse into itself. Eating the food adds a segment, beeps, and speeds the game up slightly.
Yes. It is project 56 of 61 in the Geekobot Explorer Kit, in level 9 (Interactive games). Every part on the list comes in the kit box, and you can also buy the parts one by one from the list above.
No. Every Explorer Kit project is wired on the Nano I/O shield and the breadboard with jumper wires.
7 parts: Generic Nano CH340 Development Board (Soldered), USB Cable, Dupont Jumper Wires (40 pcs), Buzzer Module 3.3–5V, MAX7219 LED Display Module, PS2 Thumb Joystick Module (KY-023 style) and Arduino Nano IO Expansion Shield (328P Compatible). On this page you can tick the parts you already have and add only the rest to your cart.
It is a advanced project and takes about 1 hour. The build on this page has 6 steps.
No. This page has the complete, tested code (explorer_kit_56_joystick_snake.ino).
About ₹560 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
2D coordinate mapping on a matrix; Moving a snake by cascading array values; Preventing an illegal reverse turn; Sampling input repeatedly during a game tick.
Warm, cool, rainbow or breathing: cycle lighting moods from your sofa.
Press to roll: the pips tumble and slow down before landing on a number.
Wait for the light, hit the button: how many milliseconds can you beat?
A bright 4-digit clock that keeps time through power cuts.
Lessons are free to read. Maker (₹499/month) and Pro add quizzes, worked problems and certificates, paid with your Geekobot account. See plans
Learning project. Check every circuit and the datasheet of each part before you power it up.