Parts & wiring

We all love stuff that’s home made, and what’s better than annoying noises brewed at home? In this project, you’ll be in full control of the noises the buzzer makes.

The program uses the light sensor to control the tone of the buzzer. If you move your hand closer to the sensor then the noise pitch will get lower, but if you take it away, it will get higher. But don’t forget to wait for 5 seconds after plugging your board into power before the noise begins.

What you’ll need for this project

To build this project, you will be using the following components:

Brain Board

Buzzer

Light Dependant Resistor

Light Sensor

Resistor

10k Resistor

How to connect the parts

To wire up this project, you’ll need your Brain Board, USB cable, buzzer, light sensor and 10k resistor. To connect your buzzer, slide its pins into the board as shown – the positive leg should go in PIN 11 and the negative leg should go in GND.

For both the LDR and the resistor, it doesn’t really matter which way you connect either of them. Slide one of the light sensor’s pins into the 5V pin on the board and the other into A0. Connect the resistor between GND and AO again.

Hover over the PLUS signs for extra tips

This is the positive leg of the buzzer. It will have a ‘+’ sign on top of it and will also be longer than the other leg.
Don’t forget to plug the board into your computer with the included USB cable.
For this to work, you’ll need to plug a leg from both the light sensor and the resistor into PIN A0.

The final program

Here’s the code we’ll be using to program this invention.
int LDR = A0;
int buzzer = 11;
int maxLight = 200;
int minLight = 0;
int light = 0;

void setup() {
    while(millis() < 5000) { light = analogRead(LDR); if(light > maxLight) maxLight = light;
      if(light < minLight) minLight = light;
    }
}

void loop() {
  light = analogRead(LDR);

  int pitch = map(light,minLight,maxLight,50,4000);

  tone(buzzer, pitch, 10);
  delay(5);
}