Podcasts about jumper wires

  • 7PODCASTS
  • 10EPISODES
  • 31mAVG DURATION
  • ?INFREQUENT EPISODES
  • May 6, 2021LATEST

POPULARITY

20172018201920202021202220232024


Best podcasts about jumper wires

Latest podcast episodes about jumper wires

Adafruit Industries
New Products 5/6/2021 feat.Adafruit I2C QT Rotary Encoder with NeoPixel - STEMMA QT / Qwiic!

Adafruit Industries

Play Episode Listen Later May 6, 2021 7:08


Adafruit 2.13" Monochrome E-Ink Bonnet for Raspberry Pi - THINK INK (0:06) https://www.adafruit.com/product/4687?utm_source=youtube&utm_medium=videodescrip&utm_campaign=newproducts Premium Female/Male 'Extension' Jumper Wires - 10 x 12" (300mm) (0:39) https://www.adafruit.com/product/5018?utm_source=youtube&utm_medium=videodescrip&utm_campaign=newproducts NeoPixel Reverse Mount RGB LEDs - 10 Pack of SK6812-E (1:02) https://www.adafruit.com/product/4960?utm_source=youtube&utm_medium=videodescrip&utm_campaign=newproducts Simple Water Detection Sensor with Digital Output (2:29) https://www.adafruit.com/product/4965?utm_source=youtube&utm_medium=videodescrip&utm_campaign=newproducts Adafruit I2C QT Rotary Encoder with NeoPixel - STEMMA QT / Qwiic (3:55) https://www.adafruit.com/product/4991?utm_source=youtube&utm_medium=videodescrip&utm_campaign=newproducts ---------------------------------------- Visit the Adafruit shop online - http://www.adafruit.com LIVE CHAT IS HERE! http://adafru.it/discord Adafruit on Instagram: https://www.instagram.com/adafruit Subscribe to Adafruit on YouTube: http://adafru.it/subscribe New tutorials on the Adafruit Learning System: http://learn.adafruit.com/ -----------------------------------------

pack extension rotary new products adafruit encoder stemma neopixel adafruit learning system jumper wires
New Products
New Products 5/6/2021 feat.Adafruit I2C QT Rotary Encoder with NeoPixel - STEMMA QT / Qwiic!

New Products

Play Episode Listen Later May 6, 2021 7:08


Adafruit 2.13" Monochrome E-Ink Bonnet for Raspberry Pi - THINK INK (0:06) https://www.adafruit.com/product/4687?utm_source=youtube&utm_medium=videodescrip&utm_campaign=newproducts Premium Female/Male 'Extension' Jumper Wires - 10 x 12" (300mm) (0:39) https://www.adafruit.com/product/5018?utm_source=youtube&utm_medium=videodescrip&utm_campaign=newproducts NeoPixel Reverse Mount RGB LEDs - 10 Pack of SK6812-E (1:02) https://www.adafruit.com/product/4960?utm_source=youtube&utm_medium=videodescrip&utm_campaign=newproducts Simple Water Detection Sensor with Digital Output (2:29) https://www.adafruit.com/product/4965?utm_source=youtube&utm_medium=videodescrip&utm_campaign=newproducts Adafruit I2C QT Rotary Encoder with NeoPixel - STEMMA QT / Qwiic (3:55) https://www.adafruit.com/product/4991?utm_source=youtube&utm_medium=videodescrip&utm_campaign=newproducts ---------------------------------------- Visit the Adafruit shop online - http://www.adafruit.com LIVE CHAT IS HERE! http://adafru.it/discord Adafruit on Instagram: https://www.instagram.com/adafruit Subscribe to Adafruit on YouTube: http://adafru.it/subscribe New tutorials on the Adafruit Learning System: http://learn.adafruit.com/ -----------------------------------------

pack extension rotary new products adafruit encoder stemma neopixel adafruit learning system jumper wires
Learn Programming and Electronics with Arduino

