Sound Responsive Light Installation with Arduino

Page 1

DESIGN WORKSHOP III Interaction Design

Chingkhomba Chingtham Exhibition Design, VII semester


L TX RX

Arduino

ON

TM

1

A5

A4

A3

A2

A1

ANALOG IN A0

VIN

POWER GND

GND

5V

3V3

RESET

IOREF

ICSP

The Arduino platform was created by Massimo Banzi and his team to help their students who had limited experience with electronics make more effective prototypes of their devices rather than just dumb mockups. Since then, the user base for the Arduino platform has exploded, supported by the fact that the whole platform is based on open-source technologies. The platform has now been used for more than just prototyping and has become the the backbone of numerous projects all over the world, from being an indespensible part of the DIY community to being used for cutting-edge research as a part of the Large Hadron Collider (LHC) at CERN.

0

)

RX0

2

3

4

5

6

7

8

9

10

11

12

13

DIGITAL (PWM=

1

ICSP2

TX0

RESET

GND

Arduino is a platform for prototyping and developing electronics devices. The Arduino platform has been a huge success because it is cost effective, has a shallow learning curve and results can be achieved in a very short time.

AREF

| about Arduino

Image 1: A simplified image of the Arduino UNO board.


| about the Project Hearing is one of the most important senses, but unlike vision, it cannot be shut. In today's overcrowded and chaotic world, it is increasingly becoming a luxury to have some peace and quiet, without having one's auditory senses bombarded. Noise increases stress and reduces productivity but it is a difficult task to manage noise levels in public spaces. It is human tendency to raise one's voice to be heard above the noise, but in doing so, adds to the very cacophony that one tries to overcome and so continues the viscious cycle of noise. The project is an effort to break that cycle by bringing in a visual element that makes people aware of noise through animated lights that change colour and behaviour based on the ambient noise levels. When it is quiet, the lights are dim and green and when the environment becomes noisy, the lights turn bright red and flicker in an agitated manner, bringing the attention of those around to the fact that then noise levels are too much and that everyone needs to actively act to reduce noise.

Image 2: Image demonstrationg the possible application of the concept in the form of a wall piece.


| making the Project

The following is a list of the broadly categorized steps involved in making the project.

|||||||||||||||||||||||||| |||||||||||||||||||||||||| |||||||||||||||||||||||||| INPUT

OUTPUT

PROCESSING

Pre-amplified microphone

Common anode RGB LED

Coding the Arduino

A pre-amplified microphone is used as the input sensor, receiving the ambient sounds from the surroundings and prividing the input to the Arduino as voltage readings.

For the output, RGB LEDs are used. The input received from the microphone is used to calculate the colours of the LEDs between a range from green to red.

Coding the Arduino involves analysing the input signal, then using mathematical formulas to transmute the input values to values that are compatible with the output LEDs.

These voltage readings are converted to numeric equivalents within the Arduino, which are then used to drive the output through the RGB LEDs.

|||||||||||||||||||||||||| ASSEMBLY

Completing the circuit

The rate of change in the colour of the LEDs is also controlled by the audio input.

Another aspect is calculating the rate of change between colours, which is also done through the application of mathematical formulas to the input signal


|||||||||||||||||||||||||||||

∑ Upper limit

5v

INPUT

Pre-amplified microphone

For this project, the 5v input yielded a signal where the zero point was at 2.5v (Image 3).

∑ Signal output ∑ Ground ∑ Voltage input

Image 4: A representative diagram of a preamplified microphone.

OR M 2.5v

SOU ND W AVEF

INPUT VOLTAGE

A pre-amplified microphone converts sound into electrical signals and then amplifies the signal to a usable level. The microphone yields readings that extend to negative voltages. The amplification, apart from incteasing the amplitude of the signal, takes care of the issue with negative voltages and raises the whole signal to positive voltages, where to 0v in the unamplified signal becomes the midpoint of the new signal.

∑ Peak sound

∑ Absolute silence

∑ Lower limit

0v

TIME

Image 3: Waveform digram of the amplified signal from the microphone.

The voltage readings from the pre-amplified microphone which is in the range between 0v to 5v are converted into numerical equivalents in the range between 0 and 1023, with 0v corresponding to 0 and 5v corresponding to 1023 (right). This conversion is done by default by the Arduino when taking readings from the analog inputs.

1023

5v

2.5v

0v

=

512

0


||||||||||||||||||||||||||||| OUTPUT

Common anode RGB LED

The coloured light output is generated by common anode RGB LEDs. These LEDs have individual ground pins for each of the red, green and blue LEDs within it and a common anode for the voltage input. Each of the three individual LEDs are controlled separately through their separate ground pins.

∑ Blue LED ∑ Green LED ∑

Voltage input (common anode)

∑ Red LED

Image 5: A representative diagram of a common anode RGB LED.

The Ardunio uses a method called Pulse Width Modulation (PWM) to change the apparent brightness of each of the LEDs, individually. This is what allows the RGB LED to produce almost all the visible colours.

GREEN LEVEL π 255 ∂

FINAL COLOR π

RED LEVEL π ∑0

The brightness is divided into 255 levels. Since we are using a common anode LED, the darkest is at level 255 and the brightest is at 0 (right). For this project, we are using only the colours between green and red. A single value can determine the colour, using it in this case as the value for red while using the inverse as the value for green (right).

0∂

∑ 255


||||||||||||||||||||||||||||| ASSEMBLY

Completing the circuit

D1/TX

B

Arduino

D3 PWM

A0

D5 PWM

A1

D6 PWM

2

3

0

ON

TM

1

D2

ioref

RX0

4

1

)

