Inside, you'll learn about: Interaction design and physical computingThe Arduino hardware and software development environmentBasics of electricity and electronicsPrototyping on a solderless breadboardDrawing a schematic diagram And more.
With inexpensive hardware and open-source software components that you can download free, getting started with Arduino is a snap. Join the tens of thousands of hobbyists who have discovered this incredible and educational platform. Written by the co-founder of the Arduino project, with illustrations by Elisa Canducci, Getting Started with Arduino gets you in on the fun! But that was just the beginning Barri Flowers. The Hideaway: An irresistible story of secrets, heartbreak and a surprising new beginning.
The Popcorn Gangster: Chopper Bob Rotella. Turn The Ship Around! David Marquet. Unbroken - Used, beaten but never broken. We do this using a small trick, as state can be only either 1 or 0. Later in the program, you can see that we use state to figure out whether the LED has to be on or off. As I mentioned, this leads to somewhat flaky results. The results are flaky because of the way we read the button.
Arduino is really fast; it executes its own internal instructions at a rate of 16 million per second—it could well be executing a few million lines of code per second. So the results end up being unpredictable; it might be off when you wanted it on, or vice versa. As even a broken clock is right twice a day, the program might show the correct behaviour every once in a while, but much of the time it will be wrong.
How do we fix this? Well, we need to detect the exact moment when the button is pressed—that is the only moment that we have to change state. The way I like to do it is to store the value of val before I read a new one; this allows me to compare the current position of the button with the previous one and change state only when the button becomes HIGH after being LOW.
Example 03B contains the code to do so: 46 Getting Started with Arduino www. You may have noticed that this approach is not entirely perfect, due to another issue with mechanical switches. Pushbuttons are very simple devices: two bits of metal kept apart by a spring. When you press the Really Getting Started with Arduino www. This sounds fine and simple, but in real life the connection is not that perfect, especially when the button is not completely pressed, and it generates some spurious signals called bouncing.
When the pushbutton is bouncing, the Arduino sees a very rapid sequence of on and off signals. Example 03C is the final code: 48 Getting Started with Arduino www. If Arduino were some sort of human language, those would be two letters of its alphabet. Considering that there are just five letters in this alphabet, you can see how much more work we have to do before we can write Arduino poetry. Figure shows the inside of a typical model.
When the sensor is in its upright position, the ball bridges the two contacts, and this works just as if you had pressed a pushbutton. When you tilt this sensor, the ball moves, and the contact is opened, which is just as if you had released a pushbutton. Using this simple component, you can implement, for example, gestural interfaces that react when an object is moved or shaken bit.
The inside of a tilt sensor 52 Getting Started with Arduino www. This small device triggers when a human being or other living being moves within its proximity. Figure 5—2. One of the limitations of the blinking LED examples that we have used so far is that you can turn the light only on and off. A fancy interactive lamp needs to be dimmable. To solve this problem, we can use a little trick that makes a lot of things such as TV or cinema possible: persistence of vision.
Figure shows how this works. This technique also works with devices other than an LED. For example, you can change the speed of a motor in the same way. Luckily, the processor used by the Arduino board has a piece of hardware that can very efficiently blink three LEDs while your sketch does something else. This hardware is implemented in pins 9, 10, and 11, which can be controlled by the analogWrite instruction. Why ? Note: Having three channels is very good, because if you buy red, green, and blue LEDs, you can mix their lights and make light of any colour that you like!
Build the circuit that you see in Figure Note that LEDs are polarized: the long pin positive should go to the right, and the short pin negative to the left. Also, most LEDs have a flattened negative side, as shown in the figure. Use a ohm resistor red violet brown. Add the circuit we used to read a button back in Chapter 4 to this breadboard. Advanced Input and Output www. However, one of the advantages of the breadboard see Appendix A is that there is a pair of rails running horizontally across the bottom and top.
One is marked red for positive and the other blue or black for ground. In the case of the circuit you need to build for this example, you have two components both of them resistors that need to be connected to the GND ground pin on the Arduino. Because the Arduino has three GND pins, you could simply connect these two circuits exactly as shown in each of the two figures; just hook them both up to the Arduino at the same time.
Getting back to this next example, if we have just one pushbutton, how do we control the brightness of a lamp? To do this, I need to upgrade example 03C from Chapter 4 to add dimming. As you can see, our interaction model is taking shape.
If you press the button and release it immediately, you switch the lamp on or off. If you hold the button down, the brightness changes; just let go when you have reached the desired brightness. Take a light sensor, like the one pictured in Figure You can get a bag of these from Maker Shed part number JM or from bit. When you shine some light at it, the resistance quickly drops and it becomes a reasonably good conductor of electricity.
It is thus a kind of light-activated switch. Now plug the LDR onto the breadboard instead of the pushbutton. Uncover the LDR, and the light goes on. In order to read this type of sensor, we need a different type of pin. By using the analogRead function, we can read the voltage applied to one of the pins. This function returns a number between 0 and , which represents voltages between 0 and 5 volts.
For example, if there is a voltage of 2. An analogue sensor circuit Advanced Input and Output www. Take a look at Figure again and hook the LED up to pin 9 as shown. For example, you could connect a thermistor, which is a simple device whose resistance changes with temperature. In the circuit, I have shown you how changes in resistance become changes in voltage that can be measured by Arduino.
If you need an exact reading, you should read the numbers that come out of the analogue pin while measuring with a real thermometer. You could put these numbers side by side in a table and work out a way to calibrate the analogue results to real-world temperatures.
Until now, we have just used an LED as an output device, but how do we read the actual values that Arduino is reading from the sensor? For this, we can have Arduino talk to a computer over a serial port, which is described in the next section. The good news is that this connection can also be used by the sketches that we write in Arduino to send data back to the computer or to receive commands from it.
For this purpose, we are going to use a serial object an object is a collection of capabilities that are bundled together for the convenience of people writing sketches. This object contains all the code that we need to send and receive data. Type this code into a new sketch you can also download the code from www. Now, any software that can read from the serial port can talk to Arduino. There are many programming languages that let you write programs on your computer that can talk to the serial port.
Processing www. If you try to drive something like a motor, the pin will immediately stop working, and could potentially burn out the whole processor. To drive bigger loads like motors or incandescent lamps, we need to use an external component that can switch such things on and off and that is driven by an Arduino pin.
It is something like the light switch that we use at home, where the action of a finger turning the light on and off is replaced by a pin on the Arduino board sending voltage to the gate of the MOSFET.
This means that electricity will flow though a piece of semiconductor material between the Drain and Source pins when a voltage is applied to the Gate pin. As the Gate is insulated from the rest through a layer of metal oxide, there is no current flowing from Arduino into the MOSFET, making it very simple to interface. They are ideal for switching on and off large loads at high frequencies.
You will also notice that the motor takes its power supply from the 9 V connector on the Arduino board. If the motor randomly turns on during upload, place a 10K resistor between pin 9 and GND. Complex Sensors We define complex sensors as those that produce a type of information that requires a bit more than a digitalRead or an analogRead function to be used. These usually are small circuits with a small microcontroller inside that preprocesses the information.
Some of the complex sensors 68 Getting Started with Arduino www. A motor circuit for Arduino Advanced Input and Output www. Analog Output This gives us the ability to control the brightness of the LED, not just turn it on or off.
We can even control the speed of a motor with it. Digital Input This allows us to read the state of simple sensors, like pushbuttons or tilt switches.
This chapter should show you how every single example can be used as a building block for a complex project. Here is where the wannabe designer in me comes out. Talking to the Cloud www.
The finished lamp The lamp, as you can see in Figure , is a simple sphere sitting on a base with a large hole to keep the sphere from rolling off your desk.
This design allows you to orient the lamp in different directions. In terms of functionality, we want to build a device that would connect to the Internet, fetch the current list of articles on the Make blog blog.
The lamp itself has a button we can use to turn it on and off, and a light sensor for automatic activation. First of all, we need Arduino to be able to connect to the Internet.
Usually what people do is run an application on a computer that will connect to the Internet, process the data, and send Arduino some simple bit of distilled information. Processing Processing is where Arduino came from. We love this language and use it to teach programming to beginners as well as to build beautiful code. Processing and Arduino are the perfect combination. Another advantage is that Processing is open source and runs on all the major platforms Mac, Linux, and Windows.
It can also generate standalone applications that run on those platforms. The proxy does the following work for us: it downloads the RSS feed from makezine. The board will send back the amount of light measured by the sensor and show it on the computer screen.
Hexadecimal numbers are handy, because each 8-bit number is stored in exactly two characters; with decimal numbers this varies from one to three Talking to the Cloud www. Predictability also makes the code simpler: we wait until we see an , then we read the six characters that follow into a buffer a variable used as a temporary holding area for data. Finally, we turn each group of two characters into a byte that represents the brightness of one of the three LEDs. Here is the code for the Processing sketch.
You can download it from www. Kurt todbot. First, you need to tell Processing to generate the font that we are using for the sketch. To do this, create and save this sketch.
Second, you will need to confirm that the sketch is using the correct serial port for talking to Arduino. On most systems, this Processing sketch will run fine. Here is the Arduino sketch also available at www. You need to use 10K resistors for all of the resistors shown in the diagram, although you could get away with lower values for the resistors connected to the LEDs.
Remember from the PWM example in Chapter 5 that LEDs are polarized: in this circuit, the long pin positive should go to the right, and the short pin negative to the left.
Most LEDs have a flattened negative side, as shown in the figure. Next, load the sketches into Arduino and Processing, then run the sketches and try it out. The three shorter leads will need to connect to Arduino pins 9, 10, and 11 with a resistor between the leads and the pins, just as with the separate red, green, and blue LEDs.
You will no longer be plugging this into the wall. Strap the Arduino on a breadboard and hot-glue the breadboard onto the back of the lamp. Connect the wires coming from the LED to the breadboard where it was connected before you removed it. Either find a nice piece of wood with a hole that can be used as a stand for the sphere or just cut the top of the cardboard box that came with the lamp at approximately 5cm or 2" and make a hole with a diameter that cradles the lamp.
Reinforce the inside of the cardboard box by using hot glue all along the inside edges, which will make the base more stable. As an exercise, try to add code that will turn on the lamp when the room gets dark. Other possible enhancements are: » Add tilt sensors to turn the lamp on or off by rotating it in different directions. Think of different things, experiment, and have fun! Troubleshooting and debugging are ancient arts in which there are a few simple rules, but most of the results are obtained through a lot of work.
The more you work with electronics and Arduino, the more you will learn and gain experience, which will ultimately make the process less painful. As every Arduino-based project is made both of hardware and software, there will be more than one place to look if something goes wrong.
Electrical Installation Work. A Textbook of Electrical Technology. Automotive Electrical Handbook. Picture of the book: Automotive Ele…. Pro Arduino. Picture of the book : 3…. Advanced Electrical Installation Work. Picture of the book : Advan…. Arduino Project Handbook Volume 1. Picture of the book: Arduino Pro….
Arduino Download Getting Started with Arduino pdf. Getting Started with Arduino.
0コメント