The arduino inventors guide free download






















Android Phones For Dummies Arduino: A Step-by-step Guide Ipad Pro: The Arduino: Step-by-step Guide To Chapter 3: 9-Pixel Animation Machine. Chapter 6: Balance Beam - video.

Chapter 7: Desktop Greenhouse. The book is not a book to read for theory, though we are hoping that you will learn a lot from it. This book is designed for doing! We see this book as a first step for many to take down the road of inventing the projects of their dreams — and through building some of ours, to learn some tips, tricks and skills necessary to be able to bring those ideas to reality in the form of rough prototypes.

This book should be read with a tool holding it open to a page that may be a little greasy or singed from a blow torch. You should read it through a pair of safety glasses with a soldering iron in one hand and a grip of wire in the other. You may have bandages around your fingers or a callus from using a craft knife, and you won't be able to see your floor under the cardboard scraps strewn about.

This book should be read not through your mind, but through your hands; by building the projects in it and allowing yourself to be inspired to hack them, modify them, make them better! There is no greater honor to this book in our minds than for people to improve the contents of the book. The projects in the book came from a number of conversations, workshops, whiteboard sessions and even arguments with friends, coworkers and other educators.

But, the idea of combining Arduino and electronics with simple craft supplies for me Derek can be tracked to a single moment in time. A ball bearing was placed in a groove on the beam, and you controlled the servo to move the beam back and forth and keep the ball bearing on it. I was going to use the balance beam as an example of a great Arduino project, but actually had forgotten it at home DOH! Out of desperation to be able to talk about the balance beam project, Jeff and I rebuilt one from cardboard out of the recycling bin and materials from the coffee table in the back of the room.

Project 5: Robot Ah, robots. Circuit 5A: Motor Basics In this circuit you will learn the basic concepts behind motor control. Note: The direction in which the motor wires face is arbitrary. Having them face out makes the circuit easier to build. Having them face in makes the circuit more robust against wires getting ripped out. Circuit 5C: Autonomous Robot Free the robots!

Make sure your switch is in the OFF position. As soon as the code is finished uploading, your robot will begin driving. Make sure it cannot drive off a table or other high surface and injure itself. Resources and Going Further Note: If you are refilling parts used in v4. Favorited Favorite 20 Wish List. Favorited Favorite 6 Wish List. Favorited Favorite 3 Wish List.

We can use the parts and concepts in the SparkFun Invetor's Kit to make a primitive keyboard instrument. An overview of each component in the SparkFun Sensor Kit, plus links to tutorials and other resources you'll need to hook them up. Favorited Favorite 6. Classroom STEM activity that has students build a battery from a lemon, measure the open and closed circuit voltages, and determine the battery's internal resistance.

Favorited Favorite 7. We use parts from the SparkFun Inventor's Kit v4. Favorited Favorite 8. Modify a simple desk lamp to respond to a double clap or other sharp noise using parts from the SparkFun Inventor's Kit v4.

We make a simple side-scrolling endless runner game using parts from the SparkFun Inventor's Kit v4. Favorited Favorite 0. Favorited Favorite 2. Favorited Favorite 35 Wish List. Favorited Favorite 30 Wish List. Favorited Favorite 9 Wish List. Comments 2 View Paginated Print. Your Account Log In Register. Polarized components can only be connected to a circuit in one direction. Every Arduino program needs these two functions. Code that goes in between the curly brackets of setup runs once, then the code in between the loop curly brackets runs over and over until the RedBoard is reset or powered off.

We use a built-in "function" called pinMode to make pin 13 a digital output. You'll learn more about digital inputs in Project 2. Causes the program to wait on this line of code for the amount of time in between the brackets.

After the time has passed, the program will continue to the next line of code. Comments are a great way to leave notes in your code explaining why you wrote it the way you did. You'll find many comments in the examples that further explain what the code is doing and why. Computer screens, movies and the lights in your house all flicker so quickly that they appear to be on all of the time but are actually blinking faster than the human eye can detect. See how much you can decrease the delay time in your program before the light appears to be on all the time but is still blinking.

Try changing the delays and adding more digitalWrite commands to make your program blink a message in Morse code. The most likely cause is that you have the wrong board selected in the Arduino IDE. If you're sure you have the correct Board selected but you still can't upload, check that you have selected the correct Serial Port. Depending on how many devices you have plugged into your computer, you may have several active Serial Ports. Make sure you are selecting the correct one.

