// Library to control NeoPixel LED ring.
#include <Adafruit_NeoPixel.h>
// Library to control the infrared (IR) remote.
#include <IRremote.h>
// Defines pins and LED settings.
// Pin for LED ring.
#define PIN 6
// Number of LEDs in the ring.
#define LED_COUNT 16
// The ring's brightness level.
#define BRIGHTNESS 250
// Pin connected to infrared (IR) receiver.
#define PIN_RECEIVER 2
// Pin connected to the buzzer.
#define BUZZER_PIN 8
// Note: The buzzer represents sound outputs that would come from a speaker through Bluetooth.
// Note: The RGB LED simulates and substitutes the circuitry of an HC-05 Bluetooth module.
// Note: The IR remote substitutes a phone, representing the buttons within an application that are tapped to change mood.
// Thanks to user arcostasi for setup of the IR remote, and the logic in the loop method.
// Thanks to Mauro Alfieri for code on Neopixel initialisation, and the set_color method.
// Thanks to the diagram reference in Wokwi Docs for assisting with pin connections and the remote commands.
// Initialises the NeoPixel ring's LED count, pin, and colour formatting.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(LED_COUNT, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// Starts serial communication and hardware.
// Serial commmunication for debugging.
Serial.begin(9600);
// Begins the IR receiver.
IrReceiver.begin(PIN_RECEIVER, ENABLE_LED_FEEDBACK);
// Prepares the NeoPixel ring for use.
pixels.begin();
// Sets brightness of LEDs.
pixels.setBrightness(BRIGHTNESS);
// Ensures that LEDs start as off.
pixels.show();
// Sets buzzer pin as the sound output.
pinMode(BUZZER_PIN, OUTPUT);
// Flashes LED ring white and off to indicate setup completion.
for (int i = 0; i < 6; i++) {
// Sets LEDs to white.
set_color(pixels.Color(255, 255, 255));
// 250 millisecond wait.
delay(250);
// Turns LEDs off.
set_color(pixels.Color(0, 0, 0));
// 250 milliseocond wait.
delay(250);
}
}
void set_color(uint32_t color) {
// Loops through every LED.
for (int i = 0; i < LED_COUNT; i++) {
// Sets the colour for the current LED.
pixels.setPixelColor(i, color);
}
// Applies the colour change to all LEDs.
pixels.show();
}
void loop() {
// CHeck if an IR signal is received.
if (IrReceiver.decode()) {
// Store the button value received.
int button_value = IrReceiver.decodedIRData.command;
// Matches button value to a case.
switch (button_value) {
// IR code for rebellious music button.
case 48:
// Displays message in serial monitor.
Serial.println("Playing Rebellious Music.");
// Sets LEDs to red.
set_color(pixels.Color(255, 0, 0));
// Buzzer on.
digitalWrite(BUZZER_PIN, HIGH);
// Wait for half a second.
delay(500);
// Buzzer off
digitalWrite(BUZZER_PIN, LOW);
// Wait for half a second.
delay(500);
break; // IR code for happy music.
case 24:
// Sets LEDs to yellow.
set_color(pixels.Color(255, 255, 0));
Serial.println("Playing Happy Music.");
digitalWrite(BUZZER_PIN, HIGH);
delay(300);
digitalWrite(BUZZER_PIN, LOW);
delay(200);
digitalWrite(BUZZER_PIN, HIGH);
delay(300);
digitalWrite(BUZZER_PIN, LOW);
break;
// IR code for sad music.
case 122:
// Sets LEDs to blue.
set_color(pixels.Color(0, 0, 255));
Serial.println("Playing Sad Music.");
digitalWrite(BUZZER_PIN, HIGH);
delay(1000);
digitalWrite(BUZZER_PIN, LOW);
delay(1000);
break;
// IR code for nature sounds.
case 16:
// Sets LEDs to green.
set_color(pixels.Color(0, 255, 0));
Serial.println("Playing Nature Sounds.");
digitalWrite(BUZZER_PIN, HIGH);
delay(200);
digitalWrite(BUZZER_PIN, LOW);
delay(300);
digitalWrite(BUZZER_PIN, HIGH);
delay(200);
digitalWrite(BUZZER_PIN, LOW);
break;
// IR code for exciting EDM.
case 56:
// Sets LEDs to orange.
set_color(pixels.Color(255, 165, 0));
Serial.println("Playing Exciting EDM.");
digitalWrite(BUZZER_PIN, HIGH);
delay(100);
digitalWrite(BUZZER_PIN, LOW);
delay(100);
digitalWrite(BUZZER_PIN, HIGH);
delay(100);
digitalWrite(BUZZER_PIN, LOW);
break;
// IR code for romantic music.
case 90:
// Sets LEDs to pink.
set_color(pixels.Color(255, 105, 180));
Serial.println("Playing Romantic Music.");
digitalWrite(BUZZER_PIN, HIGH);
delay(700);
digitalWrite(BUZZER_PIN, LOW);
delay(300);
break;
// IR code for hopeful music.
case 66:
// Sets LEDs to white.
set_color(pixels.Color(255, 255, 255));
Serial.println("Playing Hopeful Music.");
digitalWrite(BUZZER_PIN, HIGH);
delay(400);
digitalWrite(BUZZER_PIN, LOW);
delay(400);
digitalWrite(BUZZER_PIN, HIGH);
delay(600);
digitalWrite(BUZZER_PIN, LOW);
break;
// IR code for eerie music.
case 74:
// Sets LEDs to purple.
set_color(pixels.Color(128, 0, 128));
Serial.println("Playing Eerie Music.");
digitalWrite(BUZZER_PIN, HIGH);
delay(200);
digitalWrite(BUZZER_PIN, LOW);
delay(100);
digitalWrite(BUZZER_PIN, HIGH);
delay(200);
digitalWrite(BUZZER_PIN, LOW);
break;
// Responds to any other unrecognised button press.
default:
Serial.println("Other button pressed.");
break;
}
// Resumes IR receiver to get the next signal.
IrReceiver.resume();
}
}