Differences

This shows you the differences between two versions of the page.

Link to this comparison view

pm:prj2023:tmiu:soundactivatedlights [2023/05/27 12:19]
denisa.stanescu
pm:prj2023:tmiu:soundactivatedlights [2023/05/30 12:28] (current)
denisa.stanescu
Line 36: Line 36:
  
  ​{{:​pm:​prj2023:​tmiu:​soundactivatedlights:​whatsapp_image_2023-05-06_at_14.44.17.jpeg?​200|}}  ​{{:​pm:​prj2023:​tmiu:​soundactivatedlights:​whatsapp_image_2023-05-06_at_14.44.17.jpeg?​200|}}
-  * diagrame de semnal + 
-  * rezultatele simulării+
  
 + ​{{:​pm:​prj2023:​tmiu:​sch_electr.jpeg?​200|}}
  
  
Line 44: Line 44:
 ===== Software Design ===== ===== Software Design =====
  
-Descrierea codului aplicaţiei (firmware): 
-  * ADC (lab4) 
  
-sensorValue = (float)analogRead(sensorPin) * (5.0 / 1024.0); ​// performs an analog-to-digital conversion using the analogRead function; it reads the analog value from sensorPin and converts it to a digital value+  * ADC (lab4) 
 +-sensorValue = (float)analogRead(sensorPin) * (5.0 / 1024.0); ​
  
 +-performs an analog-to-digital conversion using the analogRead function; it reads the analog value from sensorPin and converts it to a digital value
   * Timer (lab3)   * Timer (lab3)
-Timer1.initialize(100000);  ​// sets the timer interval to 100ms (0.1s); this allows for periodic execution of a function based on the timer interval +-Timer1.initialize(100000);  ​ 
-  ​+ 
 +-sets the timer interval to 100ms (0.1s); this allows for periodic execution of a function based on the timer interval
   * Interrupt (lab2)   * Interrupt (lab2)
 +-Timer1.attachInterrupt(FlashLEDs); ​
  
-Timer1.attachInterrupt(FlashLEDs);​ // attaches the FlashLEDs function to the interrupt triggered by Timer1; this means that every time the timer interrupt occurs (every 100ms), the FlashLEDs function will be executed.+-attaches the FlashLEDs function to the interrupt triggered by Timer1; this means that every time the timer interrupt occurs (every 100ms), the FlashLEDs function will be executed. 
 +  * libraries and 3rd party sources: 
 +-<​avr/​interrupt.h>​
  
-  ​* (etapa 3surse şi funcţii implementate+-TimerOne.h (It is used in this code to set up a timer interrupt for flashing the LEDs) 
 +  ​algorithms and structures:​ 
 +-MainFunction(): Reads the sensor value, filters the signal, and compares it to predefined values to determine the color to display on the RGB LED strip
  
-Descrierea codului aplicaţiei ​(firmware): +-FilterSignal(float sensorSignal): Applies a filter to the sensor signal using a weighted moving average algorithm
-  * mediu de dezvoltare (if any) (e.g. AVR Studio, CodeVisionAVR) +
-  * librării şi surse 3rd-party (e.g. Procyon AVRlib) +
-  * algoritmi şi structuri pe care plănuiţi să le implementaţi +
-  * (etapa 3) surse şi funcţii implementate+
  
 +-CompareSignalFiltered(float filteredSignal):​ Compares the filtered signal to predefined thresholds to determine the appropriate color to display
  
-===== Rezultate Obţinute =====+-RGBColor(int Rcolor, int Gcolor, int Bcolor): Sets the color of the RGB LED strip by writing appropriate values to the Rpin, Gpin, and Bpin pins
  
 +  * functions:
 +-setup(): Sets up the initial configuration of the program, including serial communication initialization and timer setup
  
-Care au fost rezultatele obţinute în urma realizării proiectului vostru.+-loop(): Contains the main execution loop, calling the MainFunction() repeatedly
  
 +-FlashLEDs():​ A timer interrupt service routine (ISR) that alternates the LED strip between white and off states
  
-===== Concluzii ===== 
  
-===== Download =====+  *
  
 +<file c++>
  
-O arhivă (sau mai multe dacă este cazul) cu fişierele obţinute în urma realizării proiectului:​ surse, scheme, etcUn fişier README, un ChangeLog, un script de compilare şi copiere automată pe uC crează întotdeauna o impresie bună ;-).+#include <​avr/​interrupt.h> 
 +#include <​TimerOne.h>
  