A simple way to determine this is to look at your list of Serial Ports. Unplug your RedBoard from your computer. Look at the list again. Whichever Serial Port has disappeared from the list is the one you want to select once you plug your board back in to your computer. LEDs will only work in one direction. Try taking it out of your breadboard, turning it degrees, and reinserting it.

Jumper wires unfortunately can go "bad" from getting bent too much. The copper wire inside can break, leaving an open connection in your circuit.

If you are certain that your circuit is wired correctly and that your code is error-free and uploaded but you are still encountering issues, try replacing one or more of the jumper wires for the component that is not working. A variable is a placeholder for values that may change in your code.

You must introduce, or "declare" variables before you use them. Here we're declaring a variable called potPosition of type int integer. We will cover more types of variables in later circuits.

Don't forget that variable names are case-sensitive! Serial commands can be used to send and receive data from your computer. This line of code tells the RedBoard that we want to "begin" that communication with the computer, the same way we would say "Hi" to initiate a conversation. Notice that the baud rate, , is the same as the one we selected in the monitor. This is the speed at which the two devices communicate, and it must match on both sides. We use the analogRead function to read the value on an analog pin.

This is the line that actually prints the trimpot value to the monitor. It takes the variable potPosition and prints whatever value it equals at that moment in the loop.

The ln at the end of print tells the monitor to print a new line at the end of each value; otherwise the values would all run together on one line. Try removing the ln to see what happens. Try multiplying, dividing or adding to your sensor reading so that you can change the range of the delay in your code. For example, can you multiply the sensor reading so that the delay goes from 0— instead of 0—? Add more LEDs to your circuit.

Don't forget the current limiting resistor for each one. Try making multiple LEDs blink at different rates by changing the range of each using multiplication or division. Make sure that your 5V, A0 and GND pins are properly connected to the three pins on your potentiometer. It is easy to misalign a wire with the actual trimpot pin. Make sure that you have selected the correct baud rate, Also ensure that you are on the correct Serial Port.

The same Serial Port you use when uploading code to your board is the same Serial Port you use to print values to the Serial Monitor. For example, this sketch uses an if statement to turn the LED on when it is dark, and turn the LED off when it is light. Programmers use logic statements to translate things that happen in the real world into code. When the comparison is true e. Try using digitalWrite and delay to make the LED blink a pattern when the light level drops, then calibrate the threshold variable in the code so that the blink pattern triggers when you wave your hand over the sensor.

Now what happens when you place your finger over the photoresistor? This is a great way to see Ohm's law in action by visualizing the change in resistance's affect on the current flowing through the LED. Start the Serial Monitor in Arduino. Look at the value that the photoresistor is reading in a bright room e.

Cover the photoresistor, or turn the lights off. Then look at the new value that the photoresistor is reading e. Set the threshold in between these two numbers e.

Try unplugging your USB cable and plugging it back in. The analogWrite function outputs a voltage between 0 and 5V on a pin. The function breaks the range between 0 and 5V into little steps. Note that we are not turning the LED on to full brightness in this code so that the night-light is not too bright.

Feel free to change these values and see what happens. A nested if statement is one or more if statements "nested" inside of another if statement. If the parent if statement is true, then the code looks at each of the nested if statements and executes any that are true. If the parent if statement is false, then none of the nested statements will execute. In this line, the if statement will only be true if the value of the variable potentiometer is greater than 0 AND if the value is less than or equal to This simple version of a function executes the code inside the curly brackets whenever the name is written in the main program.

Calls a function that you have created. In a later circuit, you will learn how to make more complicated functions that take data from the main program these pieces of data are called parameters. Use the analogWrite function to blend different values of red, green and blue together to make even more colors. You can divide the potentiometer value up more and make more nested if statements so that you can have more colors as you twist the knob. Try setting your threshold variable by reading the value of a potentiometer with analogRead.

By turning the potentiometer, you can then change the threshold level and adjust your night-light for different rooms. Try using a loop with the analogWrite to get your LED to pulse gently or smoothly transition between colors.

Open the Serial Monitor in Arduino and make sure that your photoresistor is returning values between 0 and Try covering the photoresistor; the values should change. If they do not change, check the wiring of the photoresistor. If your photoresistor is working correctly, make sure that your threshold variable sits in between the value that the photoresistor reads when it is bright and the value that the photoresistor reads when it is dark e.

Then make sure that each LED is wired properly. The char , or character, variable to store character values. For example, in this sketch, the play function gets passed two variables, a character variable that represents the mucial note we want to play and an integer variable that represents how long to play that note.

A second array takes the character variable and associates a frequency value to it. This makes programming a song easier as you can just reference the character and not the exact frequency. The tone function will pulse power to a pin at a specific frequency. The duration controls how long the sound will play.

