Skip to content

xjtluk/casa0014

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

casa0014

coursework

Chrono Lumina - Light Control with Vibration and Sound Sensors

Project Overview

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.

Requirements

  • 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 connectivity
    • PubSubClient.h - For MQTT communication

Setup

  1. Wi-Fi Configuration: Connect the Arduino to your Wi-Fi using the SSID and password.
  2. MQTT Broker: The system connects to an MQTT broker (mqtt.cetools.org) for communication. The topic student/CASA0014/light/29/pixel/ is used for controlling the RGB pixels.

Functionality

  • 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.

Code Explanation

  • 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.

Key Functions

  • 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.

Usage

  1. Upload the code to the Arduino.
  2. Ensure the vibration and sound sensors are connected to the correct pins (A0 for vibration, A1 for sound).
  3. Monitor the light setup’s reaction to vibration and sound.

Troubleshooting

  • 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!

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

coursework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages