THE TAB BOOK OF ARDUINO PROJECTS PDF

adminComment(0)
    Contents:

Introduction T his book contains 36 Arduino projects. Some are easy to make, whereas others require some expertise with a soldering iron. You do not need a. The definitive collection of Arduino projects for the hobbyist and experimenter, The TAB Book of. Arduino Projects: 40 Things to Make with Shields and Proto. In this easy-to-follow book, electronics guru Simon Monk shows you how to create a wide variety of fun and functional gadgets with the Arduino.


The Tab Book Of Arduino Projects Pdf

Author:CARMELINA TIJERNIA
Language:English, Japanese, German
Country:Fiji
Genre:Children & Youth
Pages:211
Published (Last):30.04.2016
ISBN:158-2-65724-952-8
ePub File Size:30.53 MB
PDF File Size:11.63 MB
Distribution:Free* [*Sign up for free]
Downloads:24476
Uploaded by: ZONIA

ma, 25 mrt GMT the tab book of pdf -. Tab (tablature) and notation of songs by other musicians as PDF di, 26 mrt Shields By Simon Monk #e8e EBOOK EPUB site PDF. Read Download. Online The Tab Book Of Arduino Projects: Get Instant Access to PDF File: #e8e The Tab Book Of Arduino Projects: 36 Things To Make With Shields And Proto Shields

To be able to plug the Protoshield into your Arduino, you will also need some lengths of header pins. See the Appendix for more details about where to obtain components.

Figure I-6 shows the easiest way to make sure that the header pins are soldered on straight.

Read The TAB Book of Arduino Projects: 36 Things to Make with Shields and Proto Shields PDF

First, break of lengths of 10, 8, 8, and 6 pins each, and push the long ends into your Arduino. Then place the shield over the top of the holes, and make sure that it is the right way up Figure I-6a. The Arduino board will keep the pins straight while they are being soldered.

Solder each pin in turn Figure I-6b. When all the pins are soldered, the shield should look like Figure 6c when you turn it over. Components The Appendix contains a list of all the components that you will need for the projects in this book, along with various sources.

You will often find that many of the components can be obtained very cheaply on site. The Book The remainder of this book is organized into chapters that deal with a particular theme, but within that theme, there is no real order to the projects.

The only project that gets something in the way of special treatment is the first project in Chapter 1. This project is to build a persistence-of-vision POV display.

The chapter explains how to us a Prototshield and construct the project in more detail than for most other projects. Thus, if you are new to this type of construction, read Chapter 1 first, even if you do not plan to make the project.

Figure shows the effect you get when you wave the display about vigorously. This POV display also has the advantage that you can program the message that it displays from your computer.

The project uses a Protoshield with seven light-emitting diodes LEDs , series resistors, and a tilt-sensor module soldered to it.

Parts To build this project, you will need the following: LEDs are often best bought from site, especially when you need them in quantity. Protoshield Layout Figure shows the layout of the components on the Protoshield. Construction Because this is the first project in the book, I will go into some detail. The basic idea of Protoshield is that the component leads are pushed through from the top of the board and soldered to the pads beneath, and then the remaining leads of the components are joined up.

Sometimes, as with all four leads from the tilt sensor, linking wires have to be soldered in place. The general rule for soldering things onto any kind of circuit board is always to start with the lowest-lying components so that when you lay the board on its back, gravity will ensure that the components stay in position while you solder them. Step 1: Put the Resistors in Place Using Figure as a guide, bend the leads of the resistors, and push the leads through.

Figure shows the underside of the board with the resistors ready to be soldered into place. Step 2: Solder the Resistors Now solder the resistor leads next to the header pins, and cut off the excess leads on that side Figure Solder the pins on the other side of the resistors to the pads, but do not cut off the leads yet. Step 3: LEDs have a positive end and a negative end, so you need to make sure that the longer positive leads are all toward the resistors. All the negative leads of the LEDs are eventually going to be connected together.

Figure shows the first LED in place. Bend the positive lead of the LED and the free lead of the first resistor so that they run right next to each other the far right of Figure , cut off the excess lead, and solder them together. When all of the LEDs have been soldered to their corresponding resistor leads, the underside of the board should look like Figure Step 4: Start by shortening the negative lead of the middle LED so that it just reaches the pad for the GND pin; then bend the other leads in until they are all connected together Figure Step 5: We can actually test this before we go any further.

The LEDs will each light in turn. If any of the LEDs do not light, then check that they are wired up the right way and that there are no accidental solder connections.

Step 6: It comes as a tiny circuit board, so we need to attach some header pins to it to link it to the Protoshield. Figure shows the sensor with the header pins attached. The tilt sensor has four connections: GND, 5-V, and two switch connections that detect tilting in two axes. Step 7: Solder the Tilt Sensor Unlike the LEDs and resistors, the tilt sensor does not have long leads that we can use for connecting things up.