Discussion: In this video, I’ll explain what parts you'll need to complete this Arduino Crash Course. Immediately below this discussion section, there is a summary checklist of links for these parts. You're welcome to check it out! The links take you to Jameco, a United States based electronics supplier. I'm actually one of their affiliates. So, if you decide to click any of those links below, you’ll be helping to make me a multi-millionaire and continue to buy fuel for my yacht. So that would be awesome. All joking aside, you might already have a lot of this stuff laying around. It just depends on how much you've been into electronics thus far. The first thing you'll need is an Arduino UNO. As you may or may not know, Arduino has all types of derivatives out there. An Arduino UNO There is a company named Arduino that made the board. That is the official Arduino, but Arduino is open-source hardware. In other words, the Arduino company made the board’s schematics and everything publicly available. Therefore, anybody can take access that information and replicate the board. Anyone can duplicate it, modify it, and even legally sell it. That’s why there are so many derivatives, or clones, out there of an Arduino UNO board. They are basically the exact same thing as your official Arduino UNO. Sometimes you’ll find that maybe one or two customizations have been made. My recommendation to you is to get an authentic, official Arduino UNO from the Arduino company while working through this course. The reason is because that prevents any discrepancies and concerns about hardware when following the tutorials. If you're following everything in the lesson, and something is amiss, then you can at least know it's not the hardware. You’ll know that you have the same hardware with which I’m working. Again... that’s just my recommendation. Now, if you already have an Arduino clone or derivative, feel free to use it. It will probably work just fine. The next thing you'll need is a USB cable to plug your Arduino into your computer. Basic procedure is to write code on the computer and then transfer that code, uploading it to the Arduino board. An AB USB cord The USB we’ll be using in this course is an A-B type. One end looks like your typical USB that just plugs into a computer, and the other end is almost square - or maybe more like a little house, depending on your imagination. This other end is what would typically go into the back of a printer. You will also need light-emitting diodes, or LEDs. An LED It’s best to get at least 10 of the five millimeter type. Any color of mix of colors is fine. I usually use red or white. Next on the list are resistors. Resistors Resistors, as the name suggests, resist the flow of current in a circuit. The bigger the number of the resistor, the more current they resist. When it resists current, the resistor takes that electrical energy and transforms it into heat energy. Therefore, it’s important to note resistors can get hot. Just file that away as a quick mental note for later down the line when we begin setting up circuits. You may not notice it that much for the lower level things we will be doing. However, I wanted to make you aware just in case. This is the list of required resistors: ten 220 Ohm resistors and two 10,000 Ohm resistors (also referred to as 10 K resistors). You’ll also need a potentiometer. Potentiometers It really doesn't matter what size you get. I’ll be using a 10 K potentiometer for this course. If you have one around, you can just use that. A potentiometer is similar to a resistor, but it's resistance can vary. That allows you to create something called a voltage divider. We won't get into that now. Just know that you need a potentiometer of any size. Next, you'll use a solderless breadboard. No, we won’t be cutting bread - although food does sound really good right now…. But I digress, a solderless breadboard is a circuit board where you can connect electrical components together without having to solder them. It has a bunch of little holes in it, and in the holes are all these little copper clips. A solderless breadboard The holes are aligned in a bunch of rows and columns. The columns are electrically connected, but the rows are not. So, you stick the leads of your electrical components, such as an LED, into the holes for the metal clips. This will complete the circuit, connecting the electronics. This is an example of how you'll use the breadboard. Don’t worry, it’s a lot easier than it sounds. For prototyping, like we'll be doing, it's a great tool since it permits quick and easy setup and changes to your circuit. The next required items are jumper wires. Jumper wires These fit down into the little holes on a breadboard and into the little holes on the Arduino board. (We'll be talking about the Arduino board more later, but those are called the headers.) Anyway, the jumper wires allow you to extend your electrical connections, giving you some extra space with which to work. You'll need 12. Two momentary push-buttons are also on the course list. A push button This button is normally off. That means if you're not pressing the button, no electrical connection is made between either side of the button. The button is off until you push it. When you’re holding the button down, though, an electrical connection is made. Once you remove your finger, the button pops back out again, breaking the electrical connection. They come in all different styles. However, if you follow the links below, you'll get an idea for what to look. Finally, you'll need some alligator clips. Alligator clips These help you connect leads together if, for some reason, we need to connect them in a way a little different than using the holes on the solderless breadboard. It may seems like quite a bit of equipment, but it’s really not that bad. I kept convenience in mind when creating this list. All of these items are relatively cheap. There are a couple of other things you'll need, though. I assume that you already have a computer running Windows, Mac, some type of Mac software, or Linux. Of course, an internet connection is also required because you'll have to download the Arduino software. I’ll explain the Arduino software in a later lesson. There are few things that are optional. These are not covered in this crash course, but they would be fun to have in order to experiment with your code. This is the optional equipment. You could get a photoresistor, a temperature sensor, maybe some additional potentiometers, and an RGB LED. RGB means red, green, blue LED. It's kind of an all in one, and they are pretty neat use. I believe that's it for the required and optional equipment. Again, the parts list is below. I’m looking forward to jumping into the course with you. See you in the next video! Hardware List for the Arduino Crash Course Below is the list of items you will need to get you through the course. The quantities of each provide a little leeway in case your cat eats an LED or you loose a resistor in your shag carpet. I have made every effort to keep this list minimal to provide the lowest cost to entry. NOTE: The links below take you to Jameco, of whom I am an affiliate. The cost to you is the same, but I get a small commission for purchases that helps me keep the site running and allows me to buy giant yachts. I use Jameco for a bunch of stuff - I like and trust them. I also use Digikey, Mouser, Adafruit, Makershed and Sparkfun. Required: Arduino Compatible Board USB Cable to plug in Arduino (A/B type - one end is typical USB, the other is what would go into a printer) LEDs AKA Light Emitting Diodes (10) 10K potentiometer (1) 220 Ohm Resistor (10) 10K Ohm Resistor (2) Jumper Wires (12) Solderless Breadboard (1) Pushbutton (2) Alligator Clips (3) Another option is to buy our Kit-on-a-Shield for Arduino:   Click here to learn more.   You'll need this stuff too: Now there are certain things I am assuming you have access to that you will also need, these include the below items. A computer running Windows, Mac OS, or Linux An internet connection to download the Arduino Software Optional stuff: While the list above will meet all your needs, sometimes having a little extra stuff to play with makes for a more fun and diverse learning experience. Below are items you can easily experiment with alongside this course: Photo Resistor Additional potentiometers RGB LEDs - red, green and blue all in one LED matrix Temperature sensors Arduino Kit just for this course from Jameco: I have had the pleasure of working with Jameco to create a kit that provides all the needed items for the Arduino Crash Course. You can check it out here.

