Learn electronics with arduino, Study notes of Design

learn electronics

Typology: Study notes

2014/2015

Uploaded on 06/10/2015

walid31
walid31 🇩🇿

2 documents

1 / 269

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
TECHnoLogY in ACTion
Learn
Electronics
with Arduino
Don Wilcher
Learn eLectronics concepts whiLe
buiLding practicaL devices and cooL
toys with arduino.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Learn electronics with arduino and more Study notes Design in PDF only on Docsity!

TECHnoLogY in ACTion™

Learn

Electronics

with Arduino

Don Wilcher

Learn eLectronics concepts whiLe buiLding practicaL devices and cooL toys with arduino.

For your convenience Apress has placed some of the front

matter material after the index. Please use the Bookmarks

and Contents at a Glance links to access them.

xxi

Introduction

Have you ever wondered how electronic products are created? Do you have an idea for a new electronic gadget but no way of testing the feasibility of the device? Have you accumulated a junk box of electronic parts and now wonder what to build with them? Well, this book will answer all your questions about discovering cool and innovative applications for electronic gadgets using the Arduino. The book makes use of the Arduino plus discrete, integrated circuit components and solderless breadboards. Multisim software is used for circuit simulation and design equations.

Who Should Read This Book?

This book is for anyone interested in building cool Arduino electronic gadgets using simple prototyping techniques.

How This Book Is Structured

The chapters in this book are organized in such a way that the reader can choose to jump around the projects and discovery labs. Each chapter gives an introduction to the relevant key electronics components and supporting technologies. Also, each chapter explains the basic theory of operation of the electronic circuits with detailed circuit schematic diagrams. Build instructions with troubleshooting tips are included to help you detect and fix hardware/software bugs for each project. Last but not least, each chapter zooms in on a specific aspect of electronics technology followed by several semiconductor device-specific experiments. The experiments will help you understand the semiconductor device’s electrical behavior as well as the setup of basic electronic test equipment and the Arduino software IDE tool via sketches. You’ll be introduced to circuit analysis techniques and the Discovery Method, which offers suggestions for further fun ways of learning about electronics technology. The goal of these hands-on activities is to encourage readers (whether inventors, engineers, educators, or students) to develop skills in engineering their own cool gadgets using simple prototyping techniques.

Downloading the Code

The code for the examples shown in this book is available on the Apress web site, www.apress.com. A link can be found on the book’s information page under the Source Code/Downloads tab. This tab is located underneath the Related Titles section of the page.

Contacting the Author

Should you have any questions or comments—or if you spot a mistake—please contact the author at [email protected].

Chapter 1

Electronic Singing Bird

The Arduino is a small yet powerful computer board that uses physical computing techniques with an Atmel microcontroller (processing development environment) and the C programming language. To illustrate the versatility of the Arduino in turning ordinary electronic circuits into cool smart devices, I will show how to make an interactive electronic singing bird in this chapter. The required parts are pictured in Figure 1 - 1.

Parts List

Arduino Duemilanove or equivalent

0.047uF capacitor 0.1uF capacitor

470uF electrolytic capacitor 1 K resistor

50 K trimmer potentiometer Audio transformer

2N3906 PNP transistor 2N3904 NPN transistor

5VDC relay 1 N4001 silicon diode

100 W resistor 8 W speaker

Cadmium sulfide (CdS) photocell 1 small solderless breadboard

22 AWG solid wire Digital multimeter

Oscilloscope (optional) Electronic tools

How It Works

The operation of the electronic singing bird starts with a cadmium sulfide (CdS) cell (photocell) detecting the absence of light. If no light is present, a voltage drop appears across the light-dependent resistor. The voltage across the CdS cell is approximately +2.5VDC, allowing the D2 pin of the Arduino to respond to the binary 1 logic signal. The software that is programmed into the Atmega328 microcontroller will turn on the D13 pin, making it switch from a binary 0 (0 V) to a binary 1 (+5VDC). With an output voltage of +5VDC, the transistor Q2 is able to turn on, allowing it to switch or energize the K1 relay coil. The iron core that is inside of the relay coil establishes a magnetic field attracting the electrical contact to the armature or common (COM) contact. The closing of the relay contacts will supply +5VDC to the electronic oscillator circuit. The chirping sound can be heard through the 8W speaker.