Instead, use some of the trimmed resistor leads to connect the solder pads for Arduino pins 11 and 12 to the appropriate pins of the tilt sensor refer to the wiring diagram of Figure The end result is shown in Figure The 5 V and GND connections to the tilt sensor need to be made with insulated wire because they cross over other connections.

These are shown in Figure Testing Now that construction is complete, we can try out the full project. Software The code responsible for actually flashing the LEDs is fairly concise, but there is also a big array in the sketch that contains the character font in a seven-row format. The first part of the sketch is as follows: The constant gap sets the delay in microseconds between the display of each column of the text.

You can lower this value to make the message more condensed. Increasing the value will spread the message out wider. The following setup function initializes the pin attached to the tilt sensor to be an input and all the LED pins to be outputs.

It also uses the C strcpy command to copy the message to be displayed into the buffer message and initializes serial communication with your computer. The following loop function first checks to see if a new message string has been sent from the computer. If it has, it copies it into the message buffer. It then goes on to check the tilt switch. If movement is detected, it first delays for 10 columns worth of time, to allow the display to get up to speed, and then loops over each letter in the message calling the function displayChar to actually flash out the columns for that particular letter.

To flash out a particular character, the displayChar function first checks that the ASCII value of the character is in the range of 32 to decimal. The function then has a pair of nested loops—the outer loop for each column and the inner loop for each row of a particular column.

The characters array is used to look up the bit for that row and column to see if the appropriate LED should be lit. At the end of each character, a delay of twice the normal column gap allows some separation between the letters of the message. The LED pins used are kept in an array ledPins. This allows them to be iterated in a loop when setting them to be outputs. The array element for the letter A is shown below using binary numbers. A 1 means that the LED will be on; a 0 means that it will be off.

You can just make out the pattern of the A. Summary This is a fun little project to start with. In the next project, we will continue with the theme of LEDs. In this project, look for LEDs with as wide an angle of view as possible so that not all the light is shining straight up.

The resistors and transistors are soldered to the Protoshield, before any of the LEDs are attached. The LEDs will be built up in layers onto the board. Figure shows the schematic diagram for the design. You do not have to understand it to build the design, but it may help to explain why everything is connected up the way it is.

The anodes positive connections of each LED position are connected together for all three layers. However, the three transistors, T1 to T3, can switch each of the layers on and off. Construction There are two major parts to building this project.

The first is to assemble the Protoshield, and the second is to create the LED assembly itself. The starting point is a Protoshield with the header pins attached. If you are not clear how to do this, please return to Chapter 1. Solder the Resistors Using Figure as a guide, bend the leads of the resistors, and push the leads through. Solder the resistors in place, and cut off the excess leads at the edge near the pin headers.

However, leave the resistor leads toward the middle of the board in place because you will need these to make connections to the LEDs later.

Figures and show how things should look on the bottom and top of the board when you have done this. Solder the Transistors and Jumpers Now you can solder the transistors. Make sure that they are the right way around; you can see the transistors have one flat side in Figure In this figure, you can also see the bare wire coming vertically out of the board.

The underside of the board is shown in Figure , and you can see that the other connections for the transistors have been made with insulated wire or by bending the leads of the transistors and soldering them together to form connections. Use Figure as a guide to making these connections.

These will not be connected until we start to attach the LEDs. Put the board aside for a moment until we have built the first layer of LEDs.

This is almost impossible without some kind of mechanism for keeping all the LEDs in the right place while you solder them. For this task, I made a simple holder out of cardboard.

You could, if you wish, use something stiffer, such as wood, but cardboard will do the job. Figure shows the cardboard holder. To make it, cut out a piece of thick cardboard about 2 inches 50 mm square. The holes are going to be drilled at the nine intersections of these lines. Drilling may seem a bit excessive for cardboard, but drilling a hole with just the right diameter for the LEDs 5 mm keeps the LEDs snugly in place while you are trying to solder them.

Figure shows the pattern of the LEDs. This is the same for all three layers of the board. Each LED has a positive lead the longer lead. This lead will always be left unbent. However, all the negative leads of the LEDs are going to be connected together by bending the leads to a horizontal position so that they just reach to the next LED.

Place the LEDs into the holder with their leads facing upward. Note that with the exception of the middle LED, all the LEDs have their longer positive lead toward the outside of the square. Note that the arrow marks the endpoint of the lead. Figure shows the first row of LEDs soldered up.

Carefully edge each of the vertical LED pins into the correct hole in the Protoshield. Refer to Figure Push them all through by the same amount, which should be just enough to solder to but no longer. It is easiest to do this by starting at one edge of the LEDs and working across. After the LED pins are soldered, the resistor leads that you have not yet soldered should be soldered to the LED connections.

Finally, the vertical lead coming straight out for the board from the transistor T1 should be soldered to the common negative connections of the LEDs. Make sure that the lead is not touching anything, and snip off any excess.

