Close-up of the HC-SR04 ultrasonic sensor on a breadboard, its wires running to the Uno

    Full source.

    Every wire.

    Embedded systems

    Three Arduino Uno builds by our founder, shown whole: what each does, its parts, every wire and the full source, running in your browser.

    Code that has to fit

    TiketCaribbean runs on servers with memory to spare. The builds on this page run on an ATmega328P, the chip on the Arduino Uno: 16 MHz, 32 KB of flash for the program and 2 KB of RAM for everything else.

    Nothing sits between the code and the pins. Timing, memory and what happens when a part does not answer are all handled in the sketch itself.

    Jerome McCave, our founder, is a software engineer and an embedded systems engineer. He holds an MEng in Mechanical Engineering with Aeronautics from the University of Glasgow, and with GU Orbit, the university's student space team, he developed and tested CAN bus firmware and a watchdog timer for a 3U CubeSat.

    Every build below is his. Each sketch is compiled for the Uno and runs here on a simulated ATmega328P, instruction by instruction, with its parts modelled around it.

    RAM used, of the Uno's 2,048 bytes
    • Distance sensor, speaker build506 bytes, 25%
    • Distance sensor, display build1,901 bytes, 93%
    • Distance sensor, I2C scanner494 bytes, 24%
    • Reaction game1,377 bytes, 67%
    • Reaction game, remote codes537 bytes, 26%
    • Voice-controlled lights210 bytes, 10%

    Global variables only; the stack takes what is left while the sketch runs. Compiled with arduino-cli 1.6.0 and arduino:avr@1.8.8.

    Board
    Arduino Uno R3 (Elegoo), on a 9 V battery
    Parts
    HC-SR04, DFPlayer Mini with microSD and speaker, SH1106 OLED, two push buttons
    Libraries
    NewPing, DFRobotDFPlayerMini, SoftwareSerial, U8g2, Wire
    Sketches
    Speaker build, display build, I2C scanner

    Distance sensor

    Press a button and it measures how far away you are, then tells you: out loud in the first build, on a screen in the second.

    An HC-SR04 sends a 40 kHz ultrasonic pulse and the Uno times the echo. The sketch sorts each reading into four bands, more than 15 cm, more than 10, more than 5 and anything closer, and answers each band in its own way.

    In the first build a DFPlayer Mini plays one of four voice clips from a microSD card. The second build swaps the voice for an SH1106 OLED that shows a line of Trinidadian English, from "Yuh real far..." to "Watch it, man!", with the distance in centimetres underneath. One button switches the sensor on, the other switches it off.

    How it works

    • NewPing converts the echo time to centimetres and stops listening past 200 cm. A reading of 0 means nothing answered in range, and the display build says so: "No one there...".
    • A three-second cooldown between readings keeps the speaker from talking over itself.
    • The speaker build drives the DFPlayer over SoftwareSerial on pins 5 and 6, which leaves the Uno's hardware serial port free for the USB link and the serial monitor.
    • The first build reads HIGH as pressed, so its buttons switch 5 V onto the pin with a pull-down resistor to ground. The second uses the Uno's internal pull-ups and reads LOW as pressed, which needs no resistors at all.
    • U8g2's full-buffer mode keeps the whole 128 × 64 frame in RAM: 1,024 bytes. With everything else, the display build uses 1,901 of the Uno's 2,048 bytes.
    The speaker build from above: the Uno beside a breadboard holding two push buttons, the DFPlayer Mini and the sensor
    The breadboard with the HC-SR04 sensor and the DFPlayer Mini, wired to the Uno
    The Elegoo Uno R3 powered by a 9 V battery through its barrel jack
    The speaker build on the bench: an Elegoo Uno R3 run from a 9 V battery, with the HC-SR04, the DFPlayer Mini and both buttons on a breadboard.

    The sketches and their wiring

    The first build: a voice clip for each distance band, played through a DFPlayer Mini.

    Every connection

    Connections for object_distance_sensor.ino
    Uno pinGoes toCarries
    D5DFPlayer Mini RXCommands to the player (SoftwareSerial TX)
    D6DFPlayer Mini TXReplies from the player (SoftwareSerial RX)
    D7On button Leg 2HIGH while pressed
    D8Off button Leg 2HIGH while pressed
    D9HC-SR04 TrigTrigger pulse to the sensor
    D10HC-SR04 EchoEcho pulse; its length is the distance
    5VDFPlayer Mini VCC, On button Leg 1, Off button Leg 1, HC-SR04 VCCSupply
    GNDDFPlayer Mini GND, On button Pull-down, Off button Pull-down, HC-SR04 GNDGround
    • The sketch reads HIGH as pressed, so each button switches 5 V onto its pin, with a pull-down resistor to ground as in the build photo.
    • The speaker is not wired to the Uno: it sits on the DFPlayer's SPK1 and SPK2 pins.

    Run it

    Compiled for the Uno: 5,578 bytes of flash (17%), 506 of 2,048 bytes of RAM (25%)

    The compiled sketch, running on a simulated ATmega328P instruction by instruction, with the HC-SR04 (you set the distance), the DFPlayer Mini's serial protocol, both buttons and the serial monitor.

    object_distance_sensor.ino, 89 lines

    #include <SoftwareSerial.h>#include <DFRobotDFPlayerMini.h>#include <NewPing.h>#define TRIGGER_PIN  9  // HC-SR04 Trigger pin#define ECHO_PIN     10 // HC-SR04 Echo pin#define MAX_DISTANCE 200 // Maximum measurable distance in cm#define BUTTON_ON   7  // Push button pin#define BUTTON_OFF   8  // Push button pin// Initialize ultrasonic sensorNewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);// DFPlayer Mini setupSoftwareSerial mySoftwareSerial(6, 5); // RX, TXDFRobotDFPlayerMini myDFPlayer;// Propertiesbool isActive = false; // Track if system is activebool lastButtonState = LOW; // Track previous button statebool buttonPressed = false;const unsigned long debounceDelay = 200;unsigned long lastPlayTime = 0;const unsigned long playCooldown = 3000; // 2.5 sec between sounds

    The simulator above runs the sketch as published. Edits are not compiled on this page: to run your version, paste it into sketch.ino in Wokwi, a free Arduino simulator, and add the parts from the wiring. Edits are gone when you leave.

    In Wokwi: Wokwi has no DFPlayer Mini, so in the simulator this sketch stops at "DFPlayer Mini not detected!". The display build runs there instead.

    Board
    Arduino Uno R3
    Parts
    IR receiver, Elegoo infrared remote, SH1106 OLED, buzzer
    Libraries
    IRremote, U8g2
    Sketches
    The game, remote codes

    Reaction game

    A reflex test played with a TV-style remote: wait for the screen to say now, then press 0 as fast as you can.

    Press the power button to start. After a random pause the screen says NOW and the buzzer sounds; the time from the end of the beep until the 0 key's signal arrives is your score, in milliseconds, with a verdict from "Weyzz yous a boss!" to "Smh. Do better.". Press power during the wait to cancel.

    The game expects the power key to send 0x45 and the 0 key 0x16. A second sketch prints the code of every key pressed to the serial monitor, which is how to check a remote.

    How it works

    • The receiver's output goes to pin 2, and IRremote decodes the remote's NEC frames into an 8-bit command.
    • Codes of 0x00 and 0xFF are thrown away, and so is anything within 300 ms of the last accepted press.
    • An NEC frame takes about 68 ms to send, and that time is part of every score: the clock stops only once the 0 key's frame has been decoded.
    • The display runs in U8g2's page mode, drawing the screen in eight strips through one 128-byte buffer instead of holding a 1,024-byte frame. Infrared decoding and all, the game needs 1,377 bytes of RAM.
    • ENABLE_LED_FEEDBACK flashes the Uno's own LED on pin 13 whenever a signal arrives: a quick check that the receiver is working.

    The sketches and their wiring

    The game: start, random pause, NOW, score and verdict.

    Every connection

    Connections for GameConsole.ino
    Uno pinGoes toCarries
    D2IR receiver OUTDemodulated infrared signal
    D9Buzzer +HIGH sounds the buzzer
    A4 (SDA)SH1106 OLED SDAI2C data
    A5 (SCL)SH1106 OLED SCLI2C clock
    5VIR receiver VCC, SH1106 OLED VCCSupply
    GNDIR receiver GND, Buzzer −, SH1106 OLED GNDGround
    • The remote has no wire: it talks to the receiver in infrared, using NEC codes.

    Run it

    Compiled for the Uno: 21,148 bytes of flash (66%), 1,377 of 2,048 bytes of RAM (67%)

    The compiled sketch, running on a simulated ATmega328P instruction by instruction, with the SH1106 display, the infrared remote, the buzzer and the serial monitor.

    GameConsole.ino, 145 lines

    #include <IRremote.h>#include <U8g2lib.h>#define IR_RECEIVE_PIN 2#define BUZZER_PIN 9U8G2_SH1106_128X64_NONAME_1_HW_I2C display(U8G2_R0, U8X8_PIN_NONE);bool gameStarted = false;bool waitingForReaction = false;unsigned long startTime = 0;unsigned long reactionTime = 0;unsigned long lastCommandTime = 0;#define DEBOUNCE_TIME 300// Elegoo Remote Buttons (You can confirm via Serial monitor)#define BUTTON_ON_OFF 0x45  // Power button#define BUTTON_1      0x16  // Button 0decode_results results;void setup() {

    The simulator above runs the sketch as published. Edits are not compiled on this page: to run your version, paste it into sketch.ino in Wokwi, a free Arduino simulator, and add the parts from the wiring. Edits are gone when you leave.

    In Wokwi: Wokwi's IR remote sends the same codes as the Elegoo remote. Change SH1106 to SSD1306 in the display line, add the IRremote and U8g2 libraries, and it runs.

    Board
    Arduino Uno R3, on USB
    Parts
    Red, green and blue LEDs with series resistors, a computer
    Libraries
    None beyond the Arduino core
    Sketches
    One

    Voice-controlled lights

    Say a colour and that light comes on. This is the board's half: it listens on the USB port and switches three LEDs.

    Speech recognition runs on a computer, which sends what it heard to the Uno as a line of text at 9600 baud. The sketch reads the line, switches every LED off, then lights red, green or blue if the line contains that word. Anything else leaves them all dark.

    Keeping the board's side this small means the listening program on the computer can change without touching the firmware. That program is not shown here.

    How it works

    • Serial.readStringUntil('\n') collects one line; the stream's one-second timeout ends a line that arrives without a newline.
    • Every line switches all three LEDs off first, so only one is ever lit.
    • The checks run in order, so a line that names two colours lights the first match: red before green, green before blue.
    • Matching a word inside the line, not the whole line, lets the speech side send full sentences such as "turn on the red light".

    The sketch and its wiring

    The board's half: read a line, light the colour it names.

    Every connection

    Connections for AI_Powered_Voice_Control.ino
    Uno pinGoes toCarries
    USB (serial)Computer USBLines of text at 9600 baud
    D2Red LED Anode, via resistorHIGH lights the red LED
    D3Green LED Anode, via resistorHIGH lights the green LED
    D4Blue LED Anode, via resistorHIGH lights the blue LED
    GNDRed LED Cathode, Green LED Cathode, Blue LED CathodeGround
    • Each LED needs a resistor in series to limit its current. The project does not record the values; 220 Ω is typical for the kit's LEDs.

    Run it

    Compiled for the Uno: 3,680 bytes of flash (11%), 210 of 2,048 bytes of RAM (10%)

    The compiled sketch, running on a simulated ATmega328P instruction by instruction, with the three LEDs and the serial monitor.

    AI_Powered_Voice_Control.ino, 21 lines

    // Arduino codevoid setup() {  Serial.begin(9600);  pinMode(2, OUTPUT);  pinMode(3, OUTPUT);  pinMode(4, OUTPUT);}void loop() {  if (Serial.available()) {    String cmd = Serial.readStringUntil('\n');    digitalWrite(2, LOW);    digitalWrite(3, LOW);    digitalWrite(4, LOW);    if (cmd.indexOf("red") >= 0) digitalWrite(2, HIGH);    else if (cmd.indexOf("green") >= 0) digitalWrite(3, HIGH);    else if (cmd.indexOf("blue") >= 0) digitalWrite(4, HIGH);  }}

    The simulator above runs the sketch as published. Edits are not compiled on this page: to run your version, paste it into sketch.ino in Wokwi, a free Arduino simulator, and add the parts from the wiring. Edits are gone when you leave.

    In Wokwi: Runs as it is. Wire three LEDs to pins 2, 3 and 4, then type red, green or blue into Wokwi's serial monitor.

    Port of Spain from the hills, with the Queen's Park Savannah in the middle
    Soca artists performing on a fete stage in Port of Spain
    The crowd at Notting Hill Carnival in London

    Building something physical?

    We write firmware as well as the platforms it reports to. If you are building a device, tell us about it.

    We reply to every enquiry at admin@caribraconnect.com.

    Organisers can start selling on TiketCaribbean today.

    Jerome McCave, founder of CaribraConnect Technology
    Jerome McCave, founder. He reads every enquiry.