TX0

5

6

7

8

9

10

11

12

13

DIGITAL (PWM=

L TX RX

ICSP

D0/RX

RESET2

G

GND

AREF

VIN

5V

ICSP2

R

Connecting the microphone The voltage input and ground are connected to their respective pins on the Arduino and the signal output is connected to the analog input pin 0 on the Arduino board.

Arduino UNO

A3

A5

A4

A3

A2

A1

A0

VIN

GND

GND

5V

3V3

ANALOG IN

D7 D8

A4/SDA

POWER

R1

R2

D9 PWM

Image 5: A schematic diagram of the circuit.

15

20

25

30

35

40

45

50

55

60

15

20

25

30

35

40

45

50

55

60

A B C D E

F G H

I

J

10 10

J

5

GND

N/C

5

D13/SCK

1

D12/MISO

1

D10 PWM/SS D11 PWM/MOSI

I

A5/SCL

F G H

A2

RESET

D4

A B C D E

GND

Pre-amplified AUD Microphone

RESET

RESET

AREF

Connecting the RGB LEDs The common anode of the LEDs are connected to the 5v rail. The pins for the red and green LEDs are connected to the digital output pins 11 and 10 on the Arduino board, with a 550 ohm resistor on the red pin and a 1k ohm resistor on the green pin.

IOREF

VCC

3V3

Making the circuit is fairly simple once all the components are at hand. All the tasks of signal conversion and analysing is done in code so the the pre-amplified microphone and the RGB LEDs are the only parts to be connected.

Image 6: A representative diagram of the circuit as it is on a breadboard with an Arduino UNO.


PRE-AMPLIFIED MICROPHONE

ARDUINO UNO

RGB LEDS

WIRES

RESISTORS (550 ohm & 1k ohm)

The list of necessary components

BREADBOARD


ARDUINO UNO

RGB LEDS

RESISTORS MICROPHONE Picture of the completed circuit


LEDs covered with paper for better colour reproduction

Picture of the working circuitry with the LEDs producing colours


25

30

35

40

45

50

55

60

25

30

35

40

45

50

55

60

J

20

20

I

15

15

F G H

10

10

A B C D E

5

J

5

I

GND

5V

3V3

RESET

POWER

Enlarged circuit diagram for reference RX0

0

2 1

TX0

3

4

5

6

7

8

9

10

11

12

13

GND

)

A5

ICSP

TM

A4