The only difference is that when you have finished, you will need to bend over the tips of the vertical positive leads Figure so that they can reach around the LEDs on the first layer and connect to the corresponding positive leads on that layer Figure The leads are best bent using pliers.

Soldering the second layer onto the first is a little tricky, especially reaching the middle LED. Start by soldering the positive leads of each corner LED, and then solder the other leads. Finally, do not forget to attach a vertical wire from the common negative of the middle layer down to connection point C2 on the Protoshield.

Do not forget to attach a vertical linking wire to connect the common negative of the top layer to connection point C3 of the Protoshield. Figure shows the final shield fully assembled. Note the connecting wires to the common negatives of each layer. Check that none of the LEDs has its pins accidentally connected together. You should see the LEDs twinkle on and off at random.

Software The example sketch for this hardware uses a two-dimensional array to contain the LED pins ledPins. It also uses an array for the layerSelect pins that control which layer is enabled during refreshing of the display. A separate three-dimensional array model is used to maintain the current state of the 27 LEDs. The animated flickering is caused by the animate function turning one LED on and one LED off at random each time it is called. Summary This is a great little novelty project, but one that will have tested your construction skills.

However, the wiring through the Arduino PCB should not be pushed further than, say, 1 or up to 3 A as long as the LEDs are not at full brightness all the time. Thus, quite high-power LED modules of up to, say, 5 W should be fine. When selecting your power supply, make sure that it can supply enough power for all the LEDs to be on at the same time.

Protoshield Layout Figure shows the schematic diagram for the project, and Figure shows the Protoshield layout. The schematic just shows three channels. The Protoshield layout shows the arrangement for all six channels.

If you just plan to build the three-channel version, then ignore everything inside the dashed box. Construction This is a pretty straightforward project to build. As always, start by attaching header pins to the Protoshield. These instructions assume that you are building the three-channel version of the project. Cut off the excess leads at the Arduino connector end of the resistors, but leave the ends toward the middle of the board for making connections to the MOSFETs Figures and Prepare the Header Sockets Header sockets do not usually come in the right lengths.

Typically, you will download a strip of maybe 40 header sockets that need cutting to the right length. Cutting the header sockets can be a little tricky Figures and The sockets are very close together, so you will need to cut through the seventh socket, sacrificing one socket. You can cut them with a craft knife or just score a line with the craft knife on the seventh socket, and then break it over the edge of your desk or table.

It can be difficult to get the header sockets soldered straight Figure and to avoid having them fall out at the crucial moment. A bit of adhesive putty will hold them in place while they are being soldered. Wire Up the Underside Quite a lot of the underside can be wired together using the component leads. However, you will require some additional insulated solid-core wire to make some of the connections Figures and Refer to Figure for the layout.

The finished Protoshield is shown in Figure It is a good idea to attach a label to the board showing the polarity of the connections to the LEDs. These have leads already attached that terminate in pin headers. If you would prefer screw terminals, then you will notice that some of the holes on the right-hand edge of the Protoshield are larger than the others.

This is so that up to five 0. The light panels that I used have self- adhesive tabs on the back, which were attached to the side of a project box and the wires threaded inside. Thus, in this case, an external power adaptor is used to supply the Arduino and shield. You should find that each channel cycles around in brightness.

Note that you can now unplug the USB lead from the Arduino to your computer because it is only needed for programming. Software There are lots of interesting control programs that you could write for your lighting controller. This example just cycles the brightness of each channel. Something else that you could do with the code would be to control the device through the serial monitor, sending commands that then change the brightness of each color channel to allow a color to be mixed.

Summary In this chapter, we have made a high-power LED lighting controller. In Chapter 4 we turn our attention to sensing light rather than controlling it. In fact, it is so simple that it does not even need a Protoshield board. The color-sensing module can just be attached directly to the Arduino Figure When the module is placed next to an object, it will determine its color. The only tricky bit might be tracking down the module. Modules normally can be found on site or at DealExtreme.

Look for a module that uses a TCS There are several different variations on this chip, but they all work in the same way. The chip has a transparent case, and dotted over its surface are photodiodes with different color filters over them red, green, and blue. You can read the relative amounts of each primary color.

Design The integrated circuit IC does not produce an analog output but instead varies the frequency of a train of pulses. You choose which color the pulse frequency corresponds to by changing the values on the digital inputs S2 and S3. Table lists the pins on this module. You will need to make the following connections: The pins are named according to their function rather than using the module pin names. The setup function sets the appropriate pin modes and then sets the prescale pins that control the output frequency range to HIGH, starts serial communication, and then displays a welcome message.

The loop function reads the three different colors more on this later and displays a message depending on the dominant color. Note that the lower the value, the brighter is that particular color. Each of the functions readRed, readGreen, readBlue, and readWhite just call a function readColor with the appropriate values for S2 and S3.

