Light-up Valentine heart on an Arduino Uno
A heart on an 8x8 MAX7219 LED matrix beats lub-dub, a big heart and a small one, at a pace you set with a knob, ready to glow behind red tissue in a card. The whole build, an Arduino Uno and 2 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.
// Light-up Valentine heart: a heart on an 8x8 LED matrix that beats, a big
// beat and a small one, lub-dub, at a pace you set with a knob.
//
// MAX7219 8x8 matrix module: DIN -> pin 11, CLK -> pin 13, CS -> pin 10,
// VCC -> 5 V, GND -> GND
// knob potentiometer wiper -> A0, ends to 5 V and GND
//
// Each picture is eight bytes, one per row, a 1 for every lit LED, so the big
// heart and the small heart are two short tables. A heartbeat is not one
// thump: it is two close together and then a rest, so the sketch shows the
// big heart, the small one, the big one again, then rests on the small one.
//
// The knob sets the beats a minute, from a calm 50 to an excited 140. Put the
// matrix behind a sheet of red tissue paper in a card or a little frame and
// it glows like one heart instead of 64 dots.
//
// Things to try. Turn the knob. Draw your own picture in BIG or SMALL: a
// smiling face, or your initials.
#include <LedControl.h>
LedControl matrix(11, 13, 10, 1); // DIN, CLK, CS, one module
const uint8_t BIG[8] = {
0b01100110,
0b11111111,
0b11111111,
0b11111111,
0b01111110,
0b00111100,
0b00011000,
0b00000000,
};
const uint8_t SMALL[8] = {
0b00000000,
0b00100100,
0b01111110,
0b01111110,
0b00111100,
0b00011000,
0b00000000,
0b00000000,
};
int beats = 0;
void draw(const uint8_t picture[8]) {
for (int row = 0; row < 8; row++) matrix.setRow(0, row, picture[row]);
}
void setup() {
Serial.begin(9600);
matrix.shutdown(0, false);
matrix.setIntensity(0, 8);
matrix.clearDisplay(0);
draw(SMALL);
Serial.println("Be my Valentine: the heart is beating");
}
void loop() {
int bpm = map(analogRead(A0), 0, 1023, 50, 140);
unsigned long beat = 60000UL / bpm;
// Lub, dub, rest.
draw(BIG);
delay(beat / 8);
draw(SMALL);
delay(beat / 10);
draw(BIG);
delay(beat / 8);
draw(SMALL);
beats++;
if (beats % 10 == 1) {
Serial.print("Beat ");
Serial.print(beats);
Serial.print(" at ");
Serial.print(bpm);
Serial.println(" beats a minute");
}
delay(beat - beat / 8 - beat / 10 - beat / 8);
}
Parts list
4 parts, plus the jumper wires. Every one is in the editor's parts bin.
- 1 × Arduino Uno R3
- 1 × Half breadboard
- 1 × Potentiometer
- 1 × LED matrix, 8x8
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 13; LED matrix, 8x8 pin CLK
- Arduino Uno R3 pin 11; LED matrix, 8x8 pin DIN
- Arduino Uno R3 pin 10; LED matrix, 8x8 pin CS
- Arduino Uno R3 pin 5V; Potentiometer pin 3; LED matrix, 8x8 pin VCC
- Ground: Arduino Uno R3 pin GND; Potentiometer pin 1; LED matrix, 8x8 pin GND
- Arduino Uno R3 pin A0; Potentiometer pin 2
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.