Tone can be used on any digital pin. To declare an array , you must give it a name, then either tell Arduino how many positions the array will have or assign a list of values to the array. To call one of the values in an array, simply type the name of the array and the index of the value.

You can use a variable instead of a number in between the square brackets. Try pressing the reset button on the RedBoard. It's easy to misalign a pin with a jumper wire. The advantage of external pull-ups is being able to choose a more exact value for the resistor. This is another logical operator. Two equals signs are equivalent to asking, "Are these two values equal to one another? Don't forget to add the second equals sign if you are comparing two values. Use the frequency table in the comment section at the end of the code to change the notes that each button plays.

By using combinations of buttons, you can play up to seven notes of the scale. You can do this in a few ways.

You can use a clever math equation to play more than three notes with your three keys. By multiplying each key by a different number, then adding up all of these numbers, you can make a math equation that produces a different number for each combination of keys.

Check your wiring. You may have ground and 5V backward if one or more buttons behave as though they're pressed all the time. First, make sure that the wiring is correct. It is easy to misalign a wire with a button leg. The millis function returns the number of milliseconds that have passed since the RedBoard was last turned on.

The name for these variables comes from Boolean logic. Using Boolean variables helps save memory on your microcontroller if you only need to know if something is true or false. Space in your microcontroller's memory is reserved when a variable is declared.

How much memory is reserved depends on the type of variable. Sometimes you will want to cycle through all of the LEDs or buttons connected to a project. You can do this by storing a sequence of pin numbers in an array. The advantage of having pins in an array instead of a sequence of variables is that you can use a loop to easily cycle through each pin. This turns one of the four LEDs on and plays the tone associated with it. Uses digitalRead to check which button is pressed.

Returns 0, 1, 2 or 3 if one of the buttons is pressed. Returns 4 if no button is pressed. Flashes the LEDs and plays tones in a sequence. Resets the round counter and generates a new random sequence for the user to remember. Plays a sequence of tones, turns all of the LEDs on, then waits for the player to press a button. If a button is pressed, restarts the game. Change the difficulty of the game by changing how fast the player has to press each button or by increasing or decreasing the number of rounds needed to win.

Ready for a real coding challenge? Try changing the code so that two players can play head-to-head. Make sure your LED is flipped around in the right direction. Carefully check your wiring for each button. One leg of the button should connect to a pin on the RedBoard; the other leg should connect to the ground rail on the breadboard. Make sure you don't have 5V and GND mixed up.

If you are certain that your circuit is wired correctly and that your code is error-free and uploaded, but you are still encountering issues, try replacing one or more of the jumper wires for the component that is not working.

The include command adds a library to your Arduino program. After you include a library, you can use the commands in the library in your program.

This line adds the Servo library. The Servo command creates a new servo object and assigns a name to it, myServo in this case. If you make more than one servo object, you will need to give them different names.

It will send position signals to this pin. In this sketch, pin 9 is used. Remember to only use digital pins that are capable of PWM. As shown in previous circuits, the analog pin values on your microcontroller vary from However, what if we want those values to control a servo motor that only accepts a value from ?

The answer is to use the map function. The map function takes a range of values and outputs a different range of values that can contain more or less values than the original. In this case, we are taking the range and mapping it to the range In this example, the servo is being told to go to angle Try altering the map function so that moving the potentiometer a lot only moves the servo a little.

Try swapping a light sensor in for the potentiometer. You have just made a dial that reads how much light is present! Check the wiring on your servo. Make sure that the red wire on the servo cord is connected to 5V, the black wire is connected to GND and the white signal wire is connected to pin 9. Although these servos are supposed to move from 0 to degrees, sometimes sending them to the extremes of their range causes them to twitch the servo is trying to move farther than it can.

Echo Pulse Output: Receives echo signal. Range is calculated by the proportion of trigger signal sent and echo signal received. The float variable, short for floating-point number, is similar to an integer except it can represent numbers that contain a decimal point.

Floats are good for representing values that need to be more precise than an int. Floats allow us to measure precise distances such as 9. Else if statements let you combine more than one logic statement. Arduino will test each logic statement in order; if one is true it will run the code in that section and then skip all of the other sections of code in the if statement.

This function tells the distance sensor to send out an ultrasonic wave form, measures the time it takes to bounce back to the sensor, then calculates the distance based on the speed of sound.

This calculation is based off information found in the distance sensor's datasheet. Try editing the code so that the distance sensor outputs a different unit of length, such as centimeters or feet.