The function readColor first sets the appropriate pins for the color and then records a start time in the variable start. Then it waits for 1, pulses to happen and returns the difference between the current and start times. Although not actually used, there is also a function in the sketch that writes the color values to the serial monitor. To try out the project, place it next to objects of different colors.

Open the serial monitor, and the sensor will distinguish between red, green, and blue objects. Summary The test program could easily be extended to allow a greater range of colors to be detected. They are also sometimes referred to as near-field communication NFC readers, and they can read data from a tag without the need for any electrical contacts. You just place the tag near the reader, and it will read a unique ID from the tag.

The tag may be in the form of a credit card or key fob. Figure show a simple homemade RFID lock. Note that this shield is not compatible with the Arduino Leonardo, so you will need to use an Arduino Uno for this one. To build this project, you will need the following: Shield Layout The layout of the extra components that are going to be soldered onto the prototyping area of the shield is shown in Figure Construction The construction using an RFID shield is very similar to the process using a protoshield.

The only difference is that you need to confine yourself to the small prototyping area on the board. However, we will still attach components in the same way, joining them up on the underside of the board using the component leads and extra lengths of solid-core wire where necessary. Attach Header Pins to the Shield The shield comes supplied with header pins, but these are not attached to the board. The shield also should include a tag or two for testing Figure If you want to download additional cards, make sure that they are of the type There are various different frequencies of tag in use, so be sure to get the right ones.

A good way to make sure that the header pins go in the right holes on the shield and that they are straight is to fit the headers into an Arduino and then place the shield onto the pins for soldering, as shown in Figure Having attached the header leads, you can, if you wish, test the shield to make sure that it is working okay before you attach the rest of the components. Solder the Resistors Figure shows the resistors soldered into place.

In this case, it is easier to push the leads of the resistors through and solder them to the top of the pad.

You can snip off the resistor leads that go to Arduino pins 10 to 13, but leave the other ends of the resistor leads intact for making connections.

When soldering the LED, make sure that the longest lead the common cathode is the second lead in from the left of the board. That is the lead that will be connected to ground and not to a resistor. Also make sure that the screw terminal is attached such that the open end on the side where you insert the wires goes toward the outside of the board.

Wire the Underside Now that all the components are in place, you can make the remaining connections on the underside of the board. Use Figure as a reference. Note that the board has been flipped top to bottom, so the screw terminal is at the top of the diagram now.

This needs to be downloaded from the following URL: You will also have to restart the Arduino IDE for it to pick up the new library. Open the serial monitor and set the baud rate to 9, When you wave a tag in front of the antenna of the shield, you should see some output such as that shown below in the serial monitor: Note that during testing, you can just power the Arduino and shield through the USB connection.

Later, when you deploy the lock for real, you will need to use the 12 V power supply to provide enough voltage and current to operate the door latch. The ID of the card read is shown as a series of hexadecimal digits. If you wish, you could now also load up one of the example sketches that are provided with the Adafruit library. This will display a bit more information about the tag that is scanned and provide more feedback about the shield.

If you were just running this sketch to check that the reader is working, then you can return to the preceding section and finish the construction.

If, on the other hand, you have finished the soldering, then you can now take a look at how the code works. After including the libraries needed Wire is for I2C communication , there is a constant for the maximum number of codes allowed. If you need more than this, change its value and also the number of entries in the array that follows it. Note that you can leave entries blank if they are not in use. Following this are constants for the pins used and also for the colors red, green, and blue.

The following line of code initializes the RFID shield using pin 2 for interrupt requests and pin 3 as the reset pin: This is followed by declaration of the global variable code that is used to contain the ID of the last tag scanned.

The main loop function is very light; it invokes a function scanCode that attempts to scan a tag. If this is successful, it returns true and then calls checkCode, which will compare the code just scanned with the stored codes. The function scanCode does the actual work of reading the code and converting it into a string of hexadecimal characters.

The function scanCode reads the ID into byte array uid. It then iterates over each byte, converting it into a two-digit hexadecimal string that is then added to the code variable. The checkCode function compares the last scanned tag ID with each of the codes in the codes array. If it finds a match, it sets a flag to that effect. After all the codes have been checked, if a match was found, the function unlockDoor is called; otherwise, the LED is set red for 2 seconds to indicate the attempted use of an invalid tag.

Finally, the function setColor sets the color of the LED from the color supplied as an argument. This is represented as just a three-bit number, with one bit for each of the three channels.

Installing and Using the Door Lock The type of latch used is designed to replace the receptacle for a conventional lock so that when power is applied, it allows the receptacle to swivel, and the latch can then open. The lock is opened using a solenoid that requires a few hundred milliamps to activate. This is why the Arduino needs to be powered from a V, 2-A power supply. This power is also provided via the shield and MOSFET through the screw terminals, so the two leads connected to the coil of the latch mechanism can just be connected to the screw terminals on the shield.