Learn Programming and Electronics with Arduino

If Statement (and else-if), Comparison Operators and Conditions In the last lesson, we learned about the if statement. The if statement was the perfect choice for setting up instructions to run only when certain conditions were met. “If 30 seconds has passed – stop the heating element” or “If the sensor perceives a wall – turn 180 Degrees”. This lesson will expand on this amazingly useful function and show you how to stack different conditions to satisfy the flexibility you want in your designs. If you like this tutorial, click here to check out FREE Video Arduino course – thousands of people have really enjoyed it. You Will Need Potentiometer (doesn’t matter what resistance range) 220 Ohm Resistor LED (any color) Jumper Wires (3) Alligator Clip Dull machete with wood handle Step-by-Step Instructions Place the potentiometer in the breadboard. Place a jumper wire from one of the outside leads of the potentiometer to the 5V pin on Arduino. Place a jumper wire from the other outside lead of the potentiometer to one of the GND pins. Place the final jumper wire from the center pin of the potentiometer to the A0 pin. Connect either side of the 220 ohm resistor to pin 13. Connect the short leg of the LED to GND (the GND pin next to pin 13 is the most convenient). Attach the other leg of the resistor to the long leg of the LED. Plug your Arduino into your computer with the USB cable. Open the Arduino IDE. Open the sketch for this section. Click the Verify button (top left). The button will turn orange and then blue once finished. Click the Upload button. The button will turn orange and then blue when finished. Open up the Serial Monitor window. Tools > Serial Monitor. Adjust the potentiometer and watch as the LED turns on and off based on the knob position. If Then Statement Conditionals Set up This image built with Fritzing. /* Conditionals - If statement This example demonstrates the use of if() statements. It reads the state of a potentiometer (an analog input) and turns on an LED only if the potentiometer goes above a certain threshold level. It prints the analog value regardless of the level. The circuit: * potentiometer connected to analog pin 0. Center pin of the potentiometer goes to the analog pin. side pins of the potentiometer go to +5V and ground * LED connected from digital pin 13 to ground * Note: On most Arduino boards, there is already an LED on the board connected to pin 13, so you don't need any extra components for this example. created 17 Jan 2009 modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. http://www.arduino.cc/en/Tutorial/IfStatement */ // These constants won't change: const int analogPin = A0; // pin that the sensor is attached to const int ledPin = 13; // pin that the LED is attached to const int threshold = 400; // an arbitrary threshold level that's in the range of the analog input void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize serial communications: Serial.begin(9600); } void loop() { // read the value of the potentiometer: int analogValue = analogRead(analogPin); // if the analog value is high enough, turn on the LED: if (analogValue > threshold) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } // print the analog value: Serial.println(analogValue); delay(1); // delay in between reads for stability } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 /* Conditionals - If statement This example demonstrates the use of if() statements. It reads the state of a potentiometer (an analog input) and turns on an LED only if the potentiometer goes above a certain threshold level. It prints the analog value regardless of the level. The circuit: * potentiometer connected to analog pin 0. Center pin of the potentiometer goes to the analog pin. side pins of the potentiometer go to +5V and ground * LED connected from digital pin 13 to ground * Note: On most Arduino boards, there is already an LED on the board connected to pin 13, so you don't need any extra components for this example. created 17 Jan 2009 modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. http://www.arduino.cc/en/Tutorial/IfStatement */ // These constants won't change: const int analogPin = A0; // pin that the sensor is attached to const int ledPin = 13; // pin that the LED is attached to const int threshold = 400; // an arbitrary threshold level that's in the range of the analog input void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize serial communications: Serial.begin(9600); } void loop() { // read the value of the potentiometer: int analogValue = analogRead(analogPin); // if the analog value is high enough, turn on the LED: if (analogValue > threshold) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } // print the analog value: Serial.println(analogValue); delay(1); // delay in between reads for stability } Discuss the Sketch In this sketch we measure voltage at an analog pin from 0 to 1023 – this voltage changes based on where the knob of the potentiometer is set. We then define a threshold value somewhere in this range, let’s pick the number 400. When the value measured at the analog pin is above 400, we turn on the LED at pin 13, when the voltage is below 400 we turn the LED off. It’s as easy as that. Make sure you read the sketch and try to figure out what is taking place before moving on. This program might look long to you – the previous ones were a bit shorter. A good way to approach any program long or short is to cut it up into chunks and only consider pieces of it at a time. The first chunk in this sketch is the multi-line comments that clearly describe: What the program will do Generally how the program will accomplish it How to set up the circuit and the components you will need Any pertinent notes The license the program is released under (if any) The author, date and version number This might seem like a lot of stuff – but I would recommend you do the same thing for your programs! This information will not only help you understand what the heck you intended when you wrote the program but if you make the program available for others then your comments will help them as well. Some of the functions that are now integrated into the Arduino IDE were created by people just like you – they had a problem, they found a solution with some well-written code, they made it available to all the Arduino users in the world – and everybody else found it useful – and before you know it your code is famous and you win the Nobel peace prize. Enough of this tirade, let’s move onto the first block of code that will be executed by the Arduino. const int analogPin = A0; // pin that the sensor is attached to const int ledPin = 13; // pin that the LED is attached to const int threshold = 400; // an arbitrary threshold level that’s in the range of the analog input 1 2 3 4 5 const int analogPin = A0; // pin that the sensor is attached to const int ledPin = 13; // pin that the LED is attached to const int threshold = 400; // an arbitrary threshold level that’s in the range of the analog input Notice that all the variables have const in front of them. This keyword stands for constant. A constant is classified as a qualifier – it adjusts the behavior of the variable being declared. It is similar an adjective in a sentence – “The squishy material,” squishy qualifies what the material will behave. It might seem counterintuitive to the whole point of variables, but the constant qualifier will stop the variable from changing throughout your program. It protects the value from start to finish. Why do this? It protects you from unintentionally writing a new value to the variable. It happens more often than you might think – I recommend using constants when the variable will not change in the program. The integer constants we declare are pretty straightforward. The variables analogPin and ledPin are those pins the potentiometer and LED will be attached to on the Arduino board. Threshold is the arbitrary number chosen as the condition to turn our LED on or off. The next block of code is setup(). Here, we have to set the mode of a pin and set up serial communications. void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize serial communications: Serial.begin(9600); } 1 2 3 4 5 6 7 8 9 10 11 void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize serial communications: Serial.begin(9600); } Recall that all pins are by default set to INPUT, so we do not have to explicitly set the pin mode for our analogPin A0 as an INPUT – though I would argue it is best to do so for clarity. You should have serial communication down pat. We use the begin() function from the Serial library with a baud rate of 9600. Now that we have things setup, let’s get into the loop(). The first line of code we encounter reads from the value at the analog pin A0 and assigns this value to an integer variable called analogValue. int analogValue = analogRead(analogPin); 1 int analogValue = analogRead(analogPin); To do this, we use the analogRead() function. Recall that analogRead() will return a value between 0 and 1023. This value will change as we adjust the potentiometer. This line of code is checking the position of the potentiometer every time through the loop(). The next thing we want to do is compare the value we just read from the analog pin to our threshold value. The if-else statement is perfect for this. if (analogValue > threshold) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } 1 2 3 4 5 6 7 8 9 if (analogValue > threshold) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } You have seen the if statement before, now we add an else statement. The if statement checks a condition in the parenthesis, if it is TRUE, then the code in the curly brackets is executed – if the condition is not met (FALSE), then it moves to the else statement. Consider this pseudocode: if(apple is NOT rotten) { } else { } 1 2 3 4 5 if(apple is NOT rotten) { } else { } You can see that the else statement gives you control over what to do when the condition in the if statement is not met. In a later lesson we will talk about the else-if statement which will offer even further control over conditions. Explanation of iF-Then Statements In this example the condition we are interested in is: In this example the condition we are interested in is thus… analogValue > threshold 1 analogValue > threshold If this is TRUE we turn the LED on by using the digitalWrite() function: if (analogValue > threshold) { digitalWrite(ledPin, HIGH); } 1 2 3 4 5 if (analogValue > threshold) { digitalWrite(ledPin, HIGH); } If this condition is FALSE we turn off the LED by executing the code inside the curly brackets of the else statement: else { digitalWrite(ledPin, LOW); } 1 2 3 4 5 else { digitalWrite(ledPin, LOW); } Before we continue discussing the sketch, let’s do a quick overview of Comparison Operators. The condition set in an if-else statement will use what are called comparison operators. The list of comparison operators on the Arduino Reference page is as follows: == (equal to) != (not equal to) < (less than) > (greater than) = (greater than or equal to) These operators offer a broad spectrum of comparisons to use. It’s vital to pay close attention to the syntax of the comparison operators. Accidentally dropping an equal sign, or typing a > instead of a < is easy to do, and usually leaves you scratching your head when the program acts differently than you might have expected. Now that we have turned the LED on or off depending on the position of the potentiometer, let’s see exactly what values are being read. We want to do this to ensure the program is doing what we think it should and also to make sure our potentiometer (sensor) is working properly. // print the analog value: Serial.println(analogValue); 1 2 3 // print the analog value: Serial.println(analogValue); This line of code uses the println() function from the Serial library – which (as you know by now) sends the values from the Arduino to your computer. Adjust your potentiometer and watch the values change in the Serial Monitor window. Then adjust the potentiometer so the value is right at the 400 threshold and make sure the LED is responding appropriately. Finally, we want to slow down the readings to add some stability. We do this with the delay() function. delay(1); // delay in between reads for stability 1 delay(1); // delay in between reads for stability Let’s recap. First we read the value at the analog pin and assign that value to a variable. Next we check if that variable is more than or less than our threshold value. If it is above the threshold the LED turns on, if it is below the threshold the LED turns off. We also want to see the actual values at the analog pin, so we print them to the serial monitor. Finally, we wait a millisecond before our next reading – which starts the loop() at the top. You can see how handy the if-else statement can be. As I have said previously, the if-else statement is a staple of programming – you will see it (or a similar form of it), in any programming language you encounter henceforth. Try On Your Own Challenges Adjust the value of the threshold variable. Write an additional if statement to turn on the LED when the analogValue variable is less than 100. The LED should turn on when analogValue is greater than 400 and less than 100. Further Reading If-Else Statement – From the Arduino Reference More on the If-Else statement – The example sketch on the Arduino Website