Check the connection for the wire and resistor connected to each leg of the LED. Open up the serial monitor on your computer. You should see a stream of distances being printed in the monitor.

If they are all reading 0 or jump around, then check the wiring on your sensor. Ultrasonic noise pollution will interfere with your distance sensor readings.

If you aim two distance sensors at each other, they will confuse each other. Some air-conditioning systems may also emit noises in the ultrasonic range. Try pointing your sensor away from the other distance sensors or changing to a different location.

Constants are variables that have been marked as "read-only" and cannot have their value changed as the program progresses. Constants are great for declaring pin number variables that will not change throughout the program. In circuit 2A you made songs using a buzzer and the tone function, but you gave the tone function three parameters: a pin number, a frequency and a duration.

You can leave out the third parameter, and the tone will play until you change it or turn it off. Try your hand at making different objects move with your servo motor. Make an interactive pop-up story. Make an automatic fish feeder. Time to use your imagination! Open up the Serial Monitor on your computer. If they are all reading 0 or jumping around, then check the wiring on your sensor.

Some air conditioning systems may also emit noises in the ultrasonic range. Make sure all of your servo wires are connected. Be sure that the black wire is connected to the negative rail and the red wire is connected to the positive rail. Make sure you are using a digital pin that is capable of PWM.

The two lines of code that pass angles to the servo motor are myservo. Try changing these angle values to fine-tune your mechanism. As with servos, you need to create an LCD object and give it a name you can make more than one. Keep in mind that when the gate opens, it will rotate clockwise. Now you need a track. You can use a standard Hot Wheels track, which will fit on the lower support, or build your own track. On each side, measure and mark a line that is a quarter inch from the edge.

Now, fold along the lines so that you have a quarter-inch lip on each side of your track. The lip will keep your car from flying off the track and also adds a small amount of structural integrity. Your track should look similar to the one pictured in Figure Now, using a small handheld hole punch, make a hole about a half inch from the end of your track for your photoresistor.

Just be careful when cutting through the paper, and always use a cutting mat when using a knife. The hole needs to be just large enough for the head of the photoresistor to fit inside. The photoresistor will be your finish-line sensor. There is a small hole at the end of a standard Hot Wheels track, slightly smaller than the diameter of the photoresistor sensor.

Thankfully, the plastic track is flexible enough that you can simply press the head of the photo-resistor through this hole. Remove the photoresistor from the breadboard and bend the legs at a right angle along the head so that it looks like Figure Insert the head of the photoresistor through the hole in your track. Make sure that the photoresistor does not stick out too much, or your car will catch on it; the car should be able to roll over the sensor without interference. With the legs bent at right angles, you should be able to tape them down securely to the bottom side of the track, as shown in Figure Reconnect the photoresistor to your breadboard using a pair of male-to-female jumper wires.

Well, you have the total time it takes for the car to reach the bottom of the track, and you know the length of the track. With these two pieces of information, you can estimate how fast the car is moving. Average speed is defined as distance traveled per unit of time. So, to find the average speed, you need to measure the length of the track and divide this value by the time elapsed.

Our track measures about 8. If we divide these two numbers, we get an average speed of Remember that this is the average speed of the car. How fast is your car moving? Finally, rest the end of your race track without the photoresistor on the starting tower so that the ramp extends past the tower by about the length of your toy car see Figure This will be the starting position.

Push the reset button to make sure that the sketch starts over, and find your favorite Matchbox or Hot Wheels car and set it behind the starting gate.

Push the starting button and watch your car go! How long did it take to reach the bottom? On our track, our toy cars took just over 0. Try a few different cars, or invite some friends over to see whose car is the fastest. If you tape a few pennies to your car, does it go faster? Experiment and see how different things affect the drag race time of your car. In this project, we introduced you to using the LCD to display information directly from your Arduino sketch.

Racing against yourself is only so much fun. See Figure Find a friend who also has a kit, buy one separately, or find one in the additional parts kit for this book. First you need to create a separate finish-line sensor circuit. We were able to sneak in one more photoresistor and a pull-down resistor circuit near the bottom of the breadboard, as shown in Figure Place the photoresistor in the second track, and add male-to-female jumper wires to connect this to your circuit on the breadboard.

Set your second track next to the first one on the starting tower. You only need to add a few extra lines to allow for the two cars to race. First, the code adds a new constant and variable for the second photoresistor finishline sensor, finishSensor2Pin and finishSensor2. Then, it checks which sensor was crossed first using a compound if statement. If car 1 crosses first, finishSensor1 will be 0 and finishSensor2 will still be 1.



0コメント

  • 1000 / 1000