In normal use, the LED will be blue when the lock is ready. If a known tag is placed near it, the LED will go green, and the lock will open for 5 seconds. If the tag is not known, the LED will go red for 2 seconds. However, instead of using a radiofrequency identification RFID tag reader, this version of the lock uses a traditional keypad Figure Protoshield Layout Figure shows the Protoshield layout for this project.

There are a couple of important things to note about this that result from the keypad being connected directly into pins D1 to D7 of the Arduino: The keypad has one extra pin on either side of the seven middle pins that are actually used.

This means that one of the pins of the keyboard is connected to Arduino pin D1 Tx. Thus, if you are using a Uno, you will have to unplug the keypad while programming the board. If, on the other hand, you are using a Leonardo, then you can leave it connected because the Leonardo uses a separate interface for the USB. Construction This project is pretty easy to assemble, but there are a few cases where bare component leads will need to hop over other tracks on the prototshield without touching them, so follow the construction steps with care.

Matrix Keypads Keypads are normally arranged in a grid so that when one of the keys is pressed, it connects a row to a column. The key switches are arranged at the intersection of row-and-column wires.

When a key is pressed, it connects a particular row to a particular column. However, this also means that we have to do a bit more work in the software to determine which keys are pressed. The basic approach we have to take is to connect each row to a digital output and each column to a digital input. Attach Header Pins to Keypad The keypad uses seven pins but has a spare connector at each end that is not connected to anything.

You only need to solder pins to the seven pins, but you can put the extra pins on each end if you prefer. Figure shows my keypad. Note that I have chosen to include the extra unused pins at each end of the keypad connector. Attach Header Pins to the Shield In this project, we will not be using standard header pins for every pin on the Protoshield, but rather we will be using a stackable header for pins 0—7 so that the keyboard can just be plugged directly into it. Start by soldering this stackable header onto pins 0—7.

Push the header through from the top and solder it on the underside of the shield, as shown in Figure The remainder of the headers can be normal header pins.

Browse more videos

Figure shows these soldered in place. You can snip off the resistor leads that go to the Arduino pins but leave the other ends of the resistor leads intact for making connections. The leads on this transistor can be carefully bent over so that it lies at an angle to the board Figure Make sure that the metal parts of the transistor package are not touching any of the solder pads on the Protoshield.

When soldering the LED, make sure that the longest lead the common cathode is the second lead down from the top of the board. This is the lead that will be connected to ground and not to a resistor. Also make sure that the screw terminal is attached with the open end, where the wires go toward the outside of the board.

When everything is connected, the underside of the shield should look something like Figure Figure shows a diagrammatic version of the underside for easy reference. Note that the board has been flipped left to right so that the screw terminal is at the right of the diagram now. You will notice that near the screw terminal and the MOSFET, there are some links made with the component leads that need to jump over other solder pads without making contact.

Software There is an Arduino library that greatly simplifies using a keypad. This library needs to be downloaded from the following URL: Later, when you deploy the lock for real, you will need to use the V power supply to provide enough voltage and current to operate the door latch.

TAB Book of Arduino Projects: 36 Things to Make with Shields and Protoshields

Much of the code for this project is very similar to that of the RFID door lock of Chapter 5, so you also may wish to refer to that chapter. Here I will just present the parts of the sketch that are different.

We then have a variable that keeps the secret code. The loop function is as follows: Here we first define a Boolean flag called wrong that will be set to true if a wrong digit is entered as the code. Once this key has been pressed, there is a loop that captures the next four key presses and compares them with the appropriate digits of the secret code.

If any of the digits are wrong, then the wrong flag is set. After all four key presses have been captured, then either the door is unlocked or locked depending on the result in the wrong flag. Unlocking the door is similar to the sketch of Chapter 5, except that in addition to setting the color of the LED, the program also sounds the buzzer continuously for the 5 seconds that the latch remains unlocked. Sounding the buzzer requires use of the Arduino tone command. The first parameter of this command is the pin on which the tone is to be played, and the second is the frequency of the note in hertz.

The noTone command cancels the buzzing sound at the end of the 5 seconds, after which the door is then locked again using the following lockDoor function: The lockDoor function also gets called as a result of entering an incorrect code.

Therefore, to make the failure to enter a correct code obvious, a for loop is used to make the LED flash red and the buzzer sound five times. The final function that I need to mention is waitForKey. This function will wait until a key has been both pressed and released. The first while loop waits until a key is pressed. The second while loop waits until the key is released again.

The lock is unlocked using a solenoid that requires a few hundred milliamps to activate. This is why the Arduino needs to be powered from a 12 V 2 A power supply. The LED will be red when the lock first starts up. Note that the buzzer will warble for a few seconds if you are using an Arduino Leonardo. Once reset is complete, setup calls the lockDoor function, so the LED will flash red and the buzzer will sound four times. Enter the four-digit code , and the LED will go green, the buzzer will sound, and the door latch will be released for 5 seconds, after which the lock sequence will run again.

