Tero Karvinen Tero Karvinen teaches Linux and embedded systems in Haaga-Helia University of Applied Sciences, where his work has also included curriculum development and research in wireless networking. He previously worked as a CEO of a small advertisement agency.
Tero's education includes a Masters of Science in Economics. More Details. Build It Figure shows the circuit diagram for this project. Orient your breadboard so that it is taller than it is wide, as shown in Figure Circuit diagram for the simple switch circuit; the short lead connects to the black wire 2.
Insert the red LED into the breadboard and keep track of which side is positive the longer lead and which is negative the shorter lead. If you want two leads in the same row to be connected, be sure they are on the same side of the gap. Connect the alligator wire from the other resistor lead to the middle lead of the switch.
Connect the red positive wire from the battery holder to either side lead of the switch using the following technique see Figure : a. Push the wire through the hole. Fold the wire into itself. Twist the folded wire to secure it. Tying a wire to the switch leads 6. Insert the batteries into the holder. Now you can add a power switch to any of your projects. No more removing the battery when you are done playing with a prototype. If the alligator clip short-circuits two leads, the LED might be lit constantly, even if you flip the switch.
If you find the LED is never lit, try pressing on the battery wire connection and flipping the switch.
For a permanent fix, twist the switch more to make the wire tighter. In a pinch, any resistor with a brown multiplier band third stripe will do. If you have a general idea what the LED should look like when lit, you can just try out resistors.
If the LED is too dim, pick a weaker resistance. So if you forget the current limiting resistor, the LED might drain your battery and cause some components to overheat and break. Third Band Trick We use a shortcut called the third band trick to pick out resistors.
Hold a resistor so the tolerance band is on your right—these are usually gold or silver bands. The third band in from the left is known as the multiplier band. Some resistors have five bands, not four, although they are uncommon. But all the same, the multiplier band is the second-to-last band. Our rule of thumb when working with 3 V to 5 V for choosing a resistor by its third band: pick brown if you are protecting an LED, green if you need a pull-up resistor. Project 3: Buzzer Volume Control In many projects, you need the ability to slightly adjust input or output rather than toggling between on and off.
Potentiometers, also known as pots, are often used as volume controls for audio devices. Because we are going to be increasing and decreasing the current with a potentiometer, using a 9 V source voltage gives us room to increase or decrease the voltage and still produce audible output.
Build It Here are the steps for building this project: 1. Connect the negative wire of the piezo buzzer to any free column of holes on the breadboard and then insert the black negative battery clip wire into the same column. Basic Sensors 13 www. Circuit diagram for buzzer volume control 4. Clip in the 9 V battery and turn the potentiometer left to right to change the output level of the piezo buzzer. Now you can add loud noise to any of your projects. You also know how to use a potentiometer as an adjustable resistor.
You will soon learn about many other sensors that report their value with resistance, just as a potentiometer does. Start from battery positive or negative and go through the whole circuit. Project 4: Hall Effect A hall switch senses change in the magnetic field and detects if there is a magnet nearby. A very common use for this is a bike speedometer that iden- tifies how often a rapidly rotating object passes by the sensor. If you buy the similar NJKC, you will have to change the way you wire the circuit described later.
If you are using the NJKC, black will go negative rather than positive when a magnet is held to the sensor. Here are the steps for building this project: 1. Basic Sensors 15 www. Circuit diagram for the Hall sensor alarm 2. Insert the black output Hall effect switch wire into any free column of holes on the breadboard and then insert the red positive wire of the piezo buzzer into the same column. Insert the red positive wire of the 9 V battery clip into any free column of holes on the breadboard and then insert the brown positive Hall ef- fect switch wire into the same column.
Insert the blue negative Hall effect switch wire into any free column of holes on the breadboard and then insert the black negative wire from the battery clip into the same column. Insert the black negative wire from the piezo into this column. Clip in the 9 V battery and hold a magnet to the switch to make the buzzer sound. You can use it to detect when two things are brought together or separated.
For example, you could put a magnet in a door, and a Hall effect switch in the doorframe to know when it is opened or closed. It can also be used to measure rotational speed: if you embed a magnet in a stationary bicycle wheel, you could use a Hall effect switch to measure how fast you are pedaling. You could use the speed as input to a video game to make your exercise sessions more interesting.
Does it make a sound? Project 5: Firefly Night falls, and fireflies start to glow, slowly fading in and out. Then you reverse this, making your LED light up in darkness. It turns on the LED fading in darkness. By building the firefly in distinct, testable steps, you will learn a system- atic approach to building analog circuits. Integrated Circuits ICs vary in complexity and price.
The timer we use here is a cheap, com- paratively simple IC: it only has about 40 components inside, most of these being transistors and resistors. Your projects would balloon in parts and the wiring would not be an easy process.
If you think 40 components is a lot, you will be taken aback to learn that there are billions of components in ICs such as a processor Basic Sensors 17 www. This book teaches you the things you need to know to use the components in this book. Datasheets are sometimes tedious to read, but they are the authoritative source on how the IC works.
Pin numbering can be found on the datasheet. Usually, pins are numbered counter-clockwise from the notch. Hold the IC, pins down, so that you look at it from the top. Locate the polarity mark: a half-moon notch, a corner tri- angle, or a dot on pin 1.
Pins are numbered counter-clockwise from that mark, starting from pin 1. For the CAE, hold the half-moon notch to the left and the pins away from you. See Figure Pin 1 is the bottom left, and the numbers increase counter-clockwise. Thus, the last pin 8 is at top left. To make your life easier, the circuit diagrams in this book have small pin numbers on the chips. You can con- figure it as a timed delay, an oscillator, or as a flip-flop.
Instead, the timer configuration is done by connecting certain compo- nents such as resistors and capacitors to the Hardware sets up the , not software. Building and configuring gadgets by coding with Arduino is easier than the component-by-component approach you use with the Here, we have already designed the circuit for you and made the necessary calculations, making it a simple task to get familiar with the The brighter it is, the more current goes through.
The LDR works just like any analog resistor, so you could use a potentiometer in its place. Sound familiar? Who needs light in a bright room? Basic Sensors 19 www. Jumper wires These wires are not fancy and you can even make them yourself by stripping the ends off of insulated solid core thin wire. Jumper wires are available in a number of colors, lengths, and connector housings.
The core of the wire refers to the part surrounded by plastic insu- lation and can be stranded or solid. You want solid core wire because the breadboard clips need to latch onto something solid. In this circuit, you use the most common transistor, a bipolar NPN transistor. Controlling base current to the transistor is done with two resistors.
One of the resistors is connected to the plus terminal of the battery, and pulls the voltage up. The other resistor, the LDR, is connected to ground minus. The connection using the two resistors is called a voltage divider. Build It Build the circuit as shown in Figure LDR inverter circuit Transistors A transistor see Figure is an amplifier, taking small signals and making them larger.
It can also function as a switch, because a small power can con- trol a larger power. Transistors are actually the basis of all digital electronics. Microcontrollers, such as Arduino and Raspberry Pi, use very little power. If you want to control something that needs more power, such as a big motor, a transistor is one way to do that.
For example, you can use an Arduino and a servo easy instead of trying to control a motor with transistors harder. Common Emitter Amplifier Emitter E is the common ground, the negative. The arrow points to the neg- ative lead. The arrow is simply pointing the direction of current from positive to negative see Figure The small controlling base current BE flows from base B to emitter E.
This base current is the weak signal to be amplified. The large collector current CE flows from collector C to emitter E. This col- lector current only flows if there is base current. Basic Sensors 23 www. There is no base-emitter current flowing, so the big collector-emitter current is blocked. When you apply current to the base, a small base-emitter current starts flowing. This allows the big collector- emitter current through, and could start a big motor or a bright light. Take the transistor from this project, BC, with leads down and the flat text side facing you.
The collector is on the left, base is center, and the emitter is on the right. Fading an LED What could be easier than fading a light? Actually, fading an LED is tricky business.
For a dimly lit LED, there is only a small voltage range available. With microcontrollers, such as an Arduino, dimming is done by blinking the LED faster than the eye can see. Here, with analog electronics, you can use a transistor to help you control the small part of a voltage range where the LED is between on and off see Figure The transistor is used in the common collector amplifier, where the small BC current controls the bigger EC current.
You can easily test it by building a worse, alternative setup see Figure Put a potentiometer in series with the LED. You can use the timer to fade the LED. Basic Sensors 25 www. The previous projects can be accomplished on any type of breadboard, even tiny ones. When you use an IC, however, you need to make sure that your breadboard is split into two sec- tions of horizontal rows.
This breadboard layout allows for each lead of the IC to be isolated on its own electrically con- nected row. In this circuit, the timer is used in astable mode. The output fades between 3 V and 6 V. Adjusted with a transistor amplifier, this makes the LED fade in and out.
The two pins are con- nected together. You can turn the potentiometer to choose how fast the capac- itor charges. As you remember, the capacitor is connected to pin 3 OUT through the potentiometer, so the potentiometer chooses how fast the capacitor discharges. The capacitor starts to charge, and the cycle starts over.
This way, the output of the circuit keeps oscillating between 3 V and 6 V. Because it takes time to charge the capacitor, your circuit produces a triangle wave. You probably want to connect an LED to the output of your new oscilla- tor. So where do the two wires go? See Table Table It has two conductive plates, separated by an insulator. Even the symbol for a ca- pacitor shows this: two lines for the metal plates are separated by a gap. Three capacitors Figure Symbol for capacitor Capacitors are used in resonant circuits, like in radios.
They can also smooth spikes in DC power sources e. Yet another use is timing events, which is the usage you just worked with in the last project. The capacitor and resistor you hook up to the timer configure its mode.
The values also further affect the specific expression of the configured mode and allow us to make determinations about the overall circuit. A similar complexity simplification occurs when we move from the timer to a microcontroller, and then again to a system-on-a-chip. Firefly Time to build the final circuit for the project. If you skipped here to just build the firefly—good, you can read the theory when it works.
If you did every intermediate step, great—you can just combine them with the understanding you have built. Build the circuit see Figure Completed firefly Once the circuit is ready, try it out. Congratulations, you have completed the chapter on component-by- component electronics! The next chapter is about Arduino, so things are just going to get easier.
Enjoy your firefly! Basic Sensors 31 www. There are many advantages to using Arduino rather than individual components as you did in Chapter 2. Our Arduino Uno, breadboard, and laptop An Arduino runs sketches, which are programs that you write and upload to the Arduino from your computer. It is also much easier to modify code than it is to modify a circuit layout. For example, suppose you want to add a delay how often a sensor takes meas- 33 www.
It is more efficient to type a few lines of code and upload a compiled binary program than it is to hunt for a specific com- ponent and wire it into a circuit. Sketch writing will open a whole new world of opportunities in your electronics projects. Time to get building! If this is your first time using Arduino, read Appendix B to learn how to install drivers and the Arduino integrated development environment IDE.
As long as the sensors and other components are used within their electrical specifications, using an Arduino or any other programmable microcontroller board will simplify your circuit and facilitate greater flexibility. However, if you use them out- side of their specifications, such as applying more voltage to an LED than you should, you risk destroying the components, or even your Arduino.
Project 6: Momentary Push-Button and Pull-Up Resistors Buttons are not the most exotic components but surely one of the most used and common sensors. Insert the momentary push button anywhere on the breadboard. When the button is pushed, the code lights up the built-in LED attached to pin Example From now on, when you write buttonPin in your sketch, Arduino will put the number 2 in its place.
Variables make code easier to read and modify because you can change them in a single place. All variables in this sketch are integers int : whole numbers such as 1, 2, 3, or Create another variable for the LED pin. The built-in LED is on digital pin 13 D The setup function runs once when Arduino boots up. It contains all the one-time initialization you need in your sketch.
This way, we can later read its value with digitalRead. Enable the internal pull-up resistor. Magic hardware being controlled by software happens here! Arduino runs the loop function automatically after setup has finished. As the name implies, loop is called again and again until you reset or power down the Arduino. Then you save this answer to variable buttonStatus.
If the button is pressed closed , pin 2 is connected to ground and digitalRead returns LOW. Always use two equals signs when performing a comparison in an if statement. By putting LOW on the left side of the comparison, you guard against such an error: LOW is a constant, and you cannot assign a value to it. So if you use a single equals sign, Arduino would give you an error message when you try to compile and load the sketch to your Arduino.
Here the LED is illuminated. Turn off the LED. As soon as loop finishes, Arduino runs it again, starting at the top of the loop function. Pull-Up Resistors and Arduino The momentary push-button design works reliably because you engaged an internal pull-up resistor in the Arduino circuitry.
You might wonder exactly what a pull-up resistor pulls: it pulls the voltage of the pin toward the 5 volts that power the Arduino. Never trust a floating pin. A floating pin gives a useless value see Figure Sensors and Arduino 37 www. There is no point in reading a floating pin; add a pull-up resistor The Arduino IDE comes with many useful example sketches. This handles the case where the button is pressed.
We already know you have to connect a pin somewhere to read its value. Pull-up resistor to the rescue! Typical values for pull-up resistors are tens of thousands of ohms to a few million ohms e. This is how your connection works: press the button, D2 goes LOW. Release the button, and the pull-up resistor pulls it up to HIGH. How do you recognize a floating pin in your own connection? If any sensor connects to Arduino with just two leads, ask yourself whether the pin is connected in every possible state the sensor can be in.
As you can see, even the humble switch has a lot to teach us about how sensors need to be wired up. Sensors and Arduino 39 www. The receiver part of the switch collects the IR light that is reflected back.
Obstacles cause more light than usual to be reflected, which tells you that there is something in front of the sensor. This sensor can become confused in strong sunlight, and some very dark materials can pass by unnoticed.
They are usually 40 Getting Started with Sensors www. An infrared sensor switch is useful for various projects. You can set the detection range of the sen- sor by adjusting the trimmer potentiometer trimpot with a small screw- driver, as shown in Figure If it terminates in male headers, you may need to build this circuit using a breadboard and jumper wires.
As long as you have a sensor that breaks out wires for ground, 5 V, and a signal, then this layout will work with your sensor. We used a sensor with separated wires, so we inserted each lead directly into the Arduino headers.
Sensors and Arduino 41 www. Connect the circuit as shown in Figure , then run the sketch shown in Example When you put some- thing in front of the sensor, the built-in LED attached to pin 13 is lit. Follow these instructions for connecting the circuit: 1. Connect the yellow signal lead to digital pin 8 on the Arduino. Connect the green ground lead to a GND pin on the Arduino. Connecting the infrared sensor switch Example Similarly, the name buttonStatus is changed to objectDetected.
You know this code already! We changed two variable names, but that is largely cosmetic. Experiment with it yourself: can you use the infrared proximity sensor with the code from Example ? Can you use a button with the code from Example ? Many sensors have identical interfaces. Now that you know how to work with two switches, which we refer to as digital resistance sensors, you can apply this skill to similar sensors in your own projects.
They produce their results with a gradual change in resistance. For example, the more force you exert on a force-sensing resistor like a FlexiForce, the lower its resistance. Project 8: Rotation Pot The potentiometer shown in Figure is an adjustable resistor with a knob. When you turn the knob, its resistance changes.
Potentiometers are very common in everyday items such as radios and clothes irons. In RC air- planes, servomotors can determine their angular position with the help of a potentiometer. Sensors and Arduino 43 www. Try it yourself! Now, turn the knob to max or min. If the resistance of the potentiometer is sufficient, you can turn the LED on and off. Because the code is designed to read a button, you can only turn the LED on or off.
To make use of the analog values produced by the potentiometer, you must use the analogRead function. Turn it all the way in one direction, and the LED blinks slowly. Turn it all the way in the other direction, and it blinks faster. Figure shows the wiring diagram for this project. The center pin is attached to analog input pin A0. As you turn the knob, the resistance on either side of the pin varies. Parts You need the following parts for this project: 1.
Which side depends on how you insert the pot into the breadboard; try it both ways! Sensors and Arduino 45 www. Run the Code Next, run the code listed in Example The analog input pins are also numbered, but we put the letter A in front of the name when referring to them A0, A1, etc.
Note that we use the comment to show the expected range of values. After setup is finished, loop is called automatically. Read the voltage from potPin A0 with analogRead. The code saves this value to variable x. Turn on the onboard LED. When the knob is turned the other way, the delay is 0. Turn off the onboard LED. Wait again, so that the LED remains off briefly. Project 9: Photoresistor to Measure Light How bright is it?
Our students have used photoresistors to make robots love or hate light, activate lights in the dark, or create burglar alarms. Build it as shown, and run the sketch listed in Example Note the addition of the 10K resistor. This is to create a voltage divider. Photoresistor circuit layout 48 Getting Started with Sensors www.
Run the program and try it out. What happens when you make a shadow or hide the photoresistor completely? Most common sensors are analog resistance sensors, so they use a variation of this same connection.
You can apply this same approach to similar sensors you meet in the future. Project FlexiForce to Measure Pressure A force-sensitive resistor such as the FlexiForce see Figure is a flat sensor that measures how much pressure you exert on it.
Untouched, without any pressure, it has a very high resistance. When you press the round area at the end of the sensor, the resistance drops and it becomes more conductive.
A force-sensitive resistor measures pressure exerted on it Sensors and Arduino 49 www. Build the circuit as shown in Figure , and then run the sketch from Example Arduino can talk to your computer over its built-in serial port and send text back to it you can even send messages from the computer to Arduino , as shown in Figure The Arduino uses its USB port to transfer serial messages.
Serial ports are a very common way for embedded devices to talk. This allowed us to control the Arduino-based robot with our brainwaves! Another great example is our mobile phone controlled football robot from our book, Make: Arduino Bots and Gadgets. In that project, we used serial over Bluetooth, allowing the Arduino to communicate with an Android phone.
But serial is not just used for communicating directions to devices. When building an early prototype of our satellite, we used serial- over-USB to debug our project. FlexiForce circuit layout Figure Serial Monitor Run the Code Example The setup function is called automatically; it handles one-time initialization.
The loop function is called automatically and repeatedly after setup is finished. This value is stored to variable x. This prints out the value of the variable to the serial port so that it appears in the Serial Monitor. Experiment yourself: can you connect a potentiometer and read its current value through serial? If you need to challenge yourself, you can try converting rotation to angle in degrees or a percentage of maximum rotation. Are you feeling really adventurous?
Once you get your data to your computer, you can read it in any programming language. LM35 temperature sensor Our students have used the LM35 to measure temperature in their summer cottages and greenhouses, for example. It has three leads: 5 V, ground, and signal. Build It Figure shows the circuit diagram.
Build it as shown, and then run the code listed in Example Open the Serial Monitor to see the current tem- perature.
Connect the LM35 sensor to Arduino using a breadboard. But what is VOUT? Voltage OUT indicates the temperature as an output voltage, so you need to connect it to an analog input pin on Arduino Example uses A0. If you put it in your fridge, prepare to wait. When we want to quickly test cooler temperatures, we use ice cubes see Figure Wet ice cubes quickly conduct heat away from the LM35, so we get instant readings.
When the Arduino boots up, setup gets called automatically to perform one-time initialization. Opens the serial port.
Define a new function called tempC. The function analogRead returns an integer value from 0 to We convert the raw reading to a percentage by dividing it by the maximum value.
The percentage will be 0. To get the floating-point decimal answer you need, you must use the floating-point divisor The percent variable is calculated out of a maximum of 5. So multiplying by 5. Sensors and Arduino 55 www. After setup finishes, loop is called automatically, over and over until you power down the Arduino. Call the tempC function, which returns a number e. Print this number and a line break to the Serial Monitor.
Writing tempC as a function makes it easy to use it in our other projects. When you want to know the temperature, just connect the LM35 and call tempC. Upload eBook. Privacy Policy. New eBooks. Search Engine. To build electronic projects that can sense the physical world, you need to build circuits based around sensors: electronic components that react to physical phenomena by sending an electrical signal.
Even with only basic electronic components, you can build useful and educational sensor projects. But if you incorporate Arduino or Raspberry Pi into your project, you can build much more sophisticated projects that can react in interesting ways and even connect to the Internet.
This book starts by teaching you the basic electronic circuits to read and react to a sensor.
0コメント