Learn Programming and Electronics with Arduino
How to read voltages with analogRead()

Learn Programming and Electronics with Arduino

Play Episode Listen Later Mar 12, 2017 14:44


In the last lesson you learned about using the analogRead() function to collect data from a sensor connected to one of the Arduino analog pins. The range of data we received from the analogRead() function was mapped between 0 to 1023. What if we want to know the actual voltage being applied at the pin? If you like this tutorial, click here to check out FREE Video Arduino course – thousands of people have really enjoyed it. You Will Need Potentiometer (any resistance range will work) Jumper Wires – at least 3 Persian Rug Step-by-Step Instructions Place the potentiometer into your breadboard. Run a jumper wire from the 5-Volt pin of the Arduino to either one of the outside pins of the potentiometer. Run another jumper wire from one of the ground pins on the Arduino (labeled GND) to the other outside pin of the potentiometer. Run the final jumper wire from pin A0 on the Arduino to the middle pin of the potentiometer. Plug the Arduino into your computer. Open up the Arduino IDE. Open the sketch for this section. Click the Verify button on the top left side of the screen. It will turn orange and then back to blue once it has finished. Click the Upload button (next to the Verify button). It will turn orange and then back to blue once it has finished. On the menu bar, go to Tools > Serial Monitor – this will open the Serial Monitor window – you should see numbers rolling down this screen. Now adjust the knob of your potentiometer and watch the serial monitor window, the numbers should adjust between 0 and 5. Adruino Board Set up For Switch Case This image crafted with Fritzing. The Arduino Code /* ReadAnalogVoltage Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor. Graphical representation is available using serial plotter (Tools > Serial Plotter menu) Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. This example code is in the public domain. */ // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): float voltage = sensorValue * (5.0 / 1023.0); // print out the value you read: Serial.println(voltage); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 /* ReadAnalogVoltage Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor. Graphical representation is available using serial plotter (Tools > Serial Plotter menu) Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. This example code is in the public domain. */ // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): float voltage = sensorValue * (5.0 / 1023.0); // print out the value you read: Serial.println(voltage); } Discuss the Sketch This sketch does the exact same thing as the last lesson sketch except for one important change. It takes the reading provided by the analogRead() function and converts it into the actual voltage value at the respective analog pin. Let’s start from the top to review what is taking place. We have no variables to declare and initialize at the beginning of the sketch so we jump right into the setup() function. Inside the curly braces of setup() we begin serial communications by setting the baud rate. This is done using the function Serial.begin(9600). void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } 1 2 3 4 5 6 7 void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } That is all there is to the setup() of this sketch. The next block of code is loop(). Inside the curly braces of loop() the first thing we do is read the value at analog pin A0 and assign it to an integer variable called sensorValue. int sensorValue = analogRead(A0); 1 int sensorValue = analogRead(A0); Once we have recorded this value, we want to convert it to an actual voltage. You will recall that the range returned by the analogRead() function is between 0 and 1023. We want this to reflect the actual voltage at the pin – which is between 0 and 5 volts depending on where the potentiometer knob is turned. So let’s take a look at how we might accomplish this… Explanation of analog sensor code float voltage = sensorValue * (5.0 / 1023.0); 1 float voltage = sensorValue * (5.0 / 1023.0); The first thing we encounter is a new data type – called float. A float is simply a number with a decimal point; say for example 3.14 or 2.17781778. Floats, also called floating point numbers, can be huge in value, and take much more time for the Arduino to churn through than integers – this is why they are used only when necessary. We want the voltage variable set as a float data type because it will provide more resolution than an integer. The voltage variable is set equal to a somewhat confusing calculation. Our goal is to take the value that analogRead() returns and convert it into an actual voltage value. We use a conversion factor to accomplish this feat. By multiplying sensorValue by (5.0/1023.0), it scales down the range from 0-1023 (which is the range that analogRead() returns) to the range 0-5 which is the actual range of the voltage. You can think of the conversion calculation by saying “sensorValue is to X volts as 5 volts is to 1023”, where X is the converted voltage value we are trying to determine. Once we have this new value, it is assigned to the variable voltage – all of this on one line of code. Let’s recap the program… Read the sensor value at an analog pin. Assign this value to a variable. Convert this value to a voltage Save the voltage measurement to another variable And then… Well, we print it back to the serial monitor window so we can see what the voltage is at our pin. The loop() will start over again, it will sample a new value at the pin, it will convert that value and print it, and loop and loop and loop – you get the idea. Try On Your Own Switch from using the 5-volt pin on the Arduino to the 3.3-volt pin. Make sure to adjust the conversion factor. Instead of converting to a voltage value, can you change the conversion factor to return a range from 0 to 100? Further Reading float map() – this function takes the work out of conversion factors – can you implement it here?

