SlideShare a Scribd company logo
1 of 8
INGREDIENTS
10 KILOHM RESISTOR
PHOTORESISTOR
PIEZO
06
A theremin is an instrument that makes sounds based on the movements of
a musician’s hands around the instrument. You’ve probably heard one in scary
movies. The theremin detects where a performer’s hands are in relation to two
antennas by reading the capacitive change on the antennas. These antennas are
connected to analog circuitry that create the sound. One antenna controls the
frequency of the sound and the other controls volume. While the Arduino can’t
exactly replicate the mysterious sounds from this instrument, it is possible to
emulate them using the tone() function. Fig. 1shows the difference between
the pulses emitted by analogWrite() and tone(). This enables a transducer
like a speaker or piezo to move back and forth at different speeds.
TIME TO MAKE SOME NOISE! USING A PHOTORESISTOR
AND A PIEZO ELEMENT, YOU’RE GOING TO MAKE A
LIGHT-BASED THEREMIN
Discover: making sound with the tone() function, calibrating
analog sensors
Time: 45 MINUTES Builds on projects: 1,2, 3,4
Level:
LIGHT
THEREMIN
Fig.1 10MILLISECONDS
Noticehowthevoltageishighmostofthe
time,butthefrequencyisthesameasPWM50.
PWM 200: analogWrite(200)
PERIOD
0
5
PERIOD
Noticehowthesignalislowmostofthetime,
butthefrequencyisthesameasPWM200.
PWM 50: analogWrite(50)
0
5
Thedutycycleis50%(onhalfthetime,offhalf
thetime),butthefrequencychanges.
TONE 440: tone(9,440)
0
5
PERIOD
SamedutycycleasT
one440;buttwicethe
frequency.
TONE 880: tone(9,880)
0
5
PERIOD
71
+ - + -
+ -
+ -
Instead of sensing capacitance with the Arduino, you’ll be using a photoresistor
to detect the amount of light. By moving your hands over the sensor, you’ll
change the amount of light that falls on the photoresistor’s face, as you did
in Project 4. The change in the voltage on the analog pin will determine what
frequency note to play.
You’ll connect the photoresistors to the Arduino using a voltage divider circuit like
you did in Project 4.You probably noticed in the earlier project that when you read
this circuit using analogRead(), your readings didn’t range all the way from 0
to 1023. The fixed resistor connecting to ground limits the low end of the range,
and the brightness of your light limits the high end. Instead of settling for a limited
range,you’ll calibratethe sensor readings getting the high and low values,mapping
them to sound frequencies using the map() function to get as much range out of
your theremin as possible. This will have the added benefit of adjusting the sensor
readings whenever you move your circuit to a new environment, like a room with
different light conditions.
A piezo isa smallelement that vibrateswhen itreceiveselectricity. When itmoves,
it displaces air around it,creating sound waves.
BUILD THE
CIRCUIT
Fig.2
72 Project 06
Light Theremin
Fig.3
On your breadboard, connect the outer bus lines to power and
ground.
Take your piezo, and connect one end to ground, and the other
to digital pin 8 on the Arduino.
Place your photoresistor on the breadboard, connecting one
end to 5V. Connect the other end to the Arduino’s analogIn pin
0, and to ground through a 10-kilohm resistor. This circuit is the
same as the voltage divider circuit in Project 4.
Traditional theremins can control the frequency and the volume of sound. In this
example, You’ll be able to control the frequency only. While you can’t control the
volume through the Arduino, it is possible to change the voltage level that gets
to the speaker manually. What happens if you put a potentiometer in series with
pin 8 and the piezo? What about another photoresistor?
❶
❷
❸
73
Create a variable to hold the analogRead() value from the
photoresistor. Next, create variables for the high and low values.
You’re going to set the initial value in the sensorLow variable to
1023, and set the value of the sensorHigh variable to 0. When
you first run the program, you’ll compare these numbers to the
sensor’sreadings to find the real maximum and minimum values.
Create a constant named ledPin. You’ll use this as an indicator
that your sensor has finished calibrating. For this project, use the
on-board LED connected to pin 13.
In the setup(), change the pinMode() of ledPin to OUTPUT,
and turn the light on.
The next steps will calibratethe sensor’s maximum and minimum
values. You’ll use a while() statement to run a loop for 5
seconds. while() loops run until a certain condition is met. In
this case you’re going to use the millis() function to check
the current time. millis() reports how long the Arduino has
been running since it was last powered on or reset.
In the loop, you’ll read the value of the sensor; if the value is less
than sensorLow (initially 1023), you’ll update that variable. If
it is greater than sensorHigh (initially 0), that gets updated.
When 5 seconds have passed, the while() loop will end. Turn off
the LED attached to pin 13. You’ll use the sensor high and low
values just recorded to scale the frequency in the main part of
your program.
THE CODE
Create variables for
calibrating the sensor
Nameaconstantfor your
calibration indicator
Set digital pindirection and
turn it high
Use awhile() loop for
calibration
Compare sensor values for
calibration
Indicate calibration has
finished
74 Project 06
Light Theremin
1 int sensorVaLue;
2 int sensorLow = 1023;
3 int sensorHigh = 0;
4 const int LedPin = 13;
5 void setup() {
6 pinMode(LedPin, OUTPUT);
7 digitaLWrite(LedPin, HIGH);
8 whiLe (miLLis() < 5000) {
sensorVaLue = anaLogRead(A0);
if (sensorVaLue > sensorHigh) {
sensorHigh = sensorVaLue;
}
if (sensorVaLue < sensorLow) {
sensorLow = sensorVaLue;
}
9
10
11
12
13
14
15
16 }
17 digitaLWrite(LedPin, LOW);
18 }
while()
arduino.cc/while
75
Intheloop(),readthevalueon A0 andstoreitinsensorValue.
Create a variable named pitch. The value of pitch is going
to be mapped from sensorValue. Use sensorLow and
sensorHigh as the bounds for the incoming values. For starting
values for output, try 50 to 4000. These numbers set the range
of frequencies the Arduino will generate.
Next, call the tone() function to play a sound. It takes three
arguments : what pin to play the sound on (in this case pin 8),
what frequency to play (determined by the pitch variable), and
how long to play the note (try 20 milliseconds to start).
Then, call a delay() for 10 milliseconds to give the sound some
time to play.
When you first power the Arduino on, there is a 5 second win-
dow for you to calibrate the sensor. To do this, move your
hand up and down over the photoresistor, changing the
amount of light that reaches it. The closer you replicate the
motions you expect to use while playing the instrument, the
better the calibration will be.
After 5 seconds, the calibration will be complete, and the LED
on the Arduino will turn off. When this happens, you should
hear some noise coming from the piezo! As the amount of
light that falls on the sensor changes, so should the frequency
that the piezo plays.
USE IT
Readandstore the sensor
value
Mapthe sensor value to a
frequency
Play the frequency
76 Project 06
Light Theremin
19 void Loop() {
20 sensorVaLue = anaLogRead(A0);
21 int pitch =
map(sensorVaLue,sensorLow,sensorHigh, 50, 4000);
22 tone(8,pitch,20);
23deLay(10);
24 }
The range in the map() function that determines the pitch is pretty wide, try
changing the frequencies to find ones that are the right fit for your musical style.
Thetone() functionoperatesverymuch likethePWM inanalogWrite() butwith
one significantdifference.In analogWrite() the frequencyis fixed;you change the
ratio of the pulses in that period of time to vary the duty cycle. With tone() you’re
still sending pulses, but changing the frequency of them. tone() always pulses at a
50% duty cycle (half the time the pin ishigh,the other half the time itislow).
Thetone()functiongivesyoutheabilitytogeneratedifferent
frequencies when it pulses a speaker or piezo.When using
sensors ina voltage dividercircuit,you probablywon’tget a
fullrange of values between 0-1023. By calibrating sensors,
it’spossible to map your inputs to a useablerange.
77

