TinkerThon Module
TinkerThon Module
WEEK 1
🗣️“BUZZER”
What is a buzzer?
An audio signaling device which may be electromechanical or
piezoelectric or mechanical.
It converts the signal to sound.
Based on the various designs, it can generate different sounds
like alarm, music, bell & siren.
The pin configuration of the buzzer is shown below. It includes
two pins namely positive and negative. The positive terminal of
this is represented with the ‘+’ symbol or a longer terminal. This
terminal is powered through 6 Volts whereas the negative terminal
is represented with the ‘-‘symbol or short terminal and it is
connected to the GND terminal.
Working Principle:
The working principle of a buzzer,
specifically an electronic buzzer, is based on
the conversion of electrical energy into
sound. Piezoelectric buzzers use a
piezoelectric material (often a ceramic) that
deforms when an electrical voltage is applied
to it. This deformation creates mechanical
vibrations. These vibrations generate sound
waves in the audible frequency range.
Applications:
Communication Devices
Electronics used in Automobiles
Alarm Circuits
Portable Devices
Security Systems
PROJECT TIME!
It’s time to make some noise—literally! Say 🎶
hello to the Buzzer Project, your gateway to
creating interactive and sound-responsive
systems!
Project 1: Simple buzzer
Circuit diagram/ Arduino Code:
void setup() {
pinMode(buzzer, OUTPUT); // Set the buzzer pin as an output
}
void loop() {
tone(buzzer, 1000); // Send a 1 kHz sound signal to the buzzer
delay(1000); // Keep the sound on for 1 second
noTone(buzzer); // Stop the sound
delay(1000); // Wait for 1 second before repeating
}
int melody[] = {262, 294, 330, 349, 392, 440, 494, 523};
int noteDuration = 1000;
void setup() {
pinMode(8, OUTPUT);
//put this portion of the code inside the void loop if required.
for (int i = 0; i < 8; i++) {
tone(8, melody[i]);
delay(noteDuration);
noTone(8); // no tone for the duration specified by noteDuration
delay (noteDuration);
for (int j = 7: j >=0; j -- ) {
tone(8, melody[j]);
delay(noteDuration);
void loop() {
}
"Innovators, now let us understand each step of
the code. 🥁🎶
To produce SA-RI-GA-MA-PA we need different frequencies for
different notes. So if we declare every note and pass it to the
tone function it will become complex and lengthy code. To avoid
this we will go with an array concept and to produce every note
we will loop through it using for loop and array indices.
CODE
LED pin
int ledPin = 7;
// Button pin
int buttonPin - 2; void setup () f
// Set LED pin as output pinMode (ledPin, OUTPUT) :
// Set button pin as input with internal pull-up resistor
void 100p () I
/Read the state of the button pin int buttonState - digitalRead (buttonPin) ;
// Check if button is pressed
if (buttonState -= LOW) f
// Button pressed, turn LED On
digitalWrite (ledPin, HIGH) ;
else l
/ Button not pressed, turn LED Off digitalWrite (ledPin, LOW);
}
}
LETS GET A STEPWISE UNDERSTANDING
CODE
const int buttonfin - 2; const int ledPin - 9; / variables will, change:
int buttonState = 0; int count value =0: int prestate =0;
void setup () l
// initialize the LED pin as an output:
pinMode (LedFin, OUTPUT) :
// initialize the pushbutton pin as an input:
pinMode (buttonPin, INPUT) :
Serial. begin (9600) :
}
VOID LOOP(){
/ read the state of the pushoutton value:
buttonState = digitalRead (buttonPin) ;
// check if the pushbutton is pressed. If it 19, then the buttonstate is HIGH:
it (buttonState - HIGH && prestate -- 0) l
count value++:
Serial. printin (count_value) ;
// turn LED on digitalWrite (ledPin, HIGH) :
delay (100) ;
//turn TED off
digitalWrite (ledPin, LOW):
prestate =1;
}
else if (buttonstate LOW) t
prestate = 0;
}
CODE EXPLANATION
CODE EXPLANATION
buttonPin: The pin connected to the pushbutton (digital pin 2).
ledPin: The pin connected to the LED (digital pin 9).
buttonState: Holds the current state of the pushbutton (HIGH when
pressed, LOW otherwise).
count_value: Tracks how many times the button has been pressed.
prestate: Stores the previous state of the button to detect a
transition from unpressed to pressed.
setup()Function
setup() Function :
pinMode(ledPin, OUTPUT): Configures the ledPin (9) as an output
pin to control the LED.
pinMode(buttonPin, INPUT): Configures the buttonPin (2) as an
input pin to read the state of the pushbutton.
Serial.begin(9600): Initializes serial communication at 9600 baud,
enabling you to send data to the Serial Monitor for debugging.
loop()Function:
loop() Function:
buttonState = digitalRead(buttonPin): Reads the current state of the
pushbutton (HIGH when pressed, LOW otherwise) and stores it in
buttonState.
DetectingaaButton
Detecting ButtonPress:
Press:
buttonState == HIGH: The button is currently pressed.
prestate == 0: Ensures this is a new press (the button was not
pressed in the previous loop iteration).
Increment
IncrementCounter:
Counter:
count_value++: Increments the counter by 1 to track the number of
button presses.
Serial.println(count_value): Sends the updated count to the Serial
Monitor for debugging or display.
Control the LED:
digitalWrite(ledPin, HIGH): Turns the LED on.
delay(100): Keeps the LED on for 100 milliseconds.
digitalWrite(ledPin, LOW): Turns the LED off after the delay.
Sets prestate to 1 to indicate that the button is currently pressed,
ensuring the counter does not increment repeatedly while the button
remains pressed.
buttonState == LOW: Detects when the button is released.
prestate = 0: Resets prestate to allow detecting a new button press in
the next loop iteration.
🗣️“LED”
What is LED?
LED (Light Emitting Diode) is a semiconductor device that produces light when an
electric current passes through it.
It operates based on the principle of electroluminescence, where energy released by
electrons recombining with holes in the semiconductor emits photons, creating light.
Working of LED
The electrons are majority carriers in N-type and holes are majority carriers in P-
type.
The electrons of N-type are in the conduction band and holes of P-type are in the
valence band. The energy level of the Conduction band is higher than the energy
level of the Valence band.
If electrons tend to recombine with holes they have to lose some part of the energy
to fall in the lower energy band.
The electrons can lose their energy either in the form of heat or light. The electrons
LED
in Silicon and Germanium lose their energy in the form of heat.
Thus, they are not used for LEDs as we want semiconductors in which electrons lose
their energy in the form of light.
The primary materials that are used are Gallium Arsenide(GaAS),Aluminium gallium
arsenide(AlGaAs).
APPLICATIONS:
Lighting
Displays
Automotive
Medical: Applied in surgical
lights, phototherapy, and
endoscopy lighting.
Consumer Electronics:
Backlighting for smartphones,
laptops, and wearables.
🗣️TIME FOR SOME PROJECTS
Project 1: BLINKING OF LED
CODE BLOCK
CIRCUIT DIAGRAM:
void setup() {
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
EXPLANATION: }
void setup() {
int p=0;
void setup()
{
pinMode (9, OUTPUT);
pinMode (A5, INPUT);
}
EXPLANATION: void loop()
🗣️ :”LET ME BREAKDOWN
{
p-analogRead (A5);
THE CODE FOR YOU” digitalWrite(9, HIGH);
delay(p); // Wait for 1000
analogRead(A5): Reads the analog
millisecond(s)
value from pin A5, which can range digitalWrite(9, LOW);
from 0 to 1023. This value is stored in delay(p); // Wait for 1000
the variable p. millisecond(s)
digitalWrite(9, HIGH): Sets pin 9 to }
HIGH (turning on the LED or buzzer).
delay(p): The delay is based on the
analog reading from pin A5, making
the delay vary depending on the
input.
digitalWrite(9, LOW): Turns off pin 9 (turning off the LED or
buzzer).
delay(p): Waits again before repeating the loop.
Controlling Buzzer :
CIRCUIT DIAGRAM:
CODE BLOCK
CIRCUIT DIAGRAM: