Arduino Projects Experiments Part12
Arduino Projects Experiments Part12
The Metronome
Figure 25-2. Servo motor attachment to breadboard: the free wire ends are inserted into the
breadboard
The 10K potentiometer is used as a volume control to adjust the sound level of
the piezo buzzer. A cool trick used to make the tick sound, along with adjusting
the volume, is to place a small piece of tape over the piezo buzzer. Figure 25-3 shows
the location of the volume control, and the piezo buzzer with tape placed over it.
The Fritzing wiring diagram for building the Metronome is shown in Figure 25-4. As
with previous projects presented in this book, the MakerShield protoboard is a great
prototyping tool to use in building this cool mini Metronome device. Its breadboarding area allows the piezo buzzer, potentiometer, and servo motor components
to be wired to the Arduino microcontroller in a compact package.
223
225
#include <Servo.h>
Servo myservo;
int pos = 0;
// variable to store the servo position
int PBuzzer = 7; // piezo buzzer pin number
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(PBuzzer, OUTPUT);
}
void loop()
{
for(pos = 0; pos <=45; pos += 1) // goes from 0 degrees to 45 degrees
{
// in steps of 1 degree
if(pos==45){
digitalWrite(PBuzzer, LOW);
delay(15);
digitalWrite(PBuzzer, HIGH);
delay(15);
digitalWrite(PBuzzer, LOW);
delay(15);
}
myservo.write(pos);
// go to position in variable 'pos'
delay(15);
// waits 15ms to reach the position
}
for(pos = 45; pos>=1; pos-=1)
{
if (pos==1){
digitalWrite(PBuzzer, LOW);
delay(15);
digitalWrite(PBuzzer, HIGH);
delay(15);
digitalWrite(PBuzzer, LOW);
227
229
Figure 26-3. The Secret Word Game starting its timing sequence using the RGB LED
Once the RGB LED has turned off, shining a light on the photocell will reveal the
secret word on the LCD (Figure 26-4). Removing the light from the photocell will
erase the secret word on the LCD. New secret words can easily be uploaded to the
Arduino by changing one line of instruction in the sketch.
Figure 26-4. The secret word Cat being revealed on the LCD
Example 26-1. The Secret Word Game sketch
/*
Demonstrates the use of a 16x2 LCD. A brief press of the Start Game
pushbutton will turn on the RGB LED timing sequencing. The RGB LED turns
off and the secret word can be revealed by a shining light on a photocell.
25 August 2013
by Don Wilcher
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library
LiquidCrystal lcd(12, 11,
int buttonPin = 6;
//
int RPin = 7;
//
int GPin = 8;
//
int BPin = 9;
//
235
236
Figure 26-6. The Secret Word Game Fritzing circuit schematic diagram
Index
Symbols
!= (logical NOT function), 47
&& (logical AND function), 58
100 uF electrolytic capacitor, 105
|| (logical OR function), 66
(omega symbol), for ohms, 32
A
Adjustable Twin LED Flasher, 35
sketch, 39
Amazing Pushbutton (with Processing),
143156
Amazing Pushbutton in action, 153
building, 144
DisplayItems Processing sketch, 152
153
downloading and installing Processing,
148
parts list, 143
pa_Pushbutton Processing sketch,
149152
uploading the sketch, 146
visualizing digital data with Processing,
148
amplifiers
simple transistor amplifier, 103110
building a Theremin, 104
circuit theory, 109
parts list, 103
uploading Theremin sketch, 106
using Serial Monitor for Theremin
sketch data, 108
AND logic gate, 51
(see also Arduino AND logic gate)
circuit symbol for, 54
reasons to use Arduino microcontroller
to build, 55
truth table, 54
animatronic controllers, 24
Arduino AND logic gate, 5159
block diagram and circuit schematic diagram, 59
building, 55
circuit theory, 52
parts list, 51
uploading sketch for, 57
Arduino IDE
Serial Monitor, 14
Arduino NOT logic gate, 4350
block diagram and circuit schematic diagram, 49
building, 45
circuit symbol for NOT logic gate, 45
circuit theory, 44
Fritzing wiring diagram, 45
parts list, 43
pressing pushbutton switch, 47
testing using truth table, 49
truth table, 45
uploading logic gate sketch, 46
Arduino Ohmmeter, 111117
building, 112
circuit theory, 115
electrical safety tip, 117
parts list, 111
uploading the sketch, 113
Arduino OR logic gate, 6169
block diagram and circuit schematic diagram, 68
building, 64
circuit theory, 62
parts list, 61
uploading scheme for, 66
B
binary number system, 172
block diagrams, 135
C
capacitors, polarized, 106
cathodes, 85
Circuit Lab, 2
circuit schematic diagrams (see electronic
circuit schematic diagrams)
circuit symbol
for AND logic gate, 54
239
D
DC motors, 197
DMM (digital multimeter), 14
reading resistance of tilt control switch,
26
DPDT (double pole, double throw) switch,
214
E
electrical circuits, creating and testing with
online simulator, 2
Electrical Motor Tester (see Sweeping Servo)
electrical safety tips
for Arduino Ohmmeter, 117
for Metal Checker, 101
electrical signal flow of electronic products,
135
electronic circuit schematic diagrams, 15
Adjustable Twin LED Flasher, 35
AND logic gate controlling LED, 53
Arduino AND logic gate, 59
Arduino NOT logic gate, 49
Arduino Ohmmeter, 115
Arduino OR logic gate, 68
DPDT switch toggling two LEDs, 72
Electronic Cricket, 203
Electronic Pixel, 218
Interactive Twin LED Flasher, 38
LCD News Reader, 128
Logic Tester, 135
Logic Tester (with an LCD), 141
Magic Light Bulb, 91
Metal Checker, 100
Metronome, 228
OR logic gate controlling an LED, 62
Pocket Stage Light, 210
RGB Flasher, 81
Rocket Game, 181
Secret Word Game, 237
Servo Motor Tester, 197
Terrific Tilt Switch, 167
240
Index
Theremin, 109
Tilt Sensing Servo Motor Controller, 26
Trick Switch, 6
Up-Down Sensor, 73
Electronic Cricket, 199204
block diagram and circuit schematic diagram of Electronic Cricket, 203
building, 200
parts list, 199
uploading the sketch, 201
electronic metronomes, 221
Electronic Pixel, 213219
block diagram and circuit schematic diagram, 218
building, 214
parts list, 213
uploading the sketch, 216218
F
FALSE and TRUE states, 52
for loop, operating Magic Light Bulb, 92
FrankenBot toy, 3841
Interactive Twin LED Flasher, 38
Fritzing circuit schematic diagrams (see
electronic circuit schematic diagrams)
Fritzing diagrams
Adjustable Twin LED Flasher, 35
Amazing Pushbutton, 144
AND logic gate, 53
Arduino AND logic gate, 55
Arduino Ohmmeter, 112
Arduino OR logic gate, 64
electronic circuit schematic diagram of
Tilt Sensing Servo Motor Controller,
26
electronic circuit schematic of SunriseSunset Light Switch, 15
Electronic Cricket, 200
Electronic Pixel, 214
Interactive Twin LED Flasher, 38
LCD News Reader, 122
Logic Tester with an LCD, 138
Logic Tester with an RGB LED, 132
Magic Light Bulb, 88
Metal Checker, 96
Metronome, 223
OR logic gate, 62
Pocket Stage Light, 206
RGB Flasher, 81
Rocket Launcher, 170
Secret Word Game, 232
Servo Motor Tester, 194
simple NOT Logic Gate wiring diagram,
44
Sunrise-Sunset Light Switch, 10