■ Note The ability to apply the appropriate voltage and current to the base of a transistor to turn it on is known as

biasing.

Conducting a deep dive into the system block diagram reveals the circuit schematic diagram of the electronic singing bird shown in Figure 1 - 3.

Figure 1-3. Schematic diagram for the electronic singing bird circuit

Figure 1-4. One cycle of a pulse wave captured on a Multisim virtual oscilloscope

If you change the capacitance value of C3 (470uF), the electronic singing bird’s tone duration will be affected. The smaller the capacitance value, the faster the time between bird chips heard through the 8W speaker. The rheostat (50 K trimmer potentiometer) affects the switching time of the chirps. This control provides flexibility in terms of the type of chirp that can be heard through the 8W speaker. The shape of the waveform is based on the 470uF capacitor charging from the +5VDC power supply and discharging through the 1 K resistor. This charging-and-discharging electrical behavior biases the 2N3906 PNP transistor, thereby allowing it to switch on and off at a repetitive rate. The series combination of resistors, consisting of a 1OK fixed resistor and 50 K trimmer potentiometer, helps manage the switching time of the charging-and-discharging capacitor mentioned before. Capacitors C2 (47 nF) and C1 (100 nF) help reduce the switching noise peak voltage levels of C2. The pulse-generated signal is magnetically coupled to the 8W speaker by the audio transformer. To further analyze the bird’s electronic oscillator, I built a circuit model using Multisim software. Running a simulation event produced the output signal captured on a virtual oscilloscope, as shown in Figure 1 - 4.

■ Note Multisim is an intuitive software package capable of capturing circuit designs and testing electrical

behaviors through simulation.

Figure 1-7. Circuit schematic diagram showing the oscilloscope attachment to the audio transformer for capturing a pulsed waveform signal

Figure 1-6. Test setup for displaying the pulsed waveform signal from the electronic oscillator circuit

Pulse Width Modulation Basics

Pulse width modulation (PWM) is commonly used for managing the power of electrical or electronic loads. You control the average value of voltage and current fed to the electrical or electronic loads by turning the output voltage supply attached to the load on and off at a fast switching rate. The longer the output voltage supply is applied to the load, the higher the power supplied to it. The PWM switching frequency must be high in order for the power management of the electrical or electronic load to take effect. The ability to manage the power of the load effectively allows the efficiency of the circuit’s operation to reach up to 80 or 90 percent. The heat generated by the electrical or electronic load is very low, thereby providing longevity to the circuit. With this type of efficiency, incandescent lamps and electric motors, which are notorious for generating heat during normal operation, can function at a much lower temperature. Figure 1 - 8 shows a typical PWM signal for an AC electric motor. Another key electrical parameter for PWM is duty cycle. Duty cycle describes the proportion of “on” time to the regular interval, or period , of time. A low duty cycle corresponds to low power, because the power is off for most of the time. Duty cycle is expressed in percent, with 100 percent being fully on.

Figure 1-8. A typical PWM signal for an AC electric motor

■ Tip duty cycle can be expressed mathematically as follows:

duty Cycle = [ Ton / (Ton + Toff )] × 100

where Ton is the time-on of the pulsed waveform and Toff is the time-off of the electrical signal.

This technique of switching effectively to manage the power of an electrical or electronic load can be used to create audio special effects as well. Used in this application, the PWM signal is equivalent to the difference between two sawtooth waves. The ratio between the high and low levels of the pulsed waveform is typically enhanced with a low-frequency signal. In addition, changing the duty cycle of a pulsed waveform creates unique sound effects for music applications such as synthesizers. Some music synthesizers have a duty-cycle trimmer for changing the shape of the device’s square-wave output. The 50 K trimmer potentiometer for the electronic singing bird oscillator provides the similar function of changing the switching time of the circuit’s output signal.

Transistor Basics

The key electronic component of the electronic singing bird’s oscillator circuit is the transistor. The main function of the transistor in this circuit application is to amplify the charging and discharging waveform produced by capacitors wired across the primary winding of the audio amplifier. The PNP transistor is biased by the 50 K