-Fişierele se încarcă pe wiki folosind facilitatea **Add Images or other files**. Namespace-ul în care se încarcă fişierele este de tipul **:​pm:​prj20??:​c?​** sau **:​pm:​prj20??:​c?:​nume_student** (dacă este cazul). **Exemplu:​** Dumitru Alin, 331CC -> **:​pm:​prj2009:​cc:​dumitru_alin**.+#define Rpin 11 
 +#define Gpin 10 
 +#define Bpin 9 
 +#define delayLEDS 3 
 +#define sensorPin A0
  
 +float sensorValue = 0, filteredSignal = 0,
 +    filteredSignalValues[] = {3.4, 3.1, 2.7, 2.4, 2.1, 1.7, 1.3, 0.9, 0.4};
 +
 +void setup() {
 +  Serial.begin(9600);​
 +
 +  Timer1.initialize(100000); ​ // Set the timer interval to 100ms (0.1s)
 +  Timer1.attachInterrupt(FlashLEDs); ​ // Attach the FlashLEDs function to the timer interrupt
 +}
 +
 +void loop() {
 +  MainFunction();​
 +}
 +
 +void MainFunction() {
 +  sensorValue = (float)analogRead(sensorPin) * (5.0 / 1024.0);
 +  FilterSignal(sensorValue);​
 +  Serial.print(sensorValue);​
 +  Serial.print("​ ");
 +  Serial.println(filteredSignal);​
 +  CompareSignalFiltered(filteredSignal);​
 +}
 +
 +void FilterSignal(float sensorSignal) {
 +  filteredSignal = (0.945 * filteredSignal) + (0.0549 * sensorSignal);​
 +}
 +
 +void CompareSignalFiltered(float filteredSignal) {
 +  if (filteredSignal > filteredSignalValues[0]) {
 +    RGBColor(0, 0, 255);
 +    Serial.println("​Blue"​);​
 +  } else if (filteredSignal <= filteredSignalValues[0] && filteredSignal > filteredSignalValues[1]) {
 +    Serial.println("​Azure"​);​
 +    RGBColor(0, 255, 255);
 +  } else if (filteredSignal <= filteredSignalValues[1] && filteredSignal > filteredSignalValues[2]) {
 +    RGBColor(0, 127, 255);
 +    Serial.println("​Cyan"​);​
 +  } else if (filteredSignal <= filteredSignalValues[2] && filteredSignal > filteredSignalValues[3]) {
 +    RGBColor(0, 255, 127);
 +    Serial.println("​Aqua marine"​);​
 +  } else if (filteredSignal <= filteredSignalValues[3] && filteredSignal > filteredSignalValues[4]) {
 +    RGBColor(0, 255, 0);
 +    Serial.println("​Green"​);​
 +  } else if (filteredSignal <= filteredSignalValues[4] && filteredSignal > filteredSignalValues[5]) {
 +    RGBColor(255,​ 255, 0);
 +    Serial.println("​Yellow"​);​
 +  } else if (filteredSignal <= filteredSignalValues[5] && filteredSignal > filteredSignalValues[6]) {
 +    RGBColor(255,​ 0, 255);
 +    Serial.println("​Magenta"​);​
 +  } else if (filteredSignal <= filteredSignalValues[6] && filteredSignal > filteredSignalValues[7]) {
 +    RGBColor(255,​ 0, 127);
 +    Serial.println("​Rose"​);​
 +  } else if (filteredSignal <= filteredSignalValues[7] && filteredSignal > filteredSignalValues[8]) {
 +    RGBColor(255,​ 127, 0);
 +    Serial.println("​Orange"​);​
 +  } else if (filteredSignal <= filteredSignalValues[8]) {
 +    RGBColor(255,​ 0, 0);
 +    Serial.println("​Red"​);​
 +  } else {
 +    RGBColor(0, 0, 255);
 +    Serial.println("​Default:​ Blue"​);​
 +  }
 +}
 +
 +void RGBColor(int Rcolor, int Gcolor, int Bcolor) {
 +  analogWrite(Rpin,​ Rcolor);
 +  analogWrite(Gpin,​ Gcolor);  ​
 +  analogWrite(Bpin,​ Bcolor);
 +
 +  delay(delayLEDS);​
 +}
 +
 +void FlashLEDs() {
 +  static boolean flashState = false;
 +  ​
 +  if (flashState) {
 +    RGBColor(255,​ 255, 255);  // White color
 +    flashState = false;
 +  } else {
 +    RGBColor(0, 0, 0);  // Turn off LEDs
 +    flashState = true;
 +  }
 +}
 +
 +</​file>​
 +
 +
 +===== Results =====
 +
 +
 +The project utilizes an Arduino board along with a sound sensor, three resistors, three transistors,​ and a LED strip. The goal of the project is to change the color of the LED strip based on the intensity of the sound signal. The code implements a filtering mechanism to smooth out the sensor signal and compares it with predefined threshold values to determine the color.
 +
 +During testing, the project demonstrated successful functionality. As the sound intensity changes, the LED strip reacts by changing colors accordingly. The code effectively filters the sensor signal to provide more stable readings and compares the filtered signal with a set of predefined values to determine the appropriate color.
 +
 +Additionally,​ a timer interrupt has been incorporated into the code to introduce a flashing effect on the LEDs. This feature alternates between turning the LEDs on and off at a regular interval, creating a blinking effect.
 +
 +
 +
 +{{:​pm:​prj2023:​tmiu:​result-circuit.jpeg?​200|}}
 +
 +
 +
 +===== Conclusion =====
 +
 +
 +Overall, the project achieves the desired outcome of changing the LED strip'​s colors based on sound intensity, enhancing the visual experience in response to music or audio input. The added flashing effect further enhances the visual appeal of the project.
 +
 +
 +===== Download =====
 +
 +{{:​pm:​prj2023:​tmiu:​proj_details.zip|}}
  
 ===== Jurnal ===== ===== Jurnal =====
  
  
-Puteți avea și o secțiune de jurnal în care să poată urmări asistentul de proiect progresul proiectului.+Finished initial doc(7/​5/​2023) 
 + 
 +Added hardware scheme. (28/​5/​2023) 
 + 
 +Added software program.(28/​05/​2023) 
 + 
  
 +===== Bibliography =====
  
-===== Bibliografie/​Resurse ===== 
  
  
-Listă cu documente, datasheet-uri,​ resurse Internet folosite, eventual grupate pe **Resurse Software** şi **Resurse Hardware**.+[[https://​www.geeksforgeeks.org/​introduction-of-led/​]]
  
 +[[https://​randomnerdtutorials.com/​guide-for-ws2812b-addressable-rgb-led-strip-with-arduino/​]]
  
 <​html><​a class="​media mediafile mf_pdf"​ href="?​do=export_pdf">​Export to PDF</​a></​html>​ <​html><​a class="​media mediafile mf_pdf"​ href="?​do=export_pdf">​Export to PDF</​a></​html>​
  
pm/prj2023/tmiu/soundactivatedlights.1685179169.txt.gz · Last modified: 2023/05/27 12:19 by denisa.stanescu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0