However, instead of using a radiofrequency identification RFID tag reader or keypad, this version of the lock uses a secret knock Figure The idea is that you train the lock with a certain pattern of knocks, and then, when it hears the correct knock, it releases the door. This type of lock should not be considered to be as secure as the preceding two lock projects but is a great bit of fun.

Most of this design is exactly the same as that of the keypad lock in Chapter 6. All the headers can be normal 0. Construction Start by following the instructions for constructing the Protoshield in Chapter 6, but use normal header pins throughout rather than stackable headers. Note that even after you have added the extra parts, the hardware will still be compatible with the keypad lock project of Chapter 6. Then solder in the pair of header pins. Figure shows the additional components on the Protoshield.

Wire the Underside Now bend the resistor leads so that they brush the edge of each header pin and continue on to the Arduino GND and A0 connections on the Protoshield. Figure shows the additional wiring on the underside of the Protoshield. Software The software for this project is the most complex of the three door lock projects. The section of constants above this might need changing to suit your particular buzzer.

See the next section if you need to do this. When the Arduino restarts, the setup function will turn the LED blue, expecting you to immediately enter the secret knock key. The function records this key using the recordKnock function and then plays it back using the playKnock function. The recordKnock function is as follows: This function will write the knock timings into whatever array is passed to it as an argument.

It uses the first element of the array to record the number of taps detected, and the remainder of the elements of the array will contain the duration in milliseconds after the start of recording t0.

The while loop ensures that the maxRecordingTime and maxTaps are not exceeded because this would cause unpredictable results if the array bounds were exceeded and fixes the recording time at 5 seconds. The function recordKnock relies on the function tapDetected to determine whether the sensor has been tapped. The function tapDetected returns true if the reading on the analog input A0 is above the threshold. However, it delays for ignorePeriod to ensure that the ringing effect that might cause a knock to be detected twice is minimized.

Playing back the knock is a similar process to recording it. The function playKnock is as follows: To play back the knocks through the buzzer, we need to step over each element in the array, make a short buzz, and create a delay for the time difference between the current knock and the previous one.

The main loop function is as follows: Nothing will happen in the main loop until a tap is detected. This then triggers the sequence of events necessary to capture a series of taps on the sensor. The LED is set blue, and then the recordKnocks function is called. The if statement uses the guessCorrect function to check whether the knocked sequence is close enough to the saved pattern. If it is, then the door is unlocked.

The guessCorrect function is as follows: The first thing that happens in this function is that the lengths of the guess and key knocks are compared. If they are not the same length, then they cannot match, so false is returned. If they are of the same length, then the time of each tap has to be compared in turn. Because the knocking is unlikely to start at the same time after the LED went blue, the startGap variable is set to a value to synchronize the two sequences of knocks.

The error of a particular guess is calculated as the absolute value of the difference between the guess knock and the key knock less the startGap. If that error is greater than the limit in milliseconds specified in tapLeeway, then false is returned. Installing and Using the Door Lock The type of latch used is designed to replace the receptacle for a conventional lock so that when power is applied, it allows the receptacle to swivel and the latch to open.

This is why the Arduino needs to be powered from a 12 V, 2 A power supply. There are a number of constants at the top of the sketch that can be tweaked to alter the performance of the lock. The constant threshold is the value of analog reading above which the reading will count as a knock. If you find that the lock is too sensitive and registers knocks when there were none, then increase this value. The ignorePeriod value will help to eliminate double taps where there was only one. Increase this value if you find this happening.

When comparing the knocks, the value of tapLeeway specifies the number of milliseconds that the guessing taps can deviate in timing from the key taps. If you want to make the lock more lax, then increase this value. Summary In Chapter 8 we will look at using a sound shield to play the sound of a dog barking when a panic button is pressed or motion is detected using a passive infrared sensor.

Unlike most of the projects we have built so far, this project uses a ready-made shield for playing the sound file. The MP3 player shield is equipped with a 3. This is ideal for connecting to a pair of powered computer or MP3 player speakers. The louder the better! Unless you plan to record a very large amount of dog barking, any micro SD card bigger than MB will be fine. Design Figure shows how the switch and PIR sensor are attached to header pins that fit into the header sockets of the shield.

The push switch grounds the digital input when it is pressed. Construction Because most of the work is already done for us in the ready-made shield, this project is easy to make.

Because there are going to be a few extra things that we need to attach to the Arduino, we will use through header pins Figure To solder these in place, start by soldering just one pin on the underside of the board. Then straighten the header row up by melting the solder again while you get it level and flat to the board. Then you can solder the rest of the pins on that header and then repeat the process for the other headers. When all the headers are attached, the finished board should look like Figure Attach the Push Button Solder short leads of multicore insulated wire onto the push button.