More Related Content

Similar to Electronz_Chapter_6.pptx

Porte à puce - Smart Safety Door based on Arduino UNO R3
Porte à puce - Smart Safety Door based on Arduino UNO R3Porte à puce - Smart Safety Door based on Arduino UNO R3
Porte à puce - Smart Safety Door based on Arduino UNO R3Meifani Sumadijaya
 
Smart Safety Door based on Arduino Uno R3
Smart Safety Door based on Arduino Uno R3Smart Safety Door based on Arduino Uno R3
Smart Safety Door based on Arduino Uno R3Ziddan Kundrat
 
Smart Safety Door with Servo Motors as Actuators, Passcode and DHT Sensors B...
Smart Safety Door with Servo Motors as Actuators, Passcode and DHT Sensors  B...Smart Safety Door with Servo Motors as Actuators, Passcode and DHT Sensors  B...
Smart Safety Door with Servo Motors as Actuators, Passcode and DHT Sensors B...Faqih Fadhila Ardiansyah
 
Color Sensor.pptx
Color Sensor.pptxColor Sensor.pptx
Color Sensor.pptxRituSachan2
 
Automatic Door Opener using PIR Sensor
Automatic Door Opener using PIR SensorAutomatic Door Opener using PIR Sensor
Automatic Door Opener using PIR SensorRAGHUVARMA09
 