DIGITAL (PWM=

A3

A2

A1

A0

VIN

Arduino

GND

TX RX

1

F G H

ICSP2

1

A B C D E

IOREF

AREF

RESET

L ON 1

ANALOG IN


VIN

5V

3V3 VCC GND

Pre-amplified AUD Microphone

RESET

D0/RX

RESET2

D1/TX

AREF

G

B

D2

ioref

D3 PWM D4

A0

D5 PWM

A1

D6 PWM

A2

Arduino UNO

A3

D7 D8

A4/SDA

D9 PWM

A5/SCL

D10 PWM/SS D11 PWM/MOSI D12/MISO D13/SCK

GND

N/C

Enlarged schematic diagram for reference

R

R1

R2


||||||||||||||||||||||||||||| PROCESSING

Coding the Arduino

DESCRIPTION Store the numbers 10 and 11 as their pins in the variables "GREEN" and "RED" respectively Storing the values of the base of the signal input and its range. This may be changed after caliberating the microphone

Initializing the variables for recording the input signal

Initializing the variables for storing the red values for display in the LED

Initializing the variable for storing the change in the value of red Initializing the variables for storing values for calculating the rate of change of colour. The delay times are in milliseconds

Beginning the function setup() which runs once and sets the pins 10 and 11 stored in the variables "GREEN" and "RED" as digital outputs

CODE #define GREEN 10 #define RED 11 const int range = 400; const int base = 450; int currentMax = 0; int nextMax = 0; int newRed = 0; int oldRed = 0; int colourDiff = 0; int delayTime=15; const int delayDuration=15; const int maxDelay=20; void setup() { pinMode(GREEN, OUTPUT); pinMode(RED, OUTPUT); digitalWrite(GREEN, HIGH); digitalWrite(RED, HIGH); Serial.begin(9600);


End of the function setup()

Begin the function loop() which runs repeatedly

Conditional statement which runs everytime the reading is 0 (including the first run, where the variable "currentMax" has the value 0) Here, a thousand readings are taken from the mic (with a delay for stability) and the greatest reading is taken as the input value.

} void loop() { if(currentMax==0) { for(int i=0;i<1000;i++) { if(analogRead(0)>currentMax) currentMax=analogRead(0); delay(1); } Serial.println("first"); Serial.println(); }

Displaying the value of "currentMax" in the serial monitor for debugging and caliberation

Serial.print("currentMax: "); Serial.println(currentMax);

Begin the conditional statement to run if the input signal is within the expected range

if((currentMax>=base)&&(currentMax<(base+range))) {

Calling the functions "getRedVal()" and "getGreenVal" with the input signal as arguments and storing the returned values in their respective variables Displaying the value of "newRed" and "delayTime" in the serial monitor for debugging and caliberation

newRed = getRedVal(currentMax); delayTime = getDelay(currentMax);

Serial.print("newRed: "); Serial.println(newRed); Serial.print("delayTime: "); Serial.println(delayTime); Serial.println();


Begin conditional statement to run if the value of the red is increasing Here, the value of the green and red changes gradually to their target values while readings are being taken simultaneously

Storing the readings taken before to be used for the next colour change End of the conditional statement

Begin conditional statement to run if the value of the red is decreasing Here, the value of the green and red changes gradually to their target values while readings are being taken simultaneously

Storing the readings taken before to be used for the next colour change

if(newRed>oldRed) { colourDiff = newRed-oldRed; for( int i = 0 ; i < colourDiff ; i += 1 ) { oldRed += 1; analogWrite( GREEN, oldRed); analogWrite( RED,255 - oldRed ); delay(delayTime); if(analogRead(0)>nextMax) nextMax = analogRead(0); }

currentMax = nextMax; nextMax = 0;

}

else { colourDiff = oldRed-newRed; for( int i = 0 ; i < colourDiff ; i += 1 ) { oldRed -= 1; analogWrite( GREEN , oldRed); analogWrite( RED , 255 - oldRed ); delay(delayTime); if(analogRead(0)>nextMax) nextMax = analogRead(0); } } }

currentMax = nextMax; nextMax = 0;


Begin conditional statement to run if the value of the red is greater than the maximum Here, the value of the green and red changes gradually to their target values while readings are being taken simultaneously

else if(currentMax>(base+range)) { colourDiff = 255-oldRed; delayTime = maxDelay-delayDuration; for( int i = 0 ; i < colourDiff ; i += 1 ) { oldRed += 1; analogWrite( GREEN, oldRed); analogWrite( RED, 255 - oldRed ); delay(delayTime); if(analogRead(0)>nextMax) nextMax = analogRead(0); }

Storing the readings taken before to be used for the next colour change

End of the conditional statement

}

Begin conditional statement to run if the input value is invalid. Here, the value of the variable "cuttentMax" is set to zero so that fresh readings can be taken when the loop() function runs again The function"getDelay()" takes the integer of the current reading as the argument and returns the corresponding delay for the clour change. First the percentage of the input is calculated, which is then used to calculate the delay.

currentMax = nextMax; nextMax = 0;

else if(currentMax<base) { currentMax=0; }

} int getDelay(int input) { int percent = ((input-base)*100)/range; int tempDelay = maxDelay - ((delayDuration*percent)/100); if(tempDelay<0) tempDelay=tempDelay*(-1); return tempDelay; }


The function"getRedVal()" takes the integer of the current reading as the argument and returns the corresponding value of red. First the percentage of the input is calculated, which is then used to calculate the value of red from a range of 0 to 255. End of program

int getRedVal(int input) { int percent = ((input-base)*100)/range; int redVal = (255*percent)/100; if(redVal<0) redVal=redVal*(-1); return redVal; }


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.