Learn Programming and Electronics with Arduino
analogRead() and the Serial Port

Learn Programming and Electronics with Arduino

Play Episode Listen Later Mar 11, 2017 12:02


Knowing if something is on or off can be extremely useful, but often you will want to know more. How bright is the light? How fast is the satellite moving? These types of answers are often analog – they cover a large range of values, not just on or off. The Arduino handles analog inputs with 6 dedicated pins, labeled A0 through A5. These pins have access to an analog-to-digital converter, which takes the range of input values and creates a digital version by cutting up the range into tiny pieces. All this is handled behind the scenes – all you have to do is use some very simple functions and you will get what you need. You Will Need Potentiometer (any resistance range will work) Jumper Wires – at least 3 Bicycle tire Step-by-Step Instructions Place the potentiometer into your breadboard. Run a jumper wire from the 5-Volt pin of the Arduino to either one of the outside pins of your potentiometer. Run another jumper wire from one of the ground pins on your Arduino (labeled GND) to the other outside pin of the potentiometer. Run the final jumper wire from pin A0 on your Arduino to the middle pin of the potentiometer. Plug the Arduino into your computer. Open up the Arduino IDE. Open the sketch for this section. Click the Verify button on the top left side of the screen. It will turn orange and then back to blue once it has finished. Click the Upload button (next to the Verify button). It will turn orange and then back to blue once it has finished. On the menu bar, go to Tools > Serial Monitor – this will open the Serial Monitor window – you should see numbers rolling down this screen. Now adjust the knob of the potentiometer and watch the serial monitor window. The numbers should adjust between 0 and 1023. Using the Arduino analogread and map function with a potentiometer at pin A0 This image composed with Fritzing. The Arduino Code /* AnalogReadSerial Reads an analog input on pin 0, prints the result to the serial monitor. Graphical representation is available using serial plotter (Tools > Serial Plotter menu) Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. This example code is in the public domain. */ // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); // print out the value you read: Serial.println(sensorValue); delay(1); // delay in between reads for stability } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 /* AnalogReadSerial Reads an analog input on pin 0, prints the result to the serial monitor. Graphical representation is available using serial plotter (Tools > Serial Plotter menu) Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. This example code is in the public domain. */ // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); // print out the value you read: Serial.println(sensorValue); delay(1); // delay in between reads for stability } Discuss the Sketch This sketch starts with a multi-line comment describing the sketch and the circuit. You will probably notice that the first block of code is the setup() function – we do not declare or initialize any variables at the beginning of this sketch – instead we will do this inside the loop() function, as in the last example. Inside the curly braces of setup() we revisit the Serial library and use the function Serial.begin(). void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } 1 2 3 4 5 6 7 void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } If you recall from the last lesson, Serial.begin() takes the baud rate as an argument (this will almost always be 9600). This function allows you to setup a communication channel between the computer and the Arduino. As you may know by now, setup() only runs once, and then we move on to the next block of code. But wait! Don’t we have to set the mode of the pin we will be using? Great point! What the Arduino does, by default, is set all the pins on the board as INPUTs unless you tell it otherwise. So in many cases, you do not have to explicitly set a pin as an input using the pinMode() function. That being said – I make it a habit to do this anyway – because it makes things clear to me – and that is worth it in space and effort. So I dare you, set the mode of the pin using the pinMode(A0, INPUT) function inside the curly braces of setup()– you won’t regret it. Moving on to the loop() function, we start with a variable declaration and initialization. int sensorValue = analogRead(A0); 1 int sensorValue = analogRead(A0); We declare a variable called sensorValue and we initialize it to the output of a new function. This new function is the glamorous analogRead(). So take a wild guess what this new function analogRead() does. It reads the value at the analog pin that you have chosen – in this case, it is the analog pin A0, where we have the center pin of the potentiometer connected. The voltage at pin A0 will be mapped to a number between 0 and 1023, and this value will be assigned to the variable sensorValue. If you recall from above, the actual voltage at pin A0 will be between 0 and 5 volts, depending on where your potentiometer is adjusted – this value gets mapped to the range 0 – 1023 with the help of the analog-to-digital converter. So we have a variable that has recorded the value at our potentiometer – what next? Well, let’s look at the value. To do that, we need to print it from the Arduino to our computer – and you guessed it, we will use the Serial library function println() to do just that… Serial.println(sensorValue); 1 Serial.println(sensorValue); No big surprises here – we send as an argument the sensorValue variable to the function Serial.println() and our serial monitor window will display the resulting values. To finish the sketch, we invoke the delay() function for one millisecond to make sure our next reading is a stable one and we start at the top of the loop() again. We record a new value using analogRead(), save it to the variable sensorValue and then print it to the computer. All this is good and well, you might be thinking, but what does a potentiometer have to do with sensors? A potentiometer doesn’t sense anything! You are right – but interestingly, many sensors work by applying the same principle that a potentiometer does – adjusting resistance. Take a photo-resister for example – it can be used to sense light – because the resistance changes based on the brightness of light that it is exposed to – this change in resistance will adjust the amount of voltage that a pin on the receiving end will receive. So now the ball is in your court – what can you use analogRead() for? Try On Your Own Change the analog pin to A2. Make adjustments in the code and the circuit. Try a different potentiometer in the circuit, does it affect the range of values displayed? Further Reading analogRead() Analog Input Pins potentiometer tutorial – this is good