Then solder the other end of one of the leads to the GND pin indicated in Figure Attach the other lead to D12 on the header. Again, use Figure as a reference. Data have to be set to it a byte at a time. Fortunately, to simplify this process, a library has been developed that you need to download and install into your Arduino environment.

First, download the the zip file from www. For the libraries to be recognized, you need to restart the Arduino software. You may prefer to record your own deterrent sound.

If you do, then this must be in MP3 format recorded at kbs. Remember to name the file track When the file is ready, remove the micro SD card and insert it into the holder on the MP3 shield.

Using the Fake Dog Once built and programmed, this project no longer needs to be connected to your computer for anything other than power. Therefore, you probably will want to power it from an external power adapter.

Ideally, the PIR sensor will be positioned outside your door, with wires running into the house and connecting to the shield. Software The library makes the sketch itself nice and simple. This tells the library to look for a file called track The remainder of the code is mostly concerned with checking the digital inputs one for the PIR and one for the switch.

Summary This is a fun project to make and could be adapted to other uses. To improve the project, you could record a number of different tracks and have them played at random when triggered. Construction The project uses header sockets to connect the modules. If you prefer, you can just solder them directly to the Protoshield.

Step 1. However, you may choose to omit the pins for the Arduino pins A0 to A5 as these are not used in this design. Step 2. Solder the Components to the Protoshield The header sockets can be cut from a long length of header sockets see Chapter 3 for details on how to do this.

There are only two header sockets and the push switch to attach, so they can all be soldered in one go. Use Figure as a reference for positioning the header sockets and the switch. Figure shows the top side of the completed Protoshield. There are a few places where wires cross over each other, so use insulated wire where necessary.

The zip file is small, so it will not take long to download. After the library include statement, you will find the definition for the constant threshold.

This specifies the maximum distance of an object from the sensor for that object to be counted. This distance is in centimeters.

This is followed by the usual pin definitions. The ultrasonic range finder uses two Arduino pins, trigger and echo. To count objects moving past the sensor, we need to detect when they are inside the threshold distance and then wait until they move further away than that distance. To keep track of these two states, we use the constants waitingForArrival and waitingForDeparture and the variable state.

The count variable is used to keep count of the number of objects that have passed the sensor. The setup function sets the modes of the Arduino pins and initializes the display. It cannot literally wait for such a thing using a while loop because it needs to also keep checking for key presses. If the state is currently waitingForArrival and an object has come close enough, then the state is changed to waitingForDeparture. The next time around the loop, the state will now be waitingForDeparture, and unless the object has departed, it will stay in this state.

When the object does depart, the count will be incremented by one, and state will return to waitingForDeparture. The next section of the loop function checks for a button press. Finally, the count is written to the display, and the display is updated.

The function takeSounding sends a short pulse to the trigger pin of the ultrasonic rangefinder and then times how long it takes for the echo pin to go HIGH, indicating that the sound wave has returned to the module.

The distance then can be calculated from this time taken. Using the Project You probably will need to adjust the direction in which you point the rangefinder and the value of threshold to get it to work well.

Pressing the button will set the count back to zero. There are some interesting uses for this kind of project. For example, if it were battery powered and waterproof, then you could use it to keep track of how many lengths of a swimming pool you had swum. In this case, you probably would want to increment count by two each time you got close to the edge of the pool where the counter is stationed. It is also one that lends itself to various adaptations.

In Chapter 10 you will find the final security-related project in this book, in the form of a laser-based intruder alarm. In this case, the triggering of the alarm activates a relay. This offers the best flexibility in attaching sirens, lamps, or various other devices in response to the alarm being triggered. Once triggered, the alarm remains active until the reset button is pressed Figure An alarm like this is really more for fun than for serious security. It is actually fairly easily defeated using a sheet of paper placed close to the laser and an LED so that the light from the laser is reflected straight back into the LED.

Because you are using the laser with a mirror, you need to be especially careful not to reflect it back into your eyes. To see if the laser is on, never look into it. Instead, hold a piece of paper in front of it to see the dot.

Parts This project uses a Protoshield and a low-cost laser module. It also uses a clever trick to allow a large LED to be used as both the light sensor and an indicator of the alarm being triggered.

You can always add them later. Figure shows how this works. Notice how the LED is reverse biased. That is, it is the wrong way around if we want it to emit light. This way around, the LED will act like a capacitor think of a mini rechargeable battery. This will happen very quickly, so almost immediately there will be a voltage across it of 5 V. If we disconnect point A, the voltage would gradually drop back down to zero. The speed at which it drops will depend on the amount of light falling on the LED.

Thus, if having charged the LED we then switch point A to a digital input instead of an output, we can see how long it takes for the voltage to fall from being high over about 2. This time will give us a measure of the light intensity. You can find an excellent description of this technique at www. Construction Aligning the Arduino and mirror so that the beam is neatly reflected back onto the LED is quite tricky and needs both the mirror and Arduino to be anchored securely in position.