INT4073 L07(Sensors and AcutTORS).pdf
INT4073 L07(Sensors and AcutTORS).pdfINT4073 L07(Sensors and AcutTORS).pdf
INT4073 L07(Sensors and AcutTORS).pdfMSingh88
 
Arduino Workshop (3).pptx
Arduino Workshop (3).pptxArduino Workshop (3).pptx
Arduino Workshop (3).pptxHebaEng
 
Arduino frequency counter
Arduino frequency counterArduino frequency counter
Arduino frequency counternasyith_hananur
 
ESD_Project-Report
ESD_Project-ReportESD_Project-Report
ESD_Project-ReportAhmad Faizan
 
Robotics and Automation Using Arduino
Robotics and Automation Using ArduinoRobotics and Automation Using Arduino
Robotics and Automation Using ArduinoABHISHEKJAISWAL282
 
Biomedical Instrumentation Presentation on Infrared Emitter-Detector and Ardu...
Biomedical Instrumentation Presentation on Infrared Emitter-Detector and Ardu...Biomedical Instrumentation Presentation on Infrared Emitter-Detector and Ardu...
Biomedical Instrumentation Presentation on Infrared Emitter-Detector and Ardu...Redwan Islam
 
Persistence of Vision Display
Persistence of Vision DisplayPersistence of Vision Display
Persistence of Vision DisplayUday Wankar
 

Similar to Electronz_Chapter_6.pptx (20)

Porte à puce - Smart Safety Door based on Arduino UNO R3
Porte à puce - Smart Safety Door based on Arduino UNO R3Porte à puce - Smart Safety Door based on Arduino UNO R3
Porte à puce - Smart Safety Door based on Arduino UNO R3
 
Smart Safety Door based on Arduino Uno R3
Smart Safety Door based on Arduino Uno R3Smart Safety Door based on Arduino Uno R3
Smart Safety Door based on Arduino Uno R3
 
Smart Safety Door with Servo Motors as Actuators, Passcode and DHT Sensors B...
Smart Safety Door with Servo Motors as Actuators, Passcode and DHT Sensors  B...Smart Safety Door with Servo Motors as Actuators, Passcode and DHT Sensors  B...
Smart Safety Door with Servo Motors as Actuators, Passcode and DHT Sensors B...
 
Color Sensor.pptx
Color Sensor.pptxColor Sensor.pptx
Color Sensor.pptx
 
Automatic Door Opener using PIR Sensor
Automatic Door Opener using PIR SensorAutomatic Door Opener using PIR Sensor
Automatic Door Opener using PIR Sensor
 
Fun with arduino
Fun with arduinoFun with arduino
Fun with arduino
 
INT4073 L07(Sensors and AcutTORS).pdf
INT4073 L07(Sensors and AcutTORS).pdfINT4073 L07(Sensors and AcutTORS).pdf
INT4073 L07(Sensors and AcutTORS).pdf
 
Arduino Workshop (3).pptx
Arduino Workshop (3).pptxArduino Workshop (3).pptx
Arduino Workshop (3).pptx
 
Arduino
ArduinoArduino
Arduino
 
Arduino frequency counter
Arduino frequency counterArduino frequency counter
Arduino frequency counter
 
ir sensor.docx
ir sensor.docxir sensor.docx
ir sensor.docx
 