Coding 101 (MP3)
C101 97: Arduino PWM

Coding 101 (MP3)

Play Episode Listen Later Dec 21, 2015 62:01


Building Arduino with PWM. Pulse Width Modulation is a technique for getting analog results with digital means. Parts ListArduino Uno ($3.61)Breadboard and Jumper Wires ($7.48)PixelStick ($3.25)RTFPixel Circle ($10) Hosts: Fr. Robert Ballecer, SJ and Louis Maresca Subscribe and get Coding 101 automatically at https://twit.tv/code Follow @PadreSJ and @LouMM on Twitter. Bandwidth for Coding 101 is provided by CacheFly. Sponsors: digitalocean.com - promo code: C101 lynda.com/c101

programming sj coding bandwidth arduino cachefly pwm robert ballecer breadboard hosts fr pulse width modulation pixelstick jumper wires rtfpixel circle loumm building arduino parts listarduino uno
Coding 101 (Video HD)
C101 97: Arduino PWM

Coding 101 (Video HD)

Play Episode Listen Later Dec 21, 2015 62:01


Building Arduino with PWM. Pulse Width Modulation is a technique for getting analog results with digital means. Parts ListArduino Uno ($3.61)Breadboard and Jumper Wires ($7.48)PixelStick ($3.25)RTFPixel Circle ($10) Hosts: Fr. Robert Ballecer, SJ and Louis Maresca Subscribe and get Coding 101 automatically at https://twit.tv/code Follow @PadreSJ and @LouMM on Twitter. Bandwidth for Coding 101 is provided by CacheFly. Sponsors: digitalocean.com - promo code: C101 lynda.com/c101