and units. Upon powering up the circuit, you will see the LED flash at the specified frequency of the square-wave signal being applied to the base of the PNP transistor. On every falling edge transition of the square wave, the transistor’s base-emitter junction will be forward biased, thereby allowing current to flow from the emitter lead through the series-limiting 330W resistor and the LED to ground. The LED will flash briefly based on the biasing current flowing through its anode-cathode junction when the transistor turns on. You can increase the rate at which the LED flashes by changing the input frequency to a higher value. Although the circuit in this example was built on a virtual test bench using Multisim, a breadboard prototype can easily be constructed using the parts shown in Figure 1 - 9.

Transformer Action

The pulsed waveform signal that is generated by the electronic oscillator is magnetically coupled to the 8W speaker by the audio transformer. The iron core of the transformer enhances the magnetic field because of its permeability (magnetic properties), thereby allowing the maximum pulsed waveform signal to be present on the secondary winding of the audio transformer. The primary and secondary windings of the transformer’s pulsed waveform are inverted 180 degrees from each other. Figure 1 -1 1 shows the transformer’s inverted signals on the virtual oscilloscope. To see this inverted signal, you must use a dual-trace oscilloscope, which is quite expensive for an electronics hobbyist. However, Multisim’s virtual oscilloscope can be used an alternative. To see the two waveforms simultaneously, connect the channel A scope probe across the primary winding and the channel B scope probe to the secondary winding of the audio transformer. Figure 1 -1 2 shows the circuit schematic diagram for attaching the oscilloscope probes to the audio transformer. The two pulsed waveform signals will be inverted 180 degrees.

■ Note A transformer is a device that transfers electrical energy from one circuit to another through magnetically

coupled conductors—the transformer’s windings.

Since Multisim doesn’t have an electrical symbol for a speaker, I used a standard 8W resistor in the circuit model during the simulation event. One key technique to remember when modeling circuits is to find

Figure 1-10. Function generator settings for demonstrating transistor biasing

Figure 1-11. Inverted pulsed waveform signals from the audio transformer

Figure 1-12. Circuit schematic diagram showing oscilloscope probes attached to primary and secondary windings of the audio transformer

To show the effect of discharging the inductor’s coil, I added a series discharge resistor to the second inductor’s coil. Now, with each press of the switch, an initial high electrical current value will be displayed on the ammeter, followed by lower electrical current values. Again, these lower values represent the second inductor coil discharging the electrical current through the series resistor. A Multisim circuit model can easily be built for observing charging and discharging behavior of a transformer. Figure 1 -1 4 illustrates the initial condition of the circuit completely discharged of current.

Figure 1-14. Initial condition of the transformer with the switch open

As shown in Figure 1 -1 5 , the transformer has charged up to a couple hundreds of microamperes (mA). When the switch is closed continuously, the electrical current starts to diminish in value, thereby displaying a discharging transformer. To automate this charging-and-discharging test, the Arduino, along with a transistor relay circuit, can be programmed to cycle the charging-and-discharging test based on a predetermined switching cycle.

■ Tip The amount of voltage transferred in the second inductor coil as result of the first (primary) inductor coil’s

electrical current is relative to the mutual inductance (Lm) between the two inductor coils. The mutual inductance is

based on the inductance of each inductor coil and the amount of coupling (k) between the two inductor coils.

The Voltage Divider

The key interactive interface component for the electronic signing bird is the photocell. To assist in determining when light is present or not, a pull-up resistor is wired in series with the photocell. The two electrical components wired together make up a voltage divider circuit. With no light present, the photocell has a couple of kilo-ohms of resistance. The photocell voltage drop based on the total supply voltage is proportional to its resistance value. A high value of resistance will mean a significant voltage drop, and low resistance value will mean a small voltage drop. Figure 1 -1 6 is a voltage divider circuit.

■ Tip The voltage divider is a series circuit whereby the voltage drop across any resistor or combination of

resistors is equal to the ratio of the target resistance to the total resistance. This ratio is multiplied by the source

voltage of the circuit.

The photocell’s resistance is set at 4KW. The voltage across this resistance value is determined by the voltage divider equation, as follows:

