Player FM - Internet Radio Done Right
Checked 1+ y ago
הוסף לפני five שנים
תוכן מסופק על ידי Programming Electronics Academy. כל תוכן הפודקאסטים כולל פרקים, גרפיקה ותיאורי פודקאסטים מועלים ומסופקים ישירות על ידי Programming Electronics Academy או שותף פלטפורמת הפודקאסט שלהם. אם אתה מאמין שמישהו משתמש ביצירה שלך המוגנת בזכויות יוצרים ללא רשותך, אתה יכול לעקוב אחר התהליך המתואר כאן https://he.player.fm/legal.
Player FM - אפליקציית פודקאסט
התחל במצב לא מקוון עם האפליקציה Player FM !
התחל במצב לא מקוון עם האפליקציה Player FM !
פודקאסטים ששווה להאזין
בחסות
Grumpy helps a reader choose the best hydrangea for their hometown. Plus, Grumpy’s gripe of the week. You can find us online at southernliving.com/askgrumpy Ask Grumpy Credits: Steve Bender aka The Grumpy Gardener - Host Nellah McGough - Co-Host Krissy Tiglias - GM, Southern Living Lottie Leymarie - Executive Producer Michael Onufrak - Audio Engineer/Producer Isaac Nunn - Recording Tech Learn more about your ad choices. Visit podcastchoices.com/adchoices…
Using Red-Green-Blue (RGB) LEDs with Arduino (Common Cathode Type)
Manage episode 269164117 series 2774299
תוכן מסופק על ידי Programming Electronics Academy. כל תוכן הפודקאסטים כולל פרקים, גרפיקה ותיאורי פודקאסטים מועלים ומסופקים ישירות על ידי Programming Electronics Academy או שותף פלטפורמת הפודקאסט שלהם. אם אתה מאמין שמישהו משתמש ביצירה שלך המוגנת בזכויות יוצרים ללא רשותך, אתה יכול לעקוב אחר התהליך המתואר כאן https://he.player.fm/legal.
In this tutorial we describe using RGB LEDs of the Common Cathode Type. We will describe setting up the circuit, talk about the LED and discuss the code used to adjust the hue.
61 פרקים
Manage episode 269164117 series 2774299
תוכן מסופק על ידי Programming Electronics Academy. כל תוכן הפודקאסטים כולל פרקים, גרפיקה ותיאורי פודקאסטים מועלים ומסופקים ישירות על ידי Programming Electronics Academy או שותף פלטפורמת הפודקאסט שלהם. אם אתה מאמין שמישהו משתמש ביצירה שלך המוגנת בזכויות יוצרים ללא רשותך, אתה יכול לעקוב אחר התהליך המתואר כאן https://he.player.fm/legal.
In this tutorial we describe using RGB LEDs of the Common Cathode Type. We will describe setting up the circuit, talk about the LED and discuss the code used to adjust the hue.
61 פרקים
Alla avsnitt
×Have you seen some really cool stuff being made with a thing called Arduino? What is Arduino anyway? It sounds like an Italian sandwich with extra cheese or something... Well - it's that and a lot more. I hope this video can help explain some the basic premise of the Arduino!
Have you ever wanted to change the font color in the Arduino IDE? Maybe it is hard for you to read the light grey comments in the Arduino IDE, or maybe you prefer something a little bolder. Whatever your reason, in this short video, I demonstrate a relatively easy way to change the font color of comments.…
In many cases while using an Arduino, you will want to see the data being generated by the Arduino. One common method of doing this is using the Serial.print() function from the Serial library to display information to your computer’s monitor. In this week’s episode we will talk about the intricacies of the Serial.print() function. This is the second part of a two part series on the Serial.print() function (Click here for the first part). Here are the exact topics we will cover in this lesson: Adjusting the number of digits to be displayed after the decimal point with the Serial.print() function. Adjusting the format to display with the Serial.print() function Formatting the output with text and tabs If you enjoyed this video, you should consider signing up for our free Arduino Crash Course - it has 19 high quality video training classes to help build your imagination with Arduino.…
In many cases while using an Arduino, you will want to see the data being generated by the Arduino. One common method of doing this is using the Serial.print() function from the Serial library to display information to your computer’s monitor. In this week’s episode, we will talk about the intricacies of the Serial.print() function. This is the first part, of a two part series on the Serial.print() function. Here are the specific topics we will cover in this lesson: Why would you want to use the Serial.print() function? A brief overview of the Serial library The basic use of the Serial.print() function Like this video? Sign up for our FREE Arduino Crash Course to get more videos that don't assume you have a PhD. Why Would You Want to Use the Serial.print() Function? You may know that a function is a programming tool - it performs a specific task for you. The Serial.print() function’s task is to send information from your Arduino to your computer, so you can see the value displayed on your computer’s monitor. There are an endless number of reasons you may want to send information from the Arduino to a computer display, but two reasons really stand out to me: The first reason is being able to see information that you are generating with your Arduino. For example, if you have a temperature sensor hooked up to your Arduino and you want to see the value that the temperature sensor is recording, then you can use the Serial.print() function to send the data to a computer monitor via the USB cable. If you open up the serial monitor window (Tools > Serial Monitor), you will see the values streaming in from the Arduino. The other big reason to send information to a computer display using the Serial.print() function is for developing and debugging Arduino sketches. Very often, when you are developing an Arduino sketch, what you end up coding does something differently than what you expected it to do. Maybe you have a variable that gets incremented every so often and blinks an LED when it reaches a threshold. When you upload the code to the Arduino, you notice that the LED is blinking more often than it should. You can look at the code until your eyes bleed, but actually visualizing the variable being incremented [via the Serial.print() function], to see its values every time through the loop() can help explain what is happening very quickly. A Brief Overview of the Serial Library We can’t talk about the Serial.print() function, without briefly talking about the Serial library. Generally speaking, a library is simply a collection of functions that all have something in common. The print() function is part of a library called the Serial library. Now, it's not cereal like Cheerios or Captain Crunch we're talking about - it's serial as in “one after another”. The serial library allows us to interface the Arduino with other hardware, like a computer. In order for us to use the functions of the Serial library, we have to initiate serial communication - to do this we use the Serial.begin() function. Serial.begin() needs to go in the setup(). void setup() { //Initiate Serial communication. Serial.begin(9600); } Now for reasons beyond the scope of this discussion, it is convenient to use the number 9600 in the Serial.begin() function. The value 9600 specifies the baud rate. The baud rate is the rate at which information will pass from the Arduino to the computer, or in the other direction. The Basic Use of the Serial.print() Function Let's talk about how to use the Serial.print() function. Say we have a sketch. This sketch has a variable called coolFactor . I want to be able to monitor the value of the coolFactor variable – that is, I want it displayed on my computer screen. A perfect use for the Serial.print() function! The first thing we must do in the Arduino sketch is begin serial communications. Like we just said, we use the Serial.begin() function and place it within the setup() of the sketch. //A variable to hold the level of coolness int coolFactor = 3; void setup() { Serial.begin(9600); } void loop() { //Send the value of coolFactor to the the Serial port. //So we can see it in the serial monitor window Serial.print(coolFactor); } Now in the loop(), if I want to display coolFactor ’s value with print(), I simply type Serial.print() and in the parenthesis I type the variable name. If we upload this sketch to the Arduino, the value of coolFactor will be sent to the serial port every time through the loop(). In the Arduino IDE, if you open up the serial monitor window [Tools > Serial Monitor], you will see the values streaming down. In next week’s episode, we’ll talk about some more intricacies of the Serial.print() function. If you enjoyed this lesson, I welcome you to join 1000's of students who have enjoyed our free Arduino Crash Course - it's a 19 part video training series on using Arduino (You can sign up below).…

1 How to make a secret knock detector to trigger anything with only an Arduino and a few cheap components 12:57
12:57
הפעל מאוחר יותר
הפעל מאוחר יותר
רשימות
לייק
אהבתי12:57
There are a couple good use-case scenarios for making a secret knock detector using an Arduino. You are a spy who needs to authenticate your cohorts You are a super hero who wants a secret knock to open the entrance to your lair Whatever the reason - by the end of this tutorial you will know how to use an Arduino, a piezo transducer and a couple other cheap components to make secret knock detector. Here is an overview of exactly what we will talk about in this lesson: The components you will need and how to set up this simple circuit. The concept of operation of this secret knock detector A thorough description of each block of code in the Arduino sketch Why North American grizzly bears love piezo transducers For this secret knock detector circuit you need: Arduino (I use the Arduino Uno) [1] Solderless breadboard [1] 1 Mohm Resistor [1] Piezo transducer (aka buzzer) [1] Jumper wires [4] 5.1V Zener diode (for extra protection) [1] No spill stopper for a “to-go” coffee cup How to set up the Circuit: This is a really simple circuit to setup, below are step-by-step instructions and a breadboard diagram. Place the piezo transducer on the breadboard, with the positive lead and the negative lead on separate rails. Connect the positive lead to pin A0 on the Arduino and the other lead to ground. Finally, use the 1Mohm resistor to connect the leads of the piezo transducer. As an additional level of protection, you might consider adding a 5.1V zener diode between the leads to protect against high voltage spikes from frying your input pin - you might call it a cheap insurance policy. An Overview of this Secret Knock Detectors operation Here is the basic concept of how this will work. We want something to happen when you tap out a secret code. We will create a sequence of soft and hard taps - this will be our secret code which will be represented as 0’s and 1’s in an array . For example: secretKnock[secretKnockLength] = {0, 0, 1, 0}; The code above represents a secret code of soft , soft , hard, soft . The piezo transducer will turn the mechanical pressure created by the tap into a signal that the Arduino analog pin can read . The level of the signal will determine whether a tap gets characterized as soft or hard. The threshold of a soft vs hard tap need to be determined empirically, once you have the circuit built - it will depend on what you have the piezo transducer attached to - I have mine taped to a piece of paper. You should start with the default threshold values provided in the sketch and change them to suit your specific setup. Once a tap signal is picked up by the Arduino, the sketch will compare the entered sequence of taps to the secret code, one tap at a time. If the code is entered correctly, then we will trigger an action on the output pin. In this code below, we trigger an LED to turn on for a couple seconds - but you could trigger a servo arm, a pump, or whatever you might need. If the code is entered incorrectly - nothing happens. Here is the code for your hacking enjoyment: /* A simple sketch to detect a secret knock using a piezo transducer Created JUL 2015 by Michael James http://www.programmingelectronics.com/ This code is in the public domain */ const int outputPin = 6; // led indicator connected to digital pin const int knockSensor = A0; // the piezo is connected to an analog pin const int thresholdHIGH = 150; // threshold value to decide when the detected knock is hard (HIGH) const int thresholdLOW = 120; // threshold value to decide when the detected knock is gentle (LOW) const int secretKnockLength = 4; //How many knocks are in your secret knock /* This is the secret knock sequence * 0 represents a LOW or quiet knock * 1 represents a HIGH or loud knock * The sequence can be as long as you like, but longer codes increase the difficulty of matching */ const int secretKnock[secretKnockLength] = {0, 0, 1, 0}; int secretCounter = 0; //this tracks the correct knocks and allows you to move through the sequence int sensorReading = 0; // variable to store the value read from the sensor pin void setup() { //Set the output pin as an OUTPUT pinMode(outputPin, OUTPUT); //Begin Serial Communication. Serial.begin(9600); } void loop() { // read the piezo sensor and store the value in the variable sensorReading: sensorReading = analogRead(knockSensor); // First determine is knock if Hard (HIGH) or Gentle (LOW) //Hard knock (HIGH) is detected if (sensorReading >= thresholdHIGH) { //Check to see if a Hard Knock matches the Secret Knock in the correct sequence. if (secretKnock[secretCounter] == 1) { //The Knock was correct, iterate the counter. secretCounter++; Serial.println("Correct"); } else { //The Knock was incorrect, reset the counter secretCounter = 0; Serial.println("Fail - You are a spy!"); }//close if //Allow some time to pass before sampling again to ensure a clear signal. delay(100); //Gentle knock (LOW) is detected } else if (sensorReading >= thresholdLOW) { //Check to see if a Gentle Knock matches the Secret Knock in the correct sequence. if (secretKnock[secretCounter] == 0) { //The Knock was correct, iterate the counter. secretCounter++; Serial.println("Correct"); } else { //The Knock was incorrect, reset the counter. secretCounter = 0; Serial.println("Fail - You are a spy!"); }//close if //Allow some time to pass before sampling again to ensure a clear signal. delay(100); }//close if else //Check for successful entry of the code, by seeing if the entire array has been walked through. if (secretCounter == (secretKnockLength) ) { Serial.println("Welcome in fellow Illuminante!"); //if the sececret knock is correct, illuminate the LED for a couple seconds digitalWrite(outputPin, HIGH); delay(2000); digitalWrite(outputPin, LOW); //Reset the secret counter to 0. secretCounter = 0; }//close success check }//close loop If you enjoyed this lesson, you should join our free Arduino Crash Course - it has 19 Video Training lessons all about using Arduino (you can sign up below).…

1 Arduino Pseudo Random Non-Consecutive Number Generator 11:13
11:13
הפעל מאוחר יותר
הפעל מאוחר יותר
רשימות
לייק
אהבתי11:13
In this video we demonstrate how to create pseudo random numbers with Arduino - with a useful twist. This lesson was inspired by the following viewer question: How do I create Random Non-Consecutive numbers with Arduino? P.S. These are the best tutorials that a complete idiot like you could ever make, thanks. -Chris Let's overview exactly what we will talk about in today's episode: Talk about pseudo random numbers. Identify the problem - using an Arduino sketch to demonstrate. Discuss how we might solve the problem. Write an Arduino sketch that solves the problem. Review what we talked about. Before we answer the viewer’s question it is important to talk about what a pseudo random number is. A purely random number in the mathematical sense can't be predicted. The microcontroller that the Arduino uses (and for that case, most computers in general) can't really create pure random numbers. What they create instead are called pseudo random numbers . These are numbers that appear to be randomly generated, but if studied over time a predictable pattern emerges. The bottom line is that the random numbers we create with Arduino can be predicted. Now there are clever ways to create pseudo random numbers that act like the real deal – you can learn about one method in our video tutorial talking all about random numbers – but for this discussion, let’s return to our viewers inquiry. Identify the Viewer’s Problem - use an Arduino sketch to demonstrate. Ok, so let's go back to the viewers question, he wants to generate random numbers, but he never wants the same number generated two times in a row. Let's write an Arduino Sketch to make this clear. //This sketch outputs pseudo random integers. //A variable to hold pseudo random integers. int randomInt = 0; void setup() { //Initiate serial communication. Serial.begin(9600); }//Close setup function void loop() { //Create a random number and assign it to the randomInt variable. randomInt = random(0, 10); //Send randomInt to the serial port for displaying on the serial monitor window. Serial.print(randomInt); }//Close loop function. In the first block of code a variable that will hold the pseudo random integers is declared and initialized. //A variable to hold pseudo random integers. int randomInt = 0; In the setup() function we begin serial communication in order to display the numbers we generate on a computer display. void setup() { //Initiate serial communication. Serial.begin(9600); }//Close setup function In the loop() we create the random number with the Arduino random() function and assign the output to the variable we had just created. The random() function can take two arguments 1) the minimum value of the number we want generated 2) the maximum value we want generated. //Create a random number and assign it to the randomInt variable. randomInt = random(0, 10); I will use 0 for the minimum, and 10 for the maximum. Every time through the loop, a new random number will be assigned the randomInt variable. Finally, the value of randomInt is sent over the serial port to be displayed in the serial monitor window. //Send randomInt to the serial port for displaying on the serial monitor window. Serial.print(randomInt); If you upload this code and open the serial monitor you will see in some cases where the same number shows up two times in a row. This is the problem. The viewer doesn't ever want the same number two times in a row. Discuss how we might solve the problem. So let's talk about how we might solve this problem. We know we need to generate a random number. What if we create a variable to track the previous random number? Then we could use a condition that says something like "If the previous random number is equal to the random number that was just generated, toss that number out the window, and create a different one.” The final thing we would need to do is set the previous random number equal to the new random number, that way we keep updating our previous random number every time through the loop(). Let’s Implement our solution in an Arduino Sketch. Copy and paste this code into your Arduino IDE. All you need is an Arduino board attached to your computer to make it work. //This sketch outputs pseudo random non-consecutive integers. //A variable to hold pseudo random non-consecutive integers. int randomInt = 0; //A variable to hold the previously assigned pseudo random non-consecutive integers. int previousRandomInt = 0; void setup() { //Initiate serial communication. Serial.begin(9600); }//Close setup function void loop() { //Create a random number and assign it to the randomInt variable. randomInt = random(0, 10); /*Check if the random number is the same as the previous random number. If it is, then reassign a new random number until it is different from the previously set one.*/ while (randomInt == previousRandomInt) { //Create a random number and assign it to the randomInt variable. randomInt = random(0, 10); //When a consecutive random number has been identified, indicate it. Serial.println(); }//close while statement //Set previousRandomInt equal to the current randomInt. previousRandomInt = randomInt; //Send randomInt to the serial port for displaying on the serial monitor window. Serial.print(randomInt); }//Close loop function. If you upload this code to your Arduino and open the serial monitor window you will see the numbers scrolling across the serial monitor window, but now you will not witness any duplicates side-by-side. You may notice some X’s intermittently between the numbers, this is where the Arduino sketch identified a duplicate random number and generated a replacement. If you look through the code, you will see this is accomplished with a While Statement . I hope you can find some application for this simple process of creating a pseudo random non-consecutive number with Arduino. Let me know what you think the comments!…
I don’t subscribe to many magazines, but I love my subscription to Make: magazine. And even though I rarely have time to sit down and enjoy a magazine in peace and quiet (parents forget what peace and quiet means), I still manage to get through my Make: magazine cover to cover. I like it that much! This video is a short review of why I enjoy Make: magazine, and why I think you would enjoy it too. Here are some highlights: 1. Make: Magazine is published every 2 months. 2. Filled with detailed step-by-step projects 3. Has interesting editorial articles about technology 4. Covers a lot of hobby electronics topics (like Arduino) 5. Has sections dedicated to skill building Total Honesty: Nobody paid me to make this review of Make: magazine. I made this video because I personally enjoy the content and rigor and think you might like it too. That being said - if you are interested in subscribing to Make: magazine I would love for you to use the link below if you so choose: Click Here to Check Out Make: Magazine The above is an affiliate link. At no additional cost to you, I get a kick back from subscriptions that originate from the link. This cash allows me to furnish my mansion in downtown Manhattan, make necessary repairs to my yachts, and fuel the Lamborghini for joy rides. Do you subscribe to Make: magazine? I would love to hear your thoughts in the comments.…
Understanding how the Arduino IDE sets up its file directory system can spare you some confusion when it comes to saving, organizing and opening your Arduino sketches (or sketches you have downloaded from the internet). This week’s episode covers the following: The Arduino Sketchbook folder How to change the default location where your Arduino sketches get saved What happens when an Arduino file does not have an enclosing sketch folder of the same name Where and how multiple tabs get saved in an Arduino sketch Why the pancreas of a woodchuck is better suited than our own Want to fast-track your Arduino skills? Click here to join our 12-part HD Video Course. You are probably familiar with a file directory system on a computer. It's usually represented as a hierarchy of folders and files. An example would be your C Drive - inside the C drive, you may have a folder for Applications, Users, and Systems files. Inside the Users folder, you might have subfolders for Documents, Downloads, Music, etc. All the files on the computer get organized in this fashion, and Arduino sketches are no exception. The Arduino Sketchbook Folder and Changing the Default Save Location The default location where Arduino sketches you write will be saved is called the Sketchbook. The Sketchbook is simply a folder on your computer like any other. It acts as a handy repository for sketches and is also where add-on code libraries get saved. You can see the sketches in the Sketchbook folder by going to File > Sketchbook. The default name of the Sketchbook folder is “Arduino” and the default location of the Sketchbook folder is in the “My Documents” folder (or just “Documents” for Mac users). If your Sketchbook does not appear to be in this default location, you can see exactly where it is by opening the Arduino IDE and going to Arduino > Preferences. The default file path for your sketches is listed at the top of Arduino Preferences window. Mine is: /Users/michaelJames/Documents/Arduino When I save a file in the Arduino IDE, this “Arduino” folder is the default location where the sketch will be saved, unless I choose to change that location by selecting a different folder on my computer's directory. If you want to change this default location, you click the Browse button next to the file directory path and choose a different place. Pretty simple. Sketch Folders If you go into your file directory system and open up the Sketchbook folder (again, named “Arduino” by default), you may see a bunch of folders that you didn’t make. This is because every Arduino file must be inside a folder that has the same name as the file (there are some exceptions to this that we'll talk about in a moment). Let me say that one more time because it is really important to understand. Every Arduino file must be inside a folder that has the same name as the file When I write a new sketch and save it, the Arduino IDE automatically creates a new folder that has the exact same name as the sketch itself. The Arduino file (which has the extension .ino) is placed inside this enclosing folder, which is called a sketch folder. If you go into the Sketchbook folder and change the name of the enclosing folder, it will create some issues. The first issue is that when you go to File > Sketchbook, the sketch will no longer show up! If you want to open this sketch you need to go to the .ino file in your directory and open it from there. If you open a .ino file that is not inside an enclosing sketch folder of the exact same name, then you will get a pop-up from the Arduino IDE that says: “The file “sketch_name.ino” needs to be inside a sketch folder named “sketch_name”. Create this folder, move the file, and continue?” If you choose Cancel, the sketch will not open. If you choose OK, then a folder gets created (it will have the same name as the sketch) and the .ino file is placed inside it. This sketch folder will be created in whatever directory the .ino file was that you tried to open. For example, if you tried to open a .ino file that was in your My Downloads folder, then the enclosing sketch folder also will be created inside the My Downloads folder. Saving Tabs in Arduino The exception to the rule about the sketch folder having the same name as the .ino file is when you create multiple tabs in an Arduino sketch. The additional tabs do NOT need to bear the same name as the enclosing sketch folder. Once you get a handle on some of these intricacies of the Arduino IDE file system, it can really help to clear things up. Please take a moment to leave a comment if you have any insights or thoughts about this tutorial. I would love to hear them!…
In this video we talk about an Arduino shield designed to teach you about shift registers, I2C, SPI, temperature sensors, real time clocks, analog to digital convertors and flash memory chips - all this on one awesome Arduino shield! Electronics Concepts can be Intimidating Like any industry or hobby, electronics has its fare share of acronyms. A couple of the more common ones you might have come across are SPI, I2C, ADC, RTC and YOMAMA. All these acronyms can be intimidating. It’s like this giant lion staring you down. You can spend a lot of time reading about each of these concepts, buying a bunch of different parts and working up breadboards - this is a great way to learn – it’s kind of the common path many hobbyist and professionals have taken alike. But if you want to grab the lion by the throat - I would like to introduce you to my new favorite Arduino shield. The Rheingold Heavy Education Shield . It's an Arduino shield designed to teach you about the ins and outs of all these really common electronics concepts (like I2C and SPI) and applying that understanding to hardware (like analog to digital convertors and Flash RAM). It’s not just the shield that makes this an education board, it’s all of the really thorough documentation and tutorials that accompany the hardware on the Rheingold Heavy website. Have Fun Learning Electronics If you are going to learn electronics, you might as well have fun doing it. That's one great thing about the Rheingold Heavy tutorials - they are fun - the author has a great sense of humor and keeps things real. He does a great job at demystifying electronics concepts that on the outside seem extremely complex, but dissected piece by piece can be made elementary. I would say my favorite part about the tutorials is the depth and detail they cover. I think this line from one of the introductory tutorials captures the style of the author… ...I don’t like “just making it work” — I want to know why it works the way it does. Hardware and Education Unite The real magic happens when you have the Education Shield and start working through the tutorials. The lessons on the Rheingold Heavy website are all designed step-by-step to walk you through understanding in detail the hardware on the shield. The lessons are a good length, focus on just a couple concepts at a time and get into the nuts and bolts. The Rheingold Heavy Education Shield itself is jam packed with components. It's got a shift register hooked up to 8 surface mount LEDs for learning about shift registers, a real time clock, a temperature sensor, a 10 bit analog to digital convertor, and 8Mbytes of Flash RAM. All this hardware you learn to use with either I2C protocol or SPI! It’s like an electronics learning laboratory on a single Arduino shield . If you already have a handle on some of these concepts, and you don’t think you need the whole shield, you can purchase breakout boards for each separate component and all the documentation on the website works equally well for those. I know I’ve said it once, but it deserves saying again - the tutorials are written in a fun and relaxing tone - with tons of diagrams, questions along the way to make sure you’re on track and Arduino code to help experiment with the shield and concepts. History of the Rheingold Heavy Education Shield The brainchild of this education shield is Dan Hienzsch. In 2014 he ran a successful Kickstarter campaign that brought these shields to fruition. After successfully fulfilling all his Kickstarter backers (and on time!) he has set up shop and is now churning out these education shields all over the world. My Unabashed Endorsement I am just little biased towards this education shield - I know Dan - he's a great guy and very passionate about what he does. After buying the shield and the breakout boards and working through the tutorials on the website I have learned a ton! The best part is how much fun it has been to work through the material. I love learning and if I can have a single “aha!” kind of moment everyday, then I sleep at night pretty good. My experience with the Rheingold Heavy Education Shield has brought me these moments left after right. Needless to say I highly recommend this Arduino shield to any body who wants to get a solid and detailed grasp of concepts like SPI and I2C, or about using real time clocks, analog to digital convertors, temperature sensors, shift sensor and a whole lot more. With all this education packed into Rheingold Heavy Education Shield , backed-up with really enjoyable tutorials, you can't go wrong.…
This week's Episode is what I am calling an intermission, which is basically me taking a break from hardcore Arduino tutorial making, and present a less technical topic. In this intermission video, I walk through the process I use when creating Arduino tutorials and some of the software that helps me do it. Here is a list of software I use when creating Arduino tutorials: Full Disclosure: Some of these are affiliate links that help me afford gold toilets on my private island. Brainstorming/ Mindmapping software (mac): MindNode Simple Text Editor (mac): TextMate Screen Capture software: Camtasia for Mac Audio Editing: Audacity Circuit Design: Fritzing More Robust Text Editor: Microsoft Word for Mac If you want to check out some of our best Arduino tutorials, sign up for our free Arduino Crash Course below.…
If you ever have a project using two or more Arduinos, it's likely you'll want them to work together. Say for example you have one Arduino connected to an LCD shield, and another Arduino controlling an LED matrix. You want both to do something when you press a single button - how can this be done? It turns out to be extremely easy. This video will describe in detail how to trigger multiple Arduinos with a single input. CODE: /* Button Turns on and off a light emitting diode(LED) connected to digital pin 13, when pressing a pushbutton attached to pin 2. The circuit: * LED attached from pin 13 to ground * pushbutton attached to GND through pin 2 on two (or more) Arduino's * Note: on most Arduinos there is already an LED on the board attached to pin 13. created 2005 by DojoDave modified 30 Aug 2011 by Tom Igoe Modified 16 APR 2015 by Michael James https://programmingelectronics.com/using-the-same-input-to-trigger-multiple-arduinos/ This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Button */ // constants won't change. They're used here to // set pin numbers: const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin // variables will change: int buttonState = 0; // variable for reading the pushbutton status void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT_PULLUP); } void loop() { // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); // check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == LOW) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); } } Breadboard Layout: Downloads: Schematic Fritzing File.fzz If you like this tutorial, check out some of out very best by signing up for our free Arduino Crash Course below.…
In this video we will be talking about some key points to keep in mind when assembling an Arduino shield from a kit. Many of these tips will apply equally well to any type of electronics kit you are assembling. So you just bought an awesome Arduino shield - it's going fly you to the moon and back, but before you start using it you have to do some basic assembly. Here are six tips to help you get the assembly done right the first time. Read the Directions: The first advice is painfully obviously, but still worth mentioning - read the directions! When all you have to do is solder on some pin headers and a couple LEDs, it's tempting to ignore the need for directions and just go at. You’re a genius right - who needs directions? As J.R.R. Tolkien said... "Shortcuts make for long delays". Even on simple assemblies it pays to take the time to read through the directions. Most companies keep the directions online – they are really only a search away. I'm telling you it’s worth it! Consider Where you Will be Assembling the Board: You may not have a dedicated space for your electronics addiction. There have been many times when I find myself soldering stuff on my kitchen table. If you don’t have a dedicated space, a couple things you will want to consider are: • Having good lighting, so you can see what you are up to • Access to a wall outlet for your soldering iron – you want the cord to have some maneuver room • A floor without shag carpet, as they tend to be repositories for small electronics parts (the smallest parts are always the first to fall) You can’t always have the best spot, but you can make the best of what you have available. Get Your Tools Together Good instruction manuals will let you know what tools you need for the job. Generally speaking, the essential tools are: • soldering iron • solder • wire cutters Some other tools that are not necessary but make life way easier are: • Needle nose: pliers for grabbing tiny parts • Helping hand: these help not only holding parts when soldering, but also provide the magnifying glass which is good for checking solder joints • Solder wick for undoing your mistakes • A pair of safety glasses is also a good idea. You might be thinking – ah, heck with safety glasses… It's easy to write them off when assembling boards. What I have done is get a pair that is comfortable and that I keep clean - this makes using them less a hassle. It’s a small precaution to take from getting a piece of tiny sharp metal in your eye. Inventory All the Parts For whatever reason, inventorying all the parts always seemed like a waste of time to me, but now it is something I make sure to do. Two big reasons I do this. Many of the boards I get are from Kickstarter campaigns, so the people manufacturing these might be kind of new at the gig, and with all the stuff they have going on, it's very possible they missed a part in the package. Another reason I like to do the inventory is so I know if I have extras. If I have pieces left over when I finish, then I am usually wondering if I did the assembly correct or not. If you do the inventory, then you can be confident that you assembled it right. I also separate the components into different jars, or bowls. This helps me quickly find components when I am assembling the shield and prevents the pieces from ending up lost in the carpet. Check Twice Solder Once I like solder wick as much as the next guy, but I would prefer not use it. It is really worth your time to double check part locations before you start soldering. I learned my lesson when I soldered a 24 pin connecter on the wrong side on a board. Now I always check a diagram or the directions at least twice before pulling out the solder. After I solder, I also make it a point to look over the solder joints. I am amazed at how much my soldering joints can stink, even when I feel like I had done a great job (this is when a helping hand or magnifying glass is good to have). Use an Arduino Board to Help Align the Pin Headers. One thing all Arduino Shields have in common are pin headers. These are the metal rows of pins that go on the bottom of the shield and plug into the Arduino stackable headers . If you don’t get the pin headers aligned correctly then your shield may not fit well, or may not fit at all on top of the Arduino. One trick to get the alignment right is to use an Arduino to hold the pin headers in the correct position when you solder them to the bottom of the shield. To do this, simply insert the headers how they would go into the Arduino, place the shield on top, and then do your soldering. It works like a charm. Troubleshooting the Assembly Now that your Arduino shield is fully assembled, it’s time to get that puppy running. Hopefully the shield came with some type of test sketch that you can load and it verifies that everything is up and running correctly. If not, try to find some code that you know works and load it onto the Arduino. If you start with code that you can verify works (or at least works for others), it can be easier to troubleshoot any issues you might encounter. I know how demoralizing it can be to load your first sketch and getting nothing better errors when you press the verify button. Here is a tidbit of moral support - there is a learning curve to everything - no matter how easy it is “supposed” to be. In fact, some of my favorite shields took me a while to understand how to use. So try not to get frustrated if your sketch isn’t working instantly. In the end, a little bit of determination goes a long way. Do you have any tips for building Arduino shields or electronics kits in general? I would love to hear about them in the comments.…
In this episode I talk about the video channel that I host on YouTube. If you have watched any previous episodes of this channel then you know I focus on Arduino related topics. The purpose of the channel is to help people learn about using Arduino. Specifically, the target audience is electronics hobbyists who are interested in learning to use Arduino. That being said, I try to make the videos from the perspective of a beginner so if you don't know jack about electronics or programming, then the show should still be a great place for you to learn.Every Tuesday I will be releasing a new episode. Every fourth video will be something like the video shown above. The reason I am doing this is because it gives me a little bit of a break in video production, which is extremely time consuming. I am calling these types of videos "Intermissions" which is all I could come up with. So this is the first intermission video (and post). A Little Bit About Myself: I am an electronics hobbyist - I've be messing around with hobby electronics for a about a decade, and I have been learning about Arduino for a big part of that time. I don't have any formal training in electronics so the perspective you get from me might be a lot like you, someone who has tried really hard to learn about electronics with as much spare time as I could find between work, family, and the curve balls of life. I do have some formal training in programming (though not much). I took a C++ course in college and used Matlab for some research I was doing at the university. What type of topics can you expect to watch on this video channel? Like I said before this channel is focused on Arduino - but there so many applications for Arduino it gives me a bunch of latitude for all types of stuff. There will be a ton of “how to” tutorials. Not about cutting and pasting the code – they’ll be about understanding how to make your own code. I'll talk about Arduino derivatives, shields and cool hardware and sensors you can use. I am really interested in science, so I plan to start doing some videos on using Arduino to enable Citizen Science. I might start with some data logging ideas. Student Projects: On a quick aside, what I do for a living is run an online course that uses a very structured curriculum to teach electronics hobbyists how to use Arduino. The Arduino Course is designed so you don’t need any electronics background to work through it, but I find most of my students do have some electronics experience to begin with. The reason I bring this up is because many of the students submit projects they are working on and I plan to use these “intermission” videos to show off some of the stuff they have done. For example, James (a really quick study) who took the course has been making all types of cool Laser tag accessories using Arduino . Which is pretty awesome - and very impressive. Projects I am Working on: I will also use these “intermission” videos to talk about some of the projects I am working on. Lately, I have been thinking about a little robot that can draw. I only really work on it when my kids are around, so the progress is painfully slow. What I would really like is to get the robot to draw sketches of people. No idea if I will ever make it to that point (or how the heck I am going to pull it off), but it's my pet project that I have been working on. So that’s it for this first intermission post (and video). I will see you in the next show, where we will be talking more things to consider when assembling Arduino Shields from kits. Until then! If you are interested in learning how to use Arduino, sign up for our free Arduino Crash Course below.…
If you have been learning about Arduino for any amount of time, than you have probably come across the term Breakout Board. Now, you might think, as I did when I first heard about breakout boards, that they were some fixture for practicing your Kung Fu fighting. In this lesson, we will discuss what breakout boards are, how they can accelerate your Arduino prototyping and some things to look out for when you buy them. Want to step-up your Arduino skills? Click here to join our 12-part HD Video Course. Basic Concept of a Breakout Board The basic concept of a breakout board is that is takes a single electrical component and makes it easy to use. Usually the electrical component is an integrated circuit (IC). Integrated circuits, as you may know, have pins on them. The pins on an IC can do a multitude of things, but you usually have pins for supply power, pins for providing a ground, pins for receiving an input and pins for sending an output. A breakout board "breaks out" these pins onto a printed circuit board that has its own pins that are spaced perfectly for a solderless breadboard, giving you easy access to use the integrated circuit. There are all type of breakout boards - but most of them are for different types of sensors, for example: accelerometers, ultrasonic distance sensors, RFID tag sensors, temperature sensors, pressure sensors, and they even have seismic breakout boards for sensing dinosaurs' footsteps! Breakout Board vs Arduino Shield: What's the difference? You might be wondering what the difference is between a breakout board and an Arduino shield, and that is a good question. Breakout boards usually have a smaller form factor - they don't need the entire space of an Arduino shield to accomplish their mission. And while the market for most breakout boards is being driven because of their use with Arduino , since the pin-out of a breakout board is not designed specific to the Arduino headers, it means you could use a breakout board with any other microcontroller development board you want - which gives them a bit more scope than Arduino shields. Also, since breakout boards generally have fewer components than a shield does, you may find the cost is lower than a comparable Arduino shield. As you may have guessed by now, you can find a breakout board that does essentially the same thing as a shield. You might be wondering, if breakout boards are only a few components, why not just buy the integrated circuit the breakout board uses, put it on a solderless breadboard yourself, and t hen hook them up to your Arduino ? That is great question, and there is nothing saying you can't – plenty of people do - especially since the components by themselves are often far cheaper to buy alone from an electronics distributor, like digikey or mouser. So, why the heck are people buying all these breakout boards? It essentially comes down to convenience. Let me list the ways a breakout board can help you out, and then you make the call: Breakout boards can save you space We have already said that breakout boards use integrated circuits. Integrated circuits are kind of like t-shirts - you can get them in all different sizes. Usually breakout boards utilize a tiny version of an integrated circuit called an SMD (surface mounted device). The pins on SMD parts are really small - not something you can easily pop into a breadboard. The larger form factor of an integrated circuit, called a DIP (dual inline package) has bigger pins, which fit easily into a breadboard. The DIP package of an IC will be bigger than the SMD form factor. The point, I am getting to here, is that Breakout boards can sometimes save you space which may or may not be important for your project. Breakout Boards are designed for reuse Another thing about using DIP packages is that while the pins are bigger, they are not necessarily sturdy. If you plan to use a DIP component over and over, the usable life of the pins is only so long - the pins on a breakout board however, are heavy duty and designed for reuse. The DIP version on a component may not be available One other issue you may find is that the DIP version of an integrated circuit is not available - as electronics get smaller over time, the demand for larger components is drying up and manufacturers are moving away from even bothering with the DIP package, which ultimately brings you back to a breakout board. Pin labeling on a Breakout board One great feature of breakout boards is that they usually have the pin names of the integrated circuit labeled on the PCB. This makes hooking up the breakout board to your Arduino a cinch, especially when there are a ton of pins. Otherwise, you are looking at the black box of an IC and referencing the datasheet of the integrated circuit to try to figure out which pin is for what. So now that you know some of the benefits of a breakout board, let's talk about a couple things you might want to consider when you are buying them. Good documentation I said this about Arduino Shields in the last lesson , but I will say it again - good documentation is like water in the desert. The more you can get your hands on, the better. Let's face it - a lot of this electronics and programming stuff is not self evident - you need good instructions and reference material to make it work right. The test I usually use before buying a breakout board is to see what reference material I can find online for it. If nothing tangible exists, you might be spending way more time trying to get it up and running than you would prefer. Breakout boards are not necessarily interchangeable As you search for particular breakout boards, you may find that there is a super cheap version available. If you plan on using pre-existing code for a breakout board that references the more expensive version of the breakout board – i.e. maybe in the sketch comments it says, "use XYZ breakout board", one thing you will want to check is that the breakout boards use the same integrated circuit. If they don't use the same integrated circuit, and you don't know how to adjust the code for these differences, then you may find that the cheap version will cost you more time in trying to figure out how to use it. Soldering and header pins may be required Many breakout boards are sold as kits. Usually, the only things you have to solder are the header pins that allow the breakout board PCB to plug into a breadboard - this is really easy to do. It may also be the case that a kit maker just sells the breakout board with the SMD components, and you have to buy the pin headers separately. So those are a few things to keep in mind when buying a breakout boards. Using the correct supply voltage Finally, once you actually have your breakout board, make sure that you know what voltage supply pin it needs hooked up to. The Arduino has two voltage out pins, one at 3.3 volts and one at 5 volts. Many breakout boards use a supply voltage around 3.3 volts. Sometimes the supply voltage will be printed right on the PCB by the associated pin, but other times it will just say Vcc, so you will want to check the specs on the breakout board. If you are just getting started with breakout boards, a great place to look is in the Arduino IDE examples. Some pre-written sketches get you up and running quick with some common breakout boards. If you like the style of this lesson, I welcome you to join the free Arduino Crash Course - you can sign up below.…
L
Learn Programming and Electronics with Arduino

If you are learning about Arduino, you have no doubt come across the term Arduino Shield . This tutorial will explain what Arduino Shields are, why they are awesome, and several things to consider when buying shields. cool electronics ideas that you have. Now the Arduino in and of itself is pretty amazing - you can do a lot of stuff with an Arduino alone. But when you want to start adding all types of cool technologies like bluetooth, wifi, RF, motor-drivers, etc. it can be pretty tricky; especially if you are new to electronics and programming. Arduino shields take all the complexity of the hardware and reduce it to a simple interface. This allows you to get your idea up and running fast. Now it's not just the hardware that shields take care of, in many cases, Arduino shields also have programming libraries associated with them. These libraries allow you to easily implement the hardware features available on the shield. There are shields for all types of things - LCD shields, LED matrix shields, wifi and bluetooth shields, motor shields, power supply shields, geiger counter shields, there are even shields for cooking hot dogs. Chances are if you need to do something, a shield exists to get you up and running quick. Shields plug right into the top of an Arduino. The black plastic rows of holes along the sides of an Arduino are called headers , and on the bottom of a shield, you have these long spiky pieces of metal, these are called pins . The pins on a shield line up with the header rows on an Arduino and fit snuggly (more on this later). Buying an Arduino Shield? Think about this stuff: Does it have good documentation? Documentation is the fancy way of saying - “will they show me how to use this thing?” Basically, is there some type of tutorial or user manual or forum that talks about how to use the shield. This is one of the biggest factors for me when it comes to buying an Arduino shield. For all the ease of use that a shield provides, if I don't know how to use it, it's about as a good as a rock. Lucky for us, people who use Arduino tend to be awesome and do a great job writing about how to use stuff, so even if the manufacturer doesn't have good instructions, if people actually use the shield, then you will find a wealth of information online. But if you do a web search and it doesn't turn up much of anything useful, you might consider looking for another option. Two US companies that provide superb documentation of the shields they make and sell are Adafruit Industries and Sparkfun . Soldering may be required Many shields are sold as kits, that means they are not fully assembled - and will require you to do some soldering. If you are buying from a reputable source, you should know this ahead of time, but it is worth double checking. Sometimes manufacturers will offer the shield as a kit or fully assembled - I often go for the fully assembled option just to save time. If you have not soldered before, shields are usually a cinch to solder, so don't be intimidated - go get a cheap soldering iron and some solder and go for it! Probably the most important thing when soldering a shield is making sure that the pins on the bottom of the shield are straight up and down, if they aren't they won't line up to the Arduino headers and be a major pain to connect. Stackable or Not Stackable Arduino Shields If you plan on stacking an Arduino shield with other shields, you will want to make sure it is stackable. If it doesn't have pin headers on the top of the shield, or they don't look aligned correctly (usually too narrowly spaced), than it is likely another shield cannot be stacked on top of it. You might also run into a problem if components on the shield stick up too high to allow shields above from getting a snug fit. Manufactures of shields are getting more savvy to this issue, but you should always check. Not all Arduino shields have the same pinout Some older Arduino shields may not have all the pins to fill the header rows of an Arduino . This is because older versions of Arduino didn't have as many pin header slots. This usually isn't too much trouble, unless you needed to use those pins that are not connected on the shield. If you have an older version of Arduino, then a shield you buy might have more pins than your Arduino has headers for - usually they are still physically compatible - this should not be anything to sweat about. Matching Hardware and Software Versions On a final note, if you are having trouble with a shield working, it worth checking to see if you are using the most current library version for your version of shield. A great example is the near ubiquitous Adafruit motor shield. There is a hardware version 1 and a hardware version 2. There are two separate code libraries for these. If you are trying to run your new version of the hardware on the old version of the library - then you will likely run into troubles. It worth checking to see you have the correct library for the job. I hope you found this tutorial helpful, please be sure to check out our free Arduino Crash Course (signup below) if you want to accelerate your learning.…
L
Learn Programming and Electronics with Arduino

1 How to Use and Understand the Arduino Reference 12:48
12:48
הפעל מאוחר יותר
הפעל מאוחר יותר
רשימות
לייק
אהבתי12:48
So you just opened up your fancy new gadget - maybe an awesome DSLR camera, or the newest gaming system, or maybe a new Blu-ray player. As you gladly tear away the packaging - you notice a small book that feels like it was printed on 4th generation recycled newspaper - it’s the instruction manual. As you skim the pages you realize it was first written in Japanese, translated to Chinese by an Australian ventriloquist and then an intern in California used Google Translate to finish the job for your native tongue. So you toss the instruction manual and just plug the gadget in. Good for you - especially since it appears as everything is working just fine. Until.. ...something isn’t working just fine. Maybe you can’t navigate the menu options to find a setting that was advertised on the box, or maybe the functionality you thought your gadget has does not appear to be working no matter how correctly it seems you are pressing the buttons. This tutorial is going to focus on the Arduino instruction manual, known more commonly as the “Arduino Reference” or the “Arduino Documentation”. It is an important and useful aspect of learning to use Arduino - it will be your best friend in times of bewilderment, brain lapses and fits of rage. I know that instruction manuals get a bad wrap - but don't fret - the Arduino Reference is awesome! To be honest what really keeps us away from the documentation is our fears. That’s right - the reference pages can be a bit intimidating when you are just starting out. They use a lot of technical jargon, are loaded with funky acronyms and filled with rabbit holes. Nobody uses the stuff anyway...right? ( Not right - that was a joke! ) This Tutorial Will Cover: What is the Arduino Reference? The Anatomy of an Arduino Reference Page. Why You Should Be Using the Arduino Reference More. How to use brain waves to trick your cat into eating less. Have you ever read a book and come upon a word you didn’t understand? Sometimes you can infer the meaning from it’s context, but what about when no such context exists? Likely, you used a search engine to find the definition. The definition told you what the word meant, whether is was a verb or adjective (or both), it gave some examples of how to use the word, and maybe even the etymology. The Arduino Reference is the same thing. It is the “dictionary” for all the structures, variables and functions that you can use when programming a sketch. It tells you the description, the parameters it uses, the syntax (how it is written), and even gives a bunch of examples on how to use it. So let’s jump into an Arduino Reference page and dig into what we can learn. The Anatomy of an Arduino Reference Page So let’s navigate to a reference page to start our journey. You can find the index of all the Arduino Reference pages on the Arduino Website: http://arduino.cc/en/Reference/HomePage Or - if you are offline - don’t worry, your Arduino IDE comes with an html copy of all the pages. You can get to it through the Arduino IDE: Help > Reference You will note at the top of the Reference Index page, there are three columns; Structure, Variables, Functions. This is the first level of organization in the reference. So if you are looking for a variable, you know which column to start looking in. Each of the hyperlinked items on this index page will take you to the individual entries reference page. What’s great about the individual reference pages is that they are organized in a similiar manner from one to the next, so you should know what to expect. They are also terse, so don’t think you are going to have to scour through someones dissertation. Each page has some major headings. We will walk through each of the main ones, and then talk about some less common ones. Description: All entries will have a description. Pretty straightforward - this is going to be a simple explanation of what the item does. It usually uses language that is basic. Syntax: Most all entries have a “syntax” heading, but they are more prevalent for functions. The syntax shows how the function (or other code) should be written when you use it in your sketch. Basically - it is what the function needs to know to do it’s job. Let's take an example from the digitalWrite() reference page. The words in the parentheses are telling you what type of value should be passed to the function. If we want to use this function than it will need to know 2 things - the pin number and the value to write to the pin. You don’t type in the word “pin” when you use the function, you would replace that with the actual pin number, or a variable that represents that pin number. Same is true for the word “value”, you would replace this with one of the acceptable parameters (see below). So when you actually wrote the function, it might look like this: digitalWrite( 13 , HIGH ) Where 13 is the “pin” and HIGH is the “value”. Parameters: Only structures and functions will have the “Parameters” heading. These describe exactly what can go in the parentheses in the syntax above. This is good to know, because you might be trying to pass a floating point number when the function calls for an integer. Returns: This tells you what value to expect a function to give you back. For example, when you use the square root function, you expect to get back the square root. But what data type will the square root be - an integer, a float or a double? The “Return” heading will tell you. Sometimes, a function will return nothing. Take the pinMode() function for example, you give it the pin number and the mode that you want the pin to be and it simply sets the mode - there is no data it needs to give you back. Example: This is your best bet at understanding how the structure, function or variable is intended to be implemented in code. It is usually a very short code snippet, though sometimes they can be lengthy. The example below is taken from the map() reference page. A nice feature of the example description is the “get code” option on the right of the reference page next to the example code. When you click this, it will take your browser to a plain text web page where you can copy and then paste the code into your Arduino IDE. See Also: This is a bulleted list of similar or related entries to the reference page you are looking at. They will link to other reference pages inside the reference directory. If I end on a reference page that isn’t quite what I was looking for, I will usually check out the options they provide here. Sometimes, they will also link to tutorials on the Arduino website (and who doesn’t like tutorials?) Keep in mind if you are using the reference in the offline mode through the Arduino IDE and you do not have an internet connection that any links outside the reference directory will not work. That includes the most common headings, what follow are some less common, but none-the-less useful headings you will run into. Programming Tips / Coding Tip / Tip: These are going to little bits of knowledge provided by people who know their stuff. I always like to read these, because they add to the depth of my understanding. Warning: These point out common errors that occur when people like me and you try to use the code. Caveat: If there is an exception to the rule, they will be described here. Note: In many cases, the notes are the “miscellaneous” heading, capturing information that doesn’t particularly fall under other headings. Why You Should Be Using the Arduino Reference More Here is a scenario I have played out myself about 7,000 times. I am writing a program and some function does not seem to be working right. I spend 30 minutes making changes to the program, but keep getting errors. Every time I think I have it fixed, I find I am wrong. Then I decide to check out the reference at which point I quickly realize I simply didn’t understand how a function was supposed to work. So the habit I have developed when I don’t completely understand a function it to check out the associated Arduino Reference page. It saves me times, teaches me something I didn’t know or re-teaches me something I forgot - and it will do the same for you. Let’s sum all this up. The Arduino Reference page is: The Bee’s Knee’s. The Lions Mouth. My favorite page on the Arduino website. Your favorite page on the Arduino website? Challenge(s): Go the Arduino Reference Index Page and start perusing some functions. See if you can find entries with the following headings: Caveat / Warning / Tip Further Reading: Warning - this gets deep! - AVR Libc (This is the reference for what the Arduino language is based on) - User Manual for the AVR Libc P.S. Ok - as much as I love the Arduino Reference page, sometimes it has errors. So if you find any, mention it on the Arduino Forum .…
L
Learn Programming and Electronics with Arduino

1 Using Red-Green-Blue (RGB) LEDs with Arduino (Common Cathode Type) 14:47
14:47
הפעל מאוחר יותר
הפעל מאוחר יותר
רשימות
לייק
אהבתי14:47
In this tutorial we describe using RGB LEDs of the Common Cathode Type. We will describe setting up the circuit, talk about the LED and discuss the code used to adjust the hue.
L
Learn Programming and Electronics with Arduino

1 Using Random Numbers with Arduino 13:02
13:02
הפעל מאוחר יותר
הפעל מאוחר יותר
רשימות
לייק
אהבתי13:02
This video tutorial talks about using the random() and randomSeed() functions with Arduino. It is pretty straight forward, but there are some intricacies worth noting. Creating truly random numbers in Arduino is harder than you might think. The closest we can get in Arduino, and just about anywhere else, is using pseudo random numbers. That is, numbers that mimic randomness, but in fact do have a pattern if Want to fast-track your Arduino skills? Click here to join our 12-part HD Video Course. Why are Random Numbers with Arduino All the Same? The most important thing to understand when using the random() function with Arduino is that it will generate the exact same list of pseudo random numbers every time. So if you build a slot machine, and the first crank of the handle is a winner, then you can be sure that if you reset the Arduino board and pull the handle again - it will still be a winner the first time. The easy way to overcome this is using the randomSeed() function. This function takes a value (an integer for example), and uses the number to alter the random list generated by the random() function. The number you pass to the randomSeed() function is called a 'seed'. You might put randomSeed() in the setup, and then use the random() function in the loop. Something like this: //this variable will hold a random number generated by the random() function long randomNumber; //Set up - this is where you get things "set-up". It will only run once void setup() { //setup serial communications through the USB Serial.begin(9600); //Let's make it more random randomSeed(42); }//close setup void loop() { //generate a random number randomNumber = random(2,5); //display the random number on the serial monitor Serial.print("The Random Number is = "); Serial.println(randomNumber); } But there is still an issue - even though the sequence of random numbers is different when using the randomSeed() function - it will still be the same every time the sketch is run. It is just a different list of pseudo random numbers! One Solution to the Random Problem So, what to do? Lucky for us the Arduino reference has a great solution. Use the analogRead() function to read a value from an unused analog pin. Since an unused pin that has no reference voltage attached to it is basically 'floating', it will return a "noise" value. This noise value can seed the randomSeed() function to produce differing sequences of random numbers every time the sketch is run. Below is the sketch from the video using analogRead() and randomSeed() in unison: /*How to use the random() and randomSeed() function YOU WILL NEED: (3) LEDs (3) 220OHM resistors (1) Jumper Wire (4) Hot cakes CIRCUIT: Connect a resitor to pin 2 and then to a breadboard. Connect the long leg of an LED to the resitor and the short leg to one of the ground rails on the breadboard Repeat this for the other components at pin 3 and 4 Coonect the ground on the breadboard to one of the Arduino GND pins. Created JUL 2014 by Michael James https://programmingelectronics.com/thearduinocourse */ //Declare and initialize LED pin variables int LED_1 = 2; int LED_2 = 3; int LED_3 = 4; //this variable will hold a random number generated by the random() function long randomNumber; //Set up - this is where you get things "set-up". It will only run once void setup() { //setup serial communications through the USB Serial.begin(9600); //Let's print a start messgae to the serial monitor when a new sequence of random numbers starts Serial.println("Starting new Random Number Sequence"); //set the LED pins as outputs pinMode(LED_1, OUTPUT); pinMode(LED_2, OUTPUT); pinMode(LED_3, OUTPUT); //Let's make it more random randomSeed(analogRead(A0)); }//close setup //The loop() runs over and over again void loop() { //generate a random number randomNumber = random(2,5); //display the random number on the serial monitor Serial.print("The Random Number is = "); Serial.println(randomNumber); Well, hopefully that was random enough for you! If you enjoy this tutorial, I highly recommend checking out our free Arduino Crash Course (You can sign up below).…
L
Learn Programming and Electronics with Arduino

Ever ever spent too much time searching for a 220 ohm resistor or just one more jumper wire? Are you sure you had that extra LED, LDR, [Fill in the blank], but have no idea where it went? Do you just want to throw up a quick circuit and get to coding? Travel a lot and want an easy way to learn Arduino on the road?…
L
Learn Programming and Electronics with Arduino

1 How to Make One Button Have the Functionality of Two or More with Arduino 15:40
15:40
הפעל מאוחר יותר
הפעל מאוחר יותר
רשימות
לייק
אהבתי15:40
Do you have an application where you want multiple buttons for different user inputs? Maybe you have a timer and you want one button for minutes and another for hours. But there is a problem – you only have room for one button! In this tutorial, we are going to use Arduino to explore how to make one button have the functionality of two or more. Click here to join our 12-part HD Video Course. You Will Need: (1) Momentary push button (5) Jumper wires (1) Solderless breadboard (2) LEDs (2) 220 Ohm resistors Set Up The Circuit: To demonstrate making one button have the functionality of two or more, we will set up a simple circuit with 2 LEDs and a button. Based on how we press the button, different LEDs will illuminate. Follow the instructions and schematic below to get the circuit set up before we dive into the mechanics of the Arduino code. Using a jumper wire, connect any GND pin from the Arduino, to the ground rail on your breadboard. Place an LED on your breadboard, make sure to note which way the long leg is facing. Using a jumper wire, connect pin 13 from your Arduino to the breadboard in the same channel where you have the long leg of the LED attached. Now connect one side of the 220 Ohm resistor to the short leg of the LED, and connect the other leg to the ground rail on the breadboard. The orientation of the resistor doesn’t matter. Repeat this using pin 12, and another LED and resistor. Finally, place your push button on the breadboard. Depending on the style of your pushbutton, they often fit well straddling the long trench that goes through the breadboard. Connect a jumper wire from one side of the button to pin 2 on the Arduino. Connect a jumper wire from the other side of the button to the ground rail on the breadboard. That's it for the circuit setup. Now, when you press the push button (which will electrically connect both sides of the button), pin 2 to will have ground voltage applied. We will use this ground voltage input to trigger our different functions. Examine the Sketch: There are couple ways to implement the multi-function button press using Arduino. One way is to have the number of presses determine the output. For example, a single click might highlight the “hour” field of an LCD timer and a double click might highlight the “minute” field of the display. Another way that we can implement multiple functions with one button is for the user to hold down the button for different lengths of time with the length of the hold determining the output. For example, if the user holds the button for half a second and releases, something happens. If she holds it for 2 seconds, something different happens. This latter method of using button hold length time to determine separate functions is the strategy we will learn here. Before I go any further though, I would like to thank Steve for creating the base Arduino code that we will be using. Steve is a member of the Premium Arduino course (a couple of months ago, he was new to Arduino). While creating a home automation project, he was in need of using a single button to do multiple things, and came up with a very simple way to make it happen. Thanks Steve! Here is the complete sketch, I recommend looking it over first, and then we will discuss it piece by piece below. /*Using a Single Button, create mutliple options based on how long the button is pressed The circuit: * LED attached from pin 13 to ground through a 220 ohm resistor * LED attached from pin 12 to ground through a 220 ohm resistor * one side of momentary pushbutton attached to pin 2 * other side of momentary pushbutton attached to Ground * Note 1: on most Arduinos there is already an LED on the board attached to pin 13. * Note 2: In this circuit, when the button is pressed, Ground Voltage is what will be applied. Created DEC 2014 by Scuba Steve Modified JAN 2015 by Michael James Both members of https://programmingelectronics.com This code is in the public domain */ /////////Declare and Initialize Variables//////////////////////////// //We need to track how long the momentary pushbutton is held in order to execute different commands //This value will be recorded in seconds float pressLength_milliSeconds = 0; // Define the *minimum* length of time, in milli-seconds, that the button must be pressed for a particular option to occur int optionOne_milliSeconds = 100; int optionTwo_milliSeconds = 2000; //The Pin your button is attached to int buttonPin = 2; //Pin your LEDs are attached to int ledPin_Option_1 = 13; int ledPin_Option_2 = 12; void setup(){ // Initialize the pushbutton pin as an input pullup // Keep in mind, when pin 2 has ground voltage applied, we know the button is being pressed pinMode(buttonPin, INPUT_PULLUP); //set the LEDs pins as outputs pinMode(ledPin_Option_1, OUTPUT); pinMode(ledPin_Option_2, OUTPUT); //Start serial communication - for debugging purposes only Serial.begin(9600); } // close setup void loop() { //Record *roughly* the tenths of seconds the button in being held down while (digitalRead(buttonPin) == LOW ){ delay(100); //if you want more resolution, lower this number pressLength_milliSeconds = pressLength_milliSeconds + 100; //display how long button is has been held Serial.print("ms = "); Serial.println(pressLength_milliSeconds); }//close while //Different if-else conditions are triggered based on the length of the button press //Start with the longest time option first //Option 2 - Execute the second option if the button is held for the correct amount of time if (pressLength_milliSeconds >= optionTwo_milliSeconds){ digitalWrite(ledPin_Option_2, HIGH); } //option 1 - Execute the first option if the button is held for the correct amount of time else if(pressLength_milliSeconds >= optionOne_milliSeconds){ digitalWrite(ledPin_Option_1, HIGH); }//close if options //every time through the loop, we need to reset the pressLength_Seconds counter pressLength_milliSeconds = 0; } // close void loop Comments: At the top of the sketch, we find the comments. You should make it a habit to read the comments in a sketch before jumping into the mechanics of the code. The comments should lay the groundwork for what is going to happen in the program and will help you interpret the intent of the code as you begin to analyze it. Declare and Initialize Variables: After the comments, we start initializing and declaring variables. Since, we are going to be tracking time, we need to have a variable to record the length of time a button is being held. We do that with the pressLength_milliSeconds variable: //We need to track how long the momentary pushbutton is held in order to execute different commands //This value will be recorded in seconds float pressLength_Seconds = 0; Now, you might think that the variable name is really long and annoying. And I wouldn’t particularly argue with you – I mean, why would I include milliSeconds in the name of the variable? The reason I do this is because I think including the unit of measurement in the variable name is helpful when other people are trying to read your code. Writing code that other people can read is not only good for other people, but also future versions of yourself who forget what the heck you were thinking when you wrote the code! [End Rant] The next thing we need to set up are the parameters for when options will get executed. In this example, I have two variables for two options: // Define the *minimum* length of time, in milli-seconds, that the button must be pressed for a particular option to occur int optionOne_milliSeconds = 100; int optionTwo_milliSeconds = 2000; Each option is defined by the number of milliseconds that the button must be held for that specific option to get executed. In order to get my first option to happen, I have to hold the button for at least 100 milliseconds which is pretty much a short tap on the button. If I want the second option to happen, then I have to hold the button for at least 2000 milliseconds aka 2 seconds. If you wanted more options, you would add more variables here with their corresponding hold times. Our final initializations will be to specify pin numbers for our button and LEDs. //The Pin your button is attached to int buttonPin = 2; //Pin your LEDs are attached to int ledPin_Option_1 = 13; int ledPin_Option_2 = 12; Setup() the Sketch: The setup() for this sketch is pretty straight forward (if it’s not straight forward to you, make sure to check out our free 12-part Arduino Course , after which this setup will be very familiar to you). We want to make sure that the pin our push button is connected to is set as an INPUT_PULLUP: // Initialize the pushbutton pin as an input pullup // Keep in mind, when pin 2 has ground voltage applied, we know the button is being pressed pinMode(buttonPin, INPUT_PULLUP); We do this to make sure that the button pin is not floating (if you are wondering what the heck that means, you can read more on that here – but if you just roll with me until we get through this tutorial, you should be fine ). We also want to specify the pins that our LEDs are attached to as OUTPUTs, because we will be applying voltages to these pins in order to illuminate them: //set the LEDs pins as outputs pinMode(ledPin_Option_1, OUTPUT); pinMode(ledPin_Option_2, OUTPUT); Finally, it never hurts to start serial communications for debugging purposes. //Start serial communication - for debugging purposes only Serial.begin(9600); With setup() complete, now we can jump into the main loop of our sketch… The Main Loop(): We know we are going to have to measure the length of time the button is pressed, and then record it. To do this, we use a while statement whose condition requires the button pin to be in a LOW state (remember, when we push the button, pin 2 will have a ground voltage applied). //Record *roughly* the tenths of seconds the button in being held down while (digitalRead(buttonPin) == LOW ){ Once the button is pressed and held, the while statement starts executing. The first thing we do in the while statement is to delay 100 milliseconds, and then record that into our time tracking variable: delay(100); //if you want more resolution, lower this number pressLength_milliSeconds = pressLength_milliSeconds + 100; Keep in mind the first time through the loop, pressLength_milliSeconds will be equal to 0, so we are just adding 100 to the variable. It can be handy to know how long the button has been pressed as you add options. To make this easy, we want to print the current value of the pressLength_milliSeconds variable to the serial monitor window: //display how long button is has been held Serial.print("ms = "); Serial.println(pressLength_milliSeconds); Let’s ignore the rest of the code for a second, and imagine what happens if we keep holding the button. The first time through the while loop, we add 100 milliseconds to the time tracking variable and we print that value to the serial port. The next time through loop, we add another 100 milliseconds to the timer counter variable, and print this new value to the serial monitor. As long as the button is being held down, then we keep adding time to the pressLength_milliSeconds variable – this is the crux of the program. When we release the button, the while statement stops, because the condition is no longer met, and we stop adding time to pressLength_milliSeconds. So let’s pretend we held the button for three seconds, and then let go - what happens? Well, as we discussed, the while statement ends and the next line of code we encounter is an if statement. //Option 2 - Execute the second option if the button is held for the correct amount of time if (pressLength_milliSeconds >= optionTwo_milliSeconds){ digitalWrite(ledPin_Option_2, HIGH); } The condition of the if statement requires that the time we held the button be longer than or equal to the time we set for option number two. If you recall, option number two was set to occur with at least 2 seconds of button press time. Since we held the button for three seconds, this if statement will get executed. And all we do is write HIGH voltage to our “option 2” LED, making it illuminate. What if we had only held the button for one second – then what would happen? If this were case, then the first if statement condition would not have been met, but a subsequent else-if statement only requires the button hold time be 100 milliseconds or more – so the second else-if statement would get executed, which turns on the “option 1” LED. //option 1 - Execute the first option if the button is held for the correct amount of time else if(pressLength_milliSeconds >= optionOne_milliSeconds){ digitalWrite(ledPin_Option_1, HIGH); }//close if options Basically, if we hold the button a long time, the second option gets executed. If we hold the button a short time, the first option gets executed. If we wanted to add more options, we add the longer hold options at the top, and the shorter hold options at the bottom. I wouldn’t try to squeeze too many options in a small span of time or it might drive the end user crazy trying figure out the timing. Nor would I try to add more than three options for a single button within a given context, or else you chance making your potential end user want to beat you up. To finish up the sketch, we reset our button press timing variable to zero. This ensures that next time the button is pressed and held, we will start from time zero again. Try On Your Own Challenge: Add another option, which turns off both LEDs. Try adding it before the first option (you will have to adjust the timing) and then after each option. How tight can you squeeze the option time together? Experiment and determine what is a good rule of thumb. Download: PDF of this Arduino Tutorial…
L
Learn Programming and Electronics with Arduino

1 Understanding HIGH and LOW Arduino Pin States 12:31
12:31
הפעל מאוחר יותר
הפעל מאוחר יותר
רשימות
לייק
אהבתי12:31
If you are just getting started with Arduino, you might be wondering what the heck all this HIGH and LOW stuff everyone is talking about really means. At first I just figured everyone using micro-controllers was just on some type of emotional roller-coaster, until I began to realize that HIGH and LOW are actually abstractions. But let us not talk in abstractions - let us talk in concrete numbers and get down to the bottom of what HIGH and LOW actually mean. This Tutorial Will Include: What the heck is a PIN state? What are the values for Arduino Pin States? Practical Application: What do we see in practice?…
L
Learn Programming and Electronics with Arduino

1 Floating Pins, Pull-Up Resistors and Arduino 10:29
10:29
הפעל מאוחר יותר
הפעל מאוחר יותר
רשימות
לייק
אהבתי10:29
Floating Pins on Arduino have always been a bit of mystery to me. It just never made much sense. I did this video more for my own sake - just to concrete it in my brain. I hope it can add some solidarity to your understanding as well...
L
Learn Programming and Electronics with Arduino

Let's not be duped by people trying to sell us authentic Arduino's that are counterfeit. This video will show you the one way to be sure you get the real deal, and five methods of telling if you bought a counterfeit or not.
L
Learn Programming and Electronics with Arduino

1 Throw out your breadboard! Dr. Duino: An Arduino Shield for debugging and developing Arduino projects 11:35
11:35
הפעל מאוחר יותר
הפעל מאוחר יותר
רשימות
לייק
אהבתי11:35
In the last couple of episodes we have talked about Arduino shields and breakout boards. In this video, we will review a specific Arduino shield that makes developing projects and debugging sketches on the Arduino extremely easy - it's called Dr. Duino.Arduino Shield for Arduino Shields The Dr. Duino is an Arduino Shield . As would expect, it fits snuggly on top of the Arduino headers and has pin headers of it's own, which can easily accept a shield on top. The first thing you notice about Dr. Duino is that it's built like a doughnut - it's got a giant hole in the middle! (FYI - It does not taste like said pastry…) There are a couple reasons for this form factor, but foremost is that even after you stack another shield on top of Dr. Duino, you still have easy physical access to all its resources. Dr. Duino Hardware Resources What resources are we talking about? Dr. Duino has 4 momentary pushbuttons, 5 LEDs, 6 potentiometers, an RS232 connector, and a bunch of access points for 5 volts, 3.3 volts and ground, oh yeah, and a siren (piezo buzzer). So how do you access these resources and why would you even care to? Both great questions! The core feature that allows us to use all the hardware I just talked about are groups of three “jumper” pins that surround the board. Almost every pin on the Arduino is associated with a set of these jumper pins. The middle pin is connected directly to the Arduino pin. The pin on the left is connected to the pin header on top of the Dr. Duino. The pin on the right is connected to the one of the hardware resources on the Dr. Duino board. With each set of these three jumper pins we get a plastic encased "jumper" - it fits snug on top 2 pins, and electrically connects them together. For every Arduino pin that has associated Dr. Duino jumper pins we have 2 decisions: 1) We can route the Arduino pin to the shield above by connecting the center pin to the jumper pin on the left. This passes the Arduino pin directly up to the shield if you have one attached, bypassing the Dr. Duino. 2) Or, we can route the Arduino pin to the resource on the Dr. Duino shield, bypassing the shield above. Each pin has a different "resource" or piece of hardware that you can use. Here is a quick mnemonic for remembering how to place the “jumper” on the “jumper pins” – Left goes Up (to the shield above), Right goes to Down (to the Dr. Duino). Digital pins 5, 6, 10, 11, and 13 have LEDs attached. Digital Pins 7, 8, 9 and 12 have momentary pushbuttons attached. Analog pins A0 - A5 have potentiometers attached and digital pin 3 is attached to the piezo buzzer. All these asset are extremely helpful. For example, let's say I am prototyping with a motor shield. What I want is for every time I press a button, then a servo moves 180 degrees. Instead of having to bust out a breadboard and jumper wires, I simply move a jumper on the Dr. Duino and I now have a preinstalled button. As long as the shield is not using that pin for anything, it's fair game to route that pin to the Dr. Duino. Or, maybe I want to turn a potentiometer to get the servo to move. Once again - scrap the breadboard - just move a jumper on one of the analog pins and you have a built in potentiometer - in fact, every analog pin has its own dedicated potentiometer! Trying to put 6 potentiometers on a breadboard and run jumpers is a major pain - having these built right in and so compact is great. Potentiometers are great for simulating sensor inputs too. Say you are developing a project that lights up LEDs based on inputs from a pressure sensor - but you don't have the sensor yet. No worries - just use the potentiometer built in to the Dr. Duino to simulate the input from the pressure sensor. Another great resource is the piezo buzzer. Most of us get used to using the serial window to debug our sketches. For example - we use the Serial .print() function to send a value to the serial monitor window when some threshold is met. What this ends up doing is dividing our visual attention from the Arduino to the computer monitor. With the piezo buzzer, you can get the same information, but be able to look at your Arduino - it allows you to incorporate more of your senses into the debugging process. All of these features add up to a great little development package - it's like a breadboard full of components all connected on a handy shield. So if I am traveling I don’t have to pack away a bunch of pieces-parts, I can just throw the Dr. Duino in with my Arduino and go for it. A Tool for Learning Arduino Code Another great use of these resources is when you are learning to use Arduino. If you are really trying to jump right into the code, then setting up the circuit can sometimes be a hassle, even if its just a button and an LED. (Yes - I am that lazy!) With Dr. Duino you can work through practically every sketch in the examples section of the Arduino IDE with only some minor code changes (mostly pin designations changes), without having to add a single piece of hardware. That’s a time saver (especially when it’s hard enough to carve out time to learn). Especially if having to place the components just feels like another barrier to practicing your Arduino coding. A Debugging Tool So far, most of my love for the Dr. Duino has come from this development aspect, but the Dr. Duino has actually been designed to help you debug your sketches when using shields. Microcontrollers (like the Arduino uses) are truly at the threshold of hardware and software. The more you know about both the physical and virtual, the better off you will be. Here in also lies a challenge – you can screw up both the hardware and the software. A big part of debugging your work is tracking down where the issue exists – is it the copper or code? (Or both !@#$) The Dr. Duino’s key feature of being able to direct an Arduino pin to or away from a shield you are using enables you to more quickly establish the starting point of debugging. Once you master how the rerouting works, the Dr. Duino will be a go-to shield for developing and debugging. With such a diverse set of applications it’s no wonder Arduino continues to grow wildly popular. Shields like the Dr. Duino make it that much more fun to use Arduino as a rapid prototyping tool. Special Bonus If you are interested in getting your hands on a Dr Duino, you can buy them directly from the Dr. Duino website . The creator of Dr. Duino (Guido Bonelli) has been kind enough to offer Open Source Hardware Group readers a free shipping code. Free Shipping Code: OSHWG_RULES (So true…)…
L
Learn Programming and Electronics with Arduino

1 Shorthand Arithmetic :: Using Compound Operators (+= , -= , *= , /= ) with Arduino 12:43
12:43
הפעל מאוחר יותר
הפעל מאוחר יותר
רשימות
לייק
אהבתי12:43
In this lesson we discuss some common shorthand for simple arithmetic in Arduino. We cover several compound operators that add, subtract, multiply and divide making it easy to increment variables in useful ways.
L
Learn Programming and Electronics with Arduino

1 Understanding Boolean Data Types and Using the Boolean NOT (!) operator to Switch Arduino Pin States 8:11
L
Learn Programming and Electronics with Arduino

1 What to do when you just don't know :: Arduino, ADXL345 triple axis accelerometer and an RGB LED 14:04
14:04
הפעל מאוחר יותר
הפעל מאוחר יותר
רשימות
לייק
אהבתי14:04
This lesson discusses what to do when you open an existing program and realize that you simply don't understand all the stuff that is going on. It also talks about using the ADXL345 triple axis accelerometer breakout board to control the hue of a Red-Green-Blue (RGB) LED.
L
Learn Programming and Electronics with Arduino

1 3 Ways to Use Acceleration in an Arduino Sketch 17:37
17:37
הפעל מאוחר יותר
הפעל מאוחר יותר
רשימות
לייק
אהבתי17:37
This lesson covers three easy ways to implement some form of acceleration in your Arduino sketches. It will cover the following: Linear Acceleration Exponential Acceleration Messing Around with the Square Root function What is Acceleration? Acceleration is the rate of change of something over time. Acceleration would help describe things like: Have fast can a stopped car get to 88mph? If I do a wing-suit jump from the top of Mount Everest, how fast will I be when I am gliding over base camp? How can I gently slow down the movement of a mechanical servo before it comes to rest? We can implement acceleration when programming Arduino quite easily with just a couple lines of code. The basic concept is that a variable will need to change - how it changes over the course of the sketch is what we are interested in. Below are three examples of how we can code change in variables so they display acceleration. Linear acceleration Linear acceleration is a constant rate of change. It can be represented by a sloped line on an x-y axis. A simple way to use it is to increment or decrement a variable every time through a loop like below... for (int i = 0; i < 10; i++) { //accel gets increasingly smaller as for loop continues accel = accel - 100; }//close for You can see in the code above, that each time through the 'for loop', the accel variable is decreasing by 100. If accel started at 1000, this is what accel would look like with respect to the number of iterations of the for loop. You can see that the accel variable decreases at a set rate over time in a linear fashion. Exponential Acceleration Exponential acceleration changes over time too, but it does so more dramatically (It's basically a drama queen). At first the rate of change in the variable is small, but once it begins to increase it really takes off! You can use the power function built into the Arduino IDE to make a variable change exponentially. The power function syntax is quite easy. pow( base, exponent ) The parameter base is the number that get raised to the power of the exponent . Like 2 to the 5th power. Below is an example of how you might code it to change a variable exponentially over the course of a 'for loop'. for (int i = 0; i < 10; i++) { //accel grows exponentially as the for loop continues accel = pow(2, i); }//close for Looking at a chart of accel over the course of the 'for loop', we can see that the way it changes is much different than linear acceleration: The theme for exponential growth is that is starts out slow, but once it starts going it really get's going! Using the Square Root Function for Acceleration The square root function can also provide some flavor to the output from your Arduino. It's syntax is simple: sqrt( x ) It returns the square root of the number or variable that you put in the parenthesis. Below is an easy way to use it in a 'for loop': for (int i = 0; i < 6; i++) { //accel quickly decreases through the loop accel = sqrt(accel); }//close for Let's look at how accel changes over the course of the for loop(let's say it started at 10,000): You can see the a rapid deceleration in the value of the accel variable of the 'for loop'. Practice With Acceleration: If you want to take a look at what these types of acceleration will do in "real" life, then set up the circuit below. You Will Need: (10) LEDs (10) 220 Ohm Resistors (1) Jumper Wire Arduino Board Bread Board Black Marker Set Up The Circuit: Start by by placing one resistor at pin 2 on your Arduino. Connect the other end of the resistor to the breadboard and then connect the long leg of the LED to the resistor. Place the short leg of the LED in the outer ground rail of the bread board. Then add 9 more resistors and LEDs across - you should stop at Pin 11 on the Arduino. Then add a jumper wire from GND on the Arduino to the shared ground on the breadboard. (All LEDs not pictured). That is pretty much it for the circuit. Below are the code examples for the different ways to program acceleration that we talked about: Here is the code for the linear acceleration: /* Linaer ( Constant ) Acceleration The circuit: * LEDs from pins 2 through 11 to ground created 2006 by David A. Mellis modified 30 Aug 2011 by Tom Igoe Modifeid 21 Jul 2014 by Michael James This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Array */ //Declare and initialize variables // The higher the number, the slower the timing. int timer = 1000; // an array of pin numbers to which LEDs are attached int ledPins[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; // the number of pins (i.e. the length of the array) int pinCount = 10; void setup() { // the array elements are numbered from 0 to (pinCount - 1). // use a for loop to initialize each pin as an output: for (int thisPin = 0; thisPin < pinCount; thisPin++) { pinMode(ledPins[thisPin], OUTPUT); } //Start Serial Communication Serial.begin(9600); }//close setup void loop() { // loop from the lowest pin to the highest: for (int thisPin = 0; thisPin < pinCount; thisPin++) { // turn the pin on: digitalWrite(ledPins[thisPin], HIGH); delay(timer); // turn the pin off: digitalWrite(ledPins[thisPin], LOW); //decrement timer (EASY WAY) timer = timer - 100; //let's take a look at the numbers via the serial monitor window (Tools > Serial Monitor) Serial.print("Back ... LED #"); Serial.print(thisPin); Serial.print(" = "); Serial.println(timer); }//close for //reset timer for next for loop timer = 1000; // loop from the highest pin to the lowest: for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { // turn the pin on: digitalWrite(ledPins[thisPin], HIGH); delay(timer); // turn the pin off: digitalWrite(ledPins[thisPin], LOW); //decrement timer timer = timer - 100; //let's take a look at the numbers via the serial monitor window (Tools > Serial Monitor) Serial.print("Forth ... LED #"); Serial.print(thisPin); Serial.print(" = "); Serial.println(timer); }//close for //reset timer for next for loop timer = 1000; }//close loop Here is the code for the exponential acceleration: /* Exponential Acceleration The circuit: * LEDs from pins 2 through 11 to ground created 2006 by David A. Mellis modified 30 Aug 2011 by Tom Igoe Modifeid 21 Jul 2014 by Michael James This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Array */ //Declare and initialize variables // The higher the number, the slower the timing. float timer = 1000; // an array of pin numbers to which LEDs are attached int ledPins[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; // the number of pins (i.e. the length of the array) int pinCount = 10; void setup() { // the array elements are numbered from 0 to (pinCount - 1). // use a for loop to initialize each pin as an output: for (int thisPin = 0; thisPin < pinCount; thisPin++) { pinMode(ledPins[thisPin], OUTPUT); } //Start Serial Communication Serial.begin(9600); }//close setup void loop() { // loop from the lowest pin to the highest: for (int thisPin = 0; thisPin < pinCount; thisPin++) { // turn the pin on: digitalWrite(ledPins[thisPin], HIGH); delay(timer); // turn the pin off: digitalWrite(ledPins[thisPin], LOW); //decrement timer timer = pow(2, thisPin); //let's take a look at the numbers via the serial monitor window (Tools > Serial Monitor) Serial.print("Back ... LED #"); Serial.print(thisPin); Serial.print(" = "); Serial.println(timer); }//close for //reset timer for next for loop // loop from the highest pin to the lowest: for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { // turn the pin on: digitalWrite(ledPins[thisPin], HIGH); delay(timer); // turn the pin off: digitalWrite(ledPins[thisPin], LOW); //decrement timer timer = pow(2, thisPin); //let's take a look at the numbers via the serial monitor window (Tools > Serial Monitor) Serial.print("Forth ... LED #"); Serial.print(thisPin); Serial.print(" = "); Serial.println(timer); }//close for //reset timer for next for loop timer = 1000; }//close loop Here is the code for messing around with the square root: /* square root The circuit: * LEDs from pins 2 through 11 to ground created 2006 by David A. Mellis modified 30 Aug 2011 by Tom Igoe Modifeid 21 Jul 2014 by Michael James This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Array */ //Declare and initialize variables // The higher the number, the slower the timing. float timer = 1000; // an array of pin numbers to which LEDs are attached int ledPins[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; // the number of pins (i.e. the length of the array) int pinCount = 10; void setup() { // the array elements are numbered from 0 to (pinCount - 1). // use a for loop to initialize each pin as an output: for (int thisPin = 0; thisPin < pinCount; thisPin++) { pinMode(ledPins[thisPin], OUTPUT); } //Start Serial Communication Serial.begin(9600); }//close setup void loop() { // loop from the lowest pin to the highest: for (int thisPin = 0; thisPin < pinCount; thisPin++) { // turn the pin on: digitalWrite(ledPins[thisPin], HIGH); delay(timer); // turn the pin off: digitalWrite(ledPins[thisPin], LOW); //decrement timer timer = sqrt(timer); //let's take a look at the numbers via the serial monitor window (Tools > Serial Monitor) Serial.print("Back ... LED #"); Serial.print(thisPin); Serial.print(" = "); Serial.println(timer); }//close for //reset timer for next for loop timer = 1000; // loop from the highest pin to the lowest: for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { // turn the pin on: digitalWrite(ledPins[thisPin], HIGH); delay(timer); // turn the pin off: digitalWrite(ledPins[thisPin], LOW); //decrement timer timer = sqrt(timer); //let's take a look at the numbers via the serial monitor window (Tools > Serial Monitor) Serial.print("Forth ... LED #"); Serial.print(thisPin); Serial.print(" = "); Serial.println(timer); }//close for //reset timer for next for loop timer = 1000; }//close loop I hope the lesson was helpful. The idea of adding acceleration to a sketch can seem a bit intimidating at first, but as you can see, it turns out to be a rather simple addition of code. Try on Your Own Challenge: Can you make the fade amount of an LED accelerate/deccelerate? Can you add a potentiometer to the circuit above and find a way to control the amount of acceleration - either linear, exponential or otherwise.…
ברוכים הבאים אל Player FM!
Player FM סורק את האינטרנט עבור פודקאסטים באיכות גבוהה בשבילכם כדי שתהנו מהם כרגע. זה יישום הפודקאסט הטוב ביותר והוא עובד על אנדרואיד, iPhone ואינטרנט. הירשמו לסנכרון מנויים במכשירים שונים.