programming sj coding bandwidth arduino cachefly pwm robert ballecer breadboard hosts fr pulse width modulation pixelstick jumper wires rtfpixel circle loumm building arduino parts listarduino uno
Coding 101 (Video HI)
C101 97: Arduino PWM

Coding 101 (Video HI)

Play Episode Listen Later Dec 21, 2015 62:01


Building Arduino with PWM. Pulse Width Modulation is a technique for getting analog results with digital means. Parts ListArduino Uno ($3.61)Breadboard and Jumper Wires ($7.48)PixelStick ($3.25)RTFPixel Circle ($10) Hosts: Fr. Robert Ballecer, SJ and Louis Maresca Subscribe and get Coding 101 automatically at https://twit.tv/code Follow @PadreSJ and @LouMM on Twitter. Bandwidth for Coding 101 is provided by CacheFly. Sponsors: digitalocean.com - promo code: C101 lynda.com/c101

programming sj coding bandwidth arduino cachefly pwm robert ballecer breadboard hosts fr pulse width modulation pixelstick jumper wires rtfpixel circle loumm building arduino parts listarduino uno
Coding 101 (Video LO)
C101 97: Arduino PWM

Coding 101 (Video LO)

Play Episode Listen Later Dec 21, 2015 62:01


Building Arduino with PWM. Pulse Width Modulation is a technique for getting analog results with digital means. Parts ListArduino Uno ($3.61)Breadboard and Jumper Wires ($7.48)PixelStick ($3.25)RTFPixel Circle ($10) Hosts: Fr. Robert Ballecer, SJ and Louis Maresca Subscribe and get Coding 101 automatically at https://twit.tv/code Follow @PadreSJ and @LouMM on Twitter. Bandwidth for Coding 101 is provided by CacheFly. Sponsors: digitalocean.com - promo code: C101 lynda.com/c101

programming sj coding bandwidth arduino cachefly pwm robert ballecer breadboard hosts fr pulse width modulation pixelstick jumper wires rtfpixel circle loumm building arduino parts listarduino uno