If you are going to use this project for real, then you probably also will want to run leads to the switch rather than have the switch on the board and easily pressable to cancel the alarm. Figure shows the Protoshield layout. Because stability is important for this project, it is probably a good idea to solder all the header pins.

Thus, the leads have been carefully bent out so that the relay can be soldered to the top surface of the board Figure The relay now can be soldered to the top of the Protoshield in the position marked by Figure Figure shows the relay soldered into place.

Solder the Remaining Components to the Protoshield You can now solder the rest of the components to the board. Do not trim off the excess leads from the components because they will be useful later when you connect things up on the underside of the board. There are a few things to check when you are soldering: Figure shows the remaining components soldered into place.

Solder the Underside of the Protoshield You will be able to make most of the links on the underside of the board using the component leads. However, you will need a couple of longer lengths of wire for connections to the screw terminals and switch. Figure shows the underside of the board, and Figure shows the wiring diagram from the underside of the board. The sketch does not require any Arduino libraries to be installed. The pin definitions for this sketch are as follows: These pins are needed to allow the polarity of the LED to be reversed when switched between emitting and sensing light.

The laser is controlled by laserPin. This allows the sketch to turn the laser off briefly, when measuring the ambient light intensity. The constant laserNoLaserRatio determines by how many times the light-level reading must be lower with the laser lighted than without it before the laser beam is interrupted, and alarmTriggered is activated. A Boolean variable is used as a flag to indicate that the beam has been interrupted.

The setup function simply sets the pin modes of the various pins. The first part of this function tests to see if the laser beam has been interrupted. If it has, then it sets alarmTriggered to true. It will remain set to true until the button is pressed. This is detected in the next section of loop.

The alarmPin is then set to the same value as alarmTriggered. Also, if the alarm is triggered, then the flashLED function will be called, temporarily reversing the polarity of the LED to make it light rather than act as a light sensor. To decide whether the beam has been broken or not, the function laserOnTarget is used. This function first reads the light intensity with the laser turned on, then turns the laser off, waits for 10 milliseconds, and then takes another reading, before turning the laser back on.

The readings are lower the higher the light intensity, so the laserOnTarget function will only return true if the reading taken with the laser on is significantly less than the reading with no laser. The following function reads the light intensity: It then returns the time taken in microseconds.

The lighter it is, the faster the LED will lose its charge. You will remember that when the alarm is triggered, the LED is made to flash. This happens in the function flashLED. Before the LED can be used to light up rather than act as a light sensor, it must be forward biased by setting ledPinA to be an output and low. Using the Project In using this project, you will need to find a place to position the mirror so that it can reflect the laser light back onto the LED.

The way to do this is to attach the mirror to a wall self-adhesive putty is useful for this. The Arduino and shield then can be positioned opposite the mirror. Because there is a short distance between the laser and the LED, the laser module will need to be bent ever so slightly so that the reflected laser dot falls on the LED.

You will see the LED glow when this happens. A relay Figure is basically an electromagnet that closes switch contacts. Although the coil of a relay is often energized by between 5 and 12 V, the switch contacts can control high-power, high-voltage loads. For example, the relay shown in Figure claims a maximum current of 10 A at V alternating current ac, mains as well as 10 A at 24 V.

Because the relay contacts will behave just like a switch, you can use the relay to switch almost anything. The wiring diagram in Figure shows how you could use the relay with a 12 V alarm sounder and power supply. Summary This is the last of the security-related projects in this book. You'll learn how to design custom circuits with Protoshields and solder parts to the prototyping area to build professional-quality devices.

Catapult your Arduino skills to the next level with this hands-on guide. Build these and many more innovative Arduino creations: Simon Monk Abstract: Table of Contents A. Dedication B. About the Author C.

Acknowledgments D. Introduction A. Light and Color 1. Persistence-of-Vision Display 2. LED Cube 3. Color Recognizer B. Security 5. Keypad Door Lock 7. Secret Knock Lock 8. Fake Dog 9. Person Counter Laser Alarm C. Sound and Music Theremin-Like Instrument FM Radio Receiver Pedal Board Controller Music Controller Spectrum Display D. Internet E-Mail Notifier Weather Data Feed All that is really necessary is that it has enough room to easily press the switches that you want to use.

The basic approach we have to take is to connect each row to a digital output and each column to a digital input.

To install the libraries for the LED module, go to https: Note that with the exception of the middle LED, all the LEDs have their longer positive lead toward the outside of the square. Construction Because this is the first project in the book, I will go into some detail. You only need to solder pins to the seven pins, but you can put the extra pins on each end if you prefer. For example, if it were battery powered and waterproof, then you could use it to keep track of how many lengths of a swimming pool you had swum.

These are the only changes to make the sketch work with a different number and arrangement of switches.

CARLYN from Arvada
Review my other posts. I enjoy balance beam. I do like reading comics unaccountably.
>