Chapter 9.pptx
Chapter 9.pptxChapter 9.pptx
Chapter 9.pptx
 
ESD_Project-Report
ESD_Project-ReportESD_Project-Report
ESD_Project-Report
 
Robotics and Automation Using Arduino
Robotics and Automation Using ArduinoRobotics and Automation Using Arduino
Robotics and Automation Using Arduino
 
Child Pneumonia Monitor
Child Pneumonia Monitor Child Pneumonia Monitor
Child Pneumonia Monitor
 
Sensors.pptx
Sensors.pptxSensors.pptx
Sensors.pptx
 
Radar Detector
Radar Detector Radar Detector
Radar Detector
 
Final year Engineering project
Final year Engineering project Final year Engineering project
Final year Engineering project
 
Biomedical Instrumentation Presentation on Infrared Emitter-Detector and Ardu...
Biomedical Instrumentation Presentation on Infrared Emitter-Detector and Ardu...Biomedical Instrumentation Presentation on Infrared Emitter-Detector and Ardu...
Biomedical Instrumentation Presentation on Infrared Emitter-Detector and Ardu...
 
Persistence of Vision Display
Persistence of Vision DisplayPersistence of Vision Display
Persistence of Vision Display
 

More from Mokete5

Electronz_Chapter_13.pptx
Electronz_Chapter_13.pptxElectronz_Chapter_13.pptx
Electronz_Chapter_13.pptxMokete5
 
Electronz_Chapter_14.pptx
Electronz_Chapter_14.pptxElectronz_Chapter_14.pptx
Electronz_Chapter_14.pptxMokete5
 
Electronz_Chapter_12.pptx
Electronz_Chapter_12.pptxElectronz_Chapter_12.pptx
Electronz_Chapter_12.pptxMokete5
 
Electronz_Chapter_8.pptx
Electronz_Chapter_8.pptxElectronz_Chapter_8.pptx
Electronz_Chapter_8.pptxMokete5
 
Electronz_Chapter_10.pptx
Electronz_Chapter_10.pptxElectronz_Chapter_10.pptx
Electronz_Chapter_10.pptxMokete5
 
Electronz_Chapter_7.pptx
Electronz_Chapter_7.pptxElectronz_Chapter_7.pptx
Electronz_Chapter_7.pptxMokete5
 
Electronz_Chapter_15.pptx
Electronz_Chapter_15.pptxElectronz_Chapter_15.pptx
Electronz_Chapter_15.pptxMokete5
 
Electronz_Chapter_11.pptx
Electronz_Chapter_11.pptxElectronz_Chapter_11.pptx
Electronz_Chapter_11.pptxMokete5
 
Electronz_Chapter_2.pptx
Electronz_Chapter_2.pptxElectronz_Chapter_2.pptx
Electronz_Chapter_2.pptxMokete5
 
Elecronz_Chapter_1.pptx
Elecronz_Chapter_1.pptxElecronz_Chapter_1.pptx
Elecronz_Chapter_1.pptxMokete5
 
Electronz_Introduction.pptx
Electronz_Introduction.pptxElectronz_Introduction.pptx
Electronz_Introduction.pptxMokete5
 

More from Mokete5 (11)

Electronz_Chapter_13.pptx
Electronz_Chapter_13.pptxElectronz_Chapter_13.pptx
Electronz_Chapter_13.pptx
 
Electronz_Chapter_14.pptx
Electronz_Chapter_14.pptxElectronz_Chapter_14.pptx
Electronz_Chapter_14.pptx
 
Electronz_Chapter_12.pptx
Electronz_Chapter_12.pptxElectronz_Chapter_12.pptx
Electronz_Chapter_12.pptx
 
Electronz_Chapter_8.pptx
Electronz_Chapter_8.pptxElectronz_Chapter_8.pptx
Electronz_Chapter_8.pptx
 
Electronz_Chapter_10.pptx
Electronz_Chapter_10.pptxElectronz_Chapter_10.pptx
Electronz_Chapter_10.pptx
 
Electronz_Chapter_7.pptx
Electronz_Chapter_7.pptxElectronz_Chapter_7.pptx
Electronz_Chapter_7.pptx
 
