coursework
This project involves controlling an RGB light setup using an Arduino-based microcontroller. The system is designed to react to two types of inputs: vibration and sound. When a vibration is detected, the light color changes. Meanwhile, sound levels control the number of active pixels in the light setup, simulating a brightness control based on ambient sound. The system also integrates MQTT for remote control via the internet.
-
Hardware:
- Arduino MKR WiFi 1010
- Vibration Sensor (Analog)
- Sound Sensor (Analog)
- RGB Light setup (12 pixels)
- Wi-Fi access and MQTT broker for remote communication
-
Libraries:
WiFiNINA.h
- For Wi-Fi connectivityPubSubClient.h
- For MQTT communication
- Wi-Fi Configuration: Connect the Arduino to your Wi-Fi using the SSID and password.
- MQTT Broker: The system connects to an MQTT broker (
mqtt.cetools.org
) for communication. The topicstudent/CASA0014/light/29/pixel/
is used for controlling the RGB pixels.
-
Vibration Detection:
- When vibration exceeds a set threshold, the light color changes.
- The color cycles through red, green, blue, and white.
-
Sound Detection:
- The number of active pixels adjusts based on the sound level.
- Lower sound levels (0-340) activate 4 pixels, mid levels (341-681) activate 8, and high levels (682-1023) activate all 12 pixels.
-
MQTT Communication:
- The Arduino sends MQTT messages to update the light color and brightness (pixel count) based on the inputs.
- The code uses WiFi to connect to the internet and MQTT to communicate with the light setup.
- Vibration Sensor: Detects vibrations and changes the light color.
- Sound Sensor: Controls the number of active pixels based on the sound level.
- The
sendmqtt
function sends RGB color values to each pixel of the light setup.
sendmqtt(int pixelID, int r, int g, int b)
: Sends the color data to the MQTT broker for updating the light pixels.startWifi()
: Connects the Arduino to the Wi-Fi network.reconnectMQTT()
: Ensures the system reconnects to the MQTT broker if disconnected.
- Upload the code to the Arduino.
- Ensure the vibration and sound sensors are connected to the correct pins (
A0
for vibration,A1
for sound). - Monitor the light setup’s reaction to vibration and sound.
- If the Wi-Fi connection fails, ensure the SSID and password are correctly set.
- For MQTT issues, verify that the broker address and credentials are correct.
Enjoy experimenting with this interactive light control system!
This project is licensed under the MIT License - see the LICENSE file for details.