Introduction: Noise by Light

About: Happiness is invisible? Then you cannot sell it? You cannot copy it nor like it:-) You have to arrive there yourself??? But i am just a consumer! See Baudrillard, La societe de consommation, p60....
This instructable is about using light variation, eg caused by passing people, to produce some funny noises.

Input: light
Output: ticks, clicks and tones
Energy: two AA batteries, 3V
Brain: Attiny45

How:
Soldering
Programming

Why?
There are many gadgets with sounds triggered on light. The fun is to make use of the input in a way that it changes as much as possible depending on conditions. This is done in the coding part, where the intensity and speed of the light change the LDR receives is used for generating as much as possible variation in pitch and length and alternations.

Step 1: Needed Components

Microcontroller:
Attiny45

Components:
holder for the chip
Resistor 4.7 K Ohm
LDR
PCB
Speaker 8 Ohm (for some speakers a capacitor)
some wires

Speakers
For bigger sound you can either use biggers speakers, or more voltage

Step 2: Needed Tools

Tools
Soldering device
pincher

Intelligent Things:
Programmer
Laptop with AVR Studio of Gcc on MAC

Step 3: Making: Soldering

Soldering the holder on the PCB

Adding the resistor, VCC and PB4
Soldering two wires for the LDR: GND and PB4
Soldering two wires for the battery, VCC and GND
Soldering two wires for the speaker, GND and PB3

So the GND has 4 wires
PB4 has two wires
PB3 has one wire.

Step 4: Making: Programming

You can either use a programmer like mkspiII for flashing the C file to the Attiny45
or this trick with the Arduino:
http://hlt.media.mit.edu/?p=1695

Step 5: Code of the Noise

We have two numbers for input:
  • change of light: how fast
  • length of change.
At the moment the script is using only: change of light: be creative and experiment introducing length of time of the change!

First I am reading the input value and comparing it to the former input value giving me the difference:

valueADC = adc_read(3);
diff = abs(valueADC - valueADC_old);

Pulse
Then I start a pulse depending on the difference:
if (diff > 64 )  _delay_ms(  20 );
if (diff > 32 )  _delay_ms(  4 );
if (diff > 16 )  _delay_ms(  10 );
if (diff > 8 )  _delay_ms(  3 );
if (diff > 4 ) _delay_ms(  2 );
if (diff > 1 ) _delay_ms(  1);
The delay gives me the tone pitch short delay high pitch
You can try out combinations of different pitches for different diff's.

Slow Stopping
The slow dying out of the noise is done with:
while( diff >0){
"do pulse"
diff=diff/2;
}
So getting a longer noise, going through some pitches, before stopping.

Download the code from: https://github.com/contrechoc/Noise

Step 6: The LDR

Using the light is done by the Light Dependent Resistor, in combination with a fixed resistor.
By attaching legs of both to the input PIN PB4 and the legs of each either to the GND or the V, you get a balancing act on the input PIN.

Step 7: Alternatives

For adding more sophisticated sound effect you can use the music shield for the Arduino.
Or a combination?

Then the attiny45 has too few PINS and you have to use either the Arduino board or an bare Atmega328