Electronz_Chapter_15.pptx
Electronz_Chapter_15.pptxElectronz_Chapter_15.pptx
Electronz_Chapter_15.pptx
 
Electronz_Chapter_11.pptx
Electronz_Chapter_11.pptxElectronz_Chapter_11.pptx
Electronz_Chapter_11.pptx
 
Electronz_Chapter_2.pptx
Electronz_Chapter_2.pptxElectronz_Chapter_2.pptx
Electronz_Chapter_2.pptx
 
Elecronz_Chapter_1.pptx
Elecronz_Chapter_1.pptxElecronz_Chapter_1.pptx
Elecronz_Chapter_1.pptx
 
Electronz_Introduction.pptx
Electronz_Introduction.pptxElectronz_Introduction.pptx
Electronz_Introduction.pptx
 

Recently uploaded

High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 

Recently uploaded (20)

High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 

Electronz_Chapter_6.pptx

  • 2. A theremin is an instrument that makes sounds based on the movements of a musician’s hands around the instrument. You’ve probably heard one in scary movies. The theremin detects where a performer’s hands are in relation to two antennas by reading the capacitive change on the antennas. These antennas are connected to analog circuitry that create the sound. One antenna controls the frequency of the sound and the other controls volume. While the Arduino can’t exactly replicate the mysterious sounds from this instrument, it is possible to emulate them using the tone() function. Fig. 1shows the difference between the pulses emitted by analogWrite() and tone(). This enables a transducer like a speaker or piezo to move back and forth at different speeds. TIME TO MAKE SOME NOISE! USING A PHOTORESISTOR AND A PIEZO ELEMENT, YOU’RE GOING TO MAKE A LIGHT-BASED THEREMIN Discover: making sound with the tone() function, calibrating analog sensors Time: 45 MINUTES Builds on projects: 1,2, 3,4 Level: LIGHT THEREMIN Fig.1 10MILLISECONDS Noticehowthevoltageishighmostofthe time,butthefrequencyisthesameasPWM50. PWM 200: analogWrite(200) PERIOD 0 5 PERIOD Noticehowthesignalislowmostofthetime, butthefrequencyisthesameasPWM200. PWM 50: analogWrite(50) 0 5 Thedutycycleis50%(onhalfthetime,offhalf thetime),butthefrequencychanges. TONE 440: tone(9,440) 0 5 PERIOD SamedutycycleasT one440;buttwicethe frequency. TONE 880: tone(9,880) 0 5 PERIOD 71
  • 3. + - + - + - + - Instead of sensing capacitance with the Arduino, you’ll be using a photoresistor to detect the amount of light. By moving your hands over the sensor, you’ll change the amount of light that falls on the photoresistor’s face, as you did in Project 4. The change in the voltage on the analog pin will determine what frequency note to play. You’ll connect the photoresistors to the Arduino using a voltage divider circuit like you did in Project 4.You probably noticed in the earlier project that when you read this circuit using analogRead(), your readings didn’t range all the way from 0 to 1023. The fixed resistor connecting to ground limits the low end of the range, and the brightness of your light limits the high end. Instead of settling for a limited range,you’ll calibratethe sensor readings getting the high and low values,mapping them to sound frequencies using the map() function to get as much range out of your theremin as possible. This will have the added benefit of adjusting the sensor readings whenever you move your circuit to a new environment, like a room with different light conditions. A piezo isa smallelement that vibrateswhen itreceiveselectricity. When itmoves, it displaces air around it,creating sound waves. BUILD THE CIRCUIT Fig.2 72 Project 06 Light Theremin
  • 4. Fig.3 On your breadboard, connect the outer bus lines to power and ground. Take your piezo, and connect one end to ground, and the other to digital pin 8 on the Arduino. Place your photoresistor on the breadboard, connecting one end to 5V. Connect the other end to the Arduino’s analogIn pin 0, and to ground through a 10-kilohm resistor. This circuit is the same as the voltage divider circuit in Project 4. Traditional theremins can control the frequency and the volume of sound. In this example, You’ll be able to control the frequency only. While you can’t control the volume through the Arduino, it is possible to change the voltage level that gets to the speaker manually. What happens if you put a potentiometer in series with pin 8 and the piezo? What about another photoresistor? ❶ ❷ ❸ 73
  • 5. Create a variable to hold the analogRead() value from the photoresistor. Next, create variables for the high and low values. You’re going to set the initial value in the sensorLow variable to 1023, and set the value of the sensorHigh variable to 0. When you first run the program, you’ll compare these numbers to the sensor’sreadings to find the real maximum and minimum values. Create a constant named ledPin. You’ll use this as an indicator that your sensor has finished calibrating. For this project, use the on-board LED connected to pin 13. In the setup(), change the pinMode() of ledPin to OUTPUT, and turn the light on. The next steps will calibratethe sensor’s maximum and minimum values. You’ll use a while() statement to run a loop for 5 seconds. while() loops run until a certain condition is met. In this case you’re going to use the millis() function to check the current time. millis() reports how long the Arduino has been running since it was last powered on or reset. In the loop, you’ll read the value of the sensor; if the value is less than sensorLow (initially 1023), you’ll update that variable. If it is greater than sensorHigh (initially 0), that gets updated. When 5 seconds have passed, the while() loop will end. Turn off the LED attached to pin 13. You’ll use the sensor high and low values just recorded to scale the frequency in the main part of your program. THE CODE Create variables for calibrating the sensor Nameaconstantfor your calibration indicator Set digital pindirection and turn it high Use awhile() loop for calibration Compare sensor values for calibration Indicate calibration has finished 74 Project 06 Light Theremin
  • 6. 1 int sensorVaLue; 2 int sensorLow = 1023; 3 int sensorHigh = 0; 4 const int LedPin = 13; 5 void setup() { 6 pinMode(LedPin, OUTPUT); 7 digitaLWrite(LedPin, HIGH); 8 whiLe (miLLis() < 5000) { sensorVaLue = anaLogRead(A0); if (sensorVaLue > sensorHigh) { sensorHigh = sensorVaLue; } if (sensorVaLue < sensorLow) { sensorLow = sensorVaLue; } 9 10 11 12 13 14 15 16 } 17 digitaLWrite(LedPin, LOW); 18 } while() arduino.cc/while 75
  • 7. Intheloop(),readthevalueon A0 andstoreitinsensorValue. Create a variable named pitch. The value of pitch is going to be mapped from sensorValue. Use sensorLow and sensorHigh as the bounds for the incoming values. For starting values for output, try 50 to 4000. These numbers set the range of frequencies the Arduino will generate. Next, call the tone() function to play a sound. It takes three arguments : what pin to play the sound on (in this case pin 8), what frequency to play (determined by the pitch variable), and how long to play the note (try 20 milliseconds to start). Then, call a delay() for 10 milliseconds to give the sound some time to play. When you first power the Arduino on, there is a 5 second win- dow for you to calibrate the sensor. To do this, move your hand up and down over the photoresistor, changing the amount of light that reaches it. The closer you replicate the motions you expect to use while playing the instrument, the better the calibration will be. After 5 seconds, the calibration will be complete, and the LED on the Arduino will turn off. When this happens, you should hear some noise coming from the piezo! As the amount of light that falls on the sensor changes, so should the frequency that the piezo plays. USE IT Readandstore the sensor value Mapthe sensor value to a frequency Play the frequency 76 Project 06 Light Theremin
  • 8. 19 void Loop() { 20 sensorVaLue = anaLogRead(A0); 21 int pitch = map(sensorVaLue,sensorLow,sensorHigh, 50, 4000); 22 tone(8,pitch,20); 23deLay(10); 24 } The range in the map() function that determines the pitch is pretty wide, try changing the frequencies to find ones that are the right fit for your musical style. Thetone() functionoperatesverymuch likethePWM inanalogWrite() butwith one significantdifference.In analogWrite() the frequencyis fixed;you change the ratio of the pulses in that period of time to vary the duty cycle. With tone() you’re still sending pulses, but changing the frequency of them. tone() always pulses at a 50% duty cycle (half the time the pin ishigh,the other half the time itislow). Thetone()functiongivesyoutheabilitytogeneratedifferent frequencies when it pulses a speaker or piezo.When using sensors ina voltage dividercircuit,you probablywon’tget a fullrange of values between 0-1023. By calibrating sensors, it’spossible to map your inputs to a useablerange. 77