V4K = (V1 ×Photocell)/ Rtotal

Figure 1-15. The transformer charged with the switch closed

Figure 1-16. Circuit simulation with light detected simulation

photoresistors. A photocell, as explained in the previous section, changes its resistive value (ohms) based on the amount of light that shines on its surface. Photocells are manufactured in various sizes, and different-sized photocells function slightly differently. Because of this variation in size and function, photocells are traditional not used in critical light-measuring applications. The selection of a photocell is usually based on the following electrical parameters, traditionally listed on a datasheet (see www.ladyada.net/learn/sensors/cds.html):

Size: Round, 5 mm (0.2") diameter. (Other photocells can get up to 12 mm/0.4" diameter!)

Resistance range: 200 K (dark) to 10 K (10 lux brightness)

Sensitivity range: CdS cells respond to light between 400 nm (violet) and 600 nm (orange) wavelengths, peaking at about 520 nm (green)

Power supply: Pretty much anything up to 100 V, uses less than 1 mA of electrical current on average (depends on power supply voltage)

To use a photocell for light detection applications, such as the electronic singing bird project, you can wire a pull-up or pull-down resistor in series with electronic components so the appropriate voltage drop can be obtained for further signal processing. Depending on the size of the pull-up or pull-down resistor you use, the photocell will provide a voltage drop proportional to is resistance. If the photocell has a large resistance value, the voltage drop across it will be proportional to the ohmic value. Likewise, a small resistance value produced by the photocell will provide a small voltage drop across it. Figure 1 -1 8 illustrates wiring a pull-up or pull-down resistor to a photocell for light detection signal interfacing.

Figure 1-18. Light detection circuits: A photocell wired with a pull-up resistor (a), and a photocell wired with a pull- down resistor (b)

As an exercise, try building each circuit shown in Figure 1 -1 8 using Multisim software and compare the electrical behaviors to each other.

Testing the Light Detection Circuit with a Voltmeter and an Oscilloscope

You can validate the preceding exercise by using a voltmeter and an oscilloscope on a laboratory test bench. I’ll discuss the test equipment arrangement I used for both instruments in the following subsections. I’ll explain the individual test instruments and measurement points using simple Multisim circuit schematic diagrams, followed by the actual laboratory test bench setup.

Using a Voltmeter

The wiring test setup for checking the electrical operation of the light detection circuit with a voltmeter is shown in Figure 1 -1 9. Basically, the voltmeter—or digital multimeter (DMM)—test leads will be connected across the photocell. The voltmeter or DMM will be set for the appropriate measurement scale and electrical units.

Figure 1-19. Multisim circuit schematic diagram for testing the light detection circuit with a voltmeter or DMM

The actual laboratory test bench setup I used is shown in Figure 1 -2 0. I placed the DMM’s test leads (red and black) across the photocell. With the DMM set to voltage I measured the photocell’s voltage drop with the electronic singing bird’s prototype board under ambient lighting. As pictured in Figure 1 -2 0 , the photocell’s voltage drop value was low. This measurement reading coincides with the photocell’s small resistance value. Next, I covered up the photocell with my hand to shield it from the ambient lighting, and another voltage drop reading was displayed on the DMM’s liquid crystal display (LCD). This reading was approximately +2.5VDC, indicating a high resistance value from the photocell. Figure 1 -2 1 shows the high voltage drop reading of the photocell shielded from the ambient light. The voltage drop readings varied based on the type of ambient light shielding and the distance of the shield from the photocell.

■ Note Ambient lighting is normal room light. As the light shield or hand approaches the photocell, thereby

diminishing the ambient lighting, the voltage drop will increase in value, signifying that the sensor’s resistance

is increasing. The voltage drop of approximately +2.5VdC was measured on the Multisim circuit model shown

in Figure 1 -2 2.

Using an Oscilloscope

You can also use an oscilloscope to test the light detection interface circuit by following a similar wiring convention to one discussed earlier, using a voltmeter or DMM. The oscilloscope’s test probe will be attached across the photocell, similar to a voltmeter or DMM. Figure 1 -2 3 shows a Multisim circuit schematic diagram for wiring an oscilloscope to the light detection interface circuit.