Introduction: Learning to Program the Arduino - Part 1
I am learning the Arduino programming language.
It's a big deal... my friends have been trying to get me to do it for years... I found a great little kit with a bunch of components... I have some time... so let's go!
First... let's see what's in the box and write our first program.
Step 1: Arduino Tutorial - Part 1: Introduction
My friends have been trying for nearly a decade to get me to learn how to program the Arduino using the sketch IDE. I have been using something called BASCOM and even wrote an Instructable on it.
I was looking on a site called Gearbest.com and saw that they had some pretty extensive kits... the KT003 looked like a really good start... I figured i could make a series of 10 videos... then publish this Instructable. There was actually so much to learn that i am breaking this Instructable into two parts... each will have 5 videos!
I liked this kit enough that I contacted them and said I was going to do an Instructable... they said they wanted to help me out... so they gave me a promo code to give anyone else a discount.
The discount code is: GBDADD
So let's jump in and get started! First we will go through all the stuff in the box... and there is a LOT to go through... more than I thought actually... so let's get started.
- Arduino UNO R3 - Very powerful, and quite a few I/O ports... even some A/D available.
- LEDs - Lots of LEDs... we gotta connect some and light them up!
- RGB LED - This one can be any color... we just have to learn how to program it!
- 7-Segment Display - We can make numbers!
- A Battery Case - So once it's programmed... we can take it with us. (Yeay!)
- Resistors - We need these for some of the experiments.
- Jumpers - No stripping wires here... really nice pins for a breadboard.
- Breadboard - I didn't have to find one... it came in the kit... nice one too!
- Matrix LED - Humm... we can make smiley faces and stuff.
- Switches - Tiny buttons... I'm sure they will be useful
- A fire sensor - (IR Sensor) Fire... whoo!
- Photocells - We can look for light, that will be useful.
- 74HC595 - Shift register... we will dive into that in part 2.
- IR Remote Control - We can control things with a very simple interface.
- Temperature Sensor. - We can even plot the temperature on a graph.
- Potentiometer - (Variable Resistor) This allows us to have an analog input.
Let's jump to the first video, look at what is in the box, download and set up our software, and get a simple LED to blink. Once we have the software running and know we can communicate, then we will go to STEP 2 and learn more!
To program the Arduino you will need the software, it's free and can be downloaded here:
There is a section for a donation, it is an optional step... but it helps to advance the capabilities of the software, and every little bit helps.
Step 2: Arduino Tutorial - Part 2: Breadboards and LEDs
In the last section we learned what components came with the kit, how to set up the software and to program the on-board LED to blink. Now that we have a basic handle on that, we want to learn how to connect and control external components to expand our capability.
To connect external components we can use a breadboard. Back when electronic components consisted of tubes and large resistors and other parts, someone wanting to build a prototype circuit would grab a breadboard... literally... that big piece of wood used to cut bread on... and they would drive in nails, connect up wires, and solder things in place. Seriously... I couldn't make that up!
Mischka even wrote a wonderful Instructable about it that you should really go check out...
In the video, we will learn how a modern breadboard works, and with the help of my assistant Violet, we will learn the resistor color codes and how they work. This section is really important for your review... usually we are used to seeing resistors with a 3-band color code. The resistors shipped in the Gearbest kit are a 4-band type. I've been doing electronics over 30 years... it was the first time I had used them... so even I learned how to read these!
When connecting an LED to a power source... if you do not control the current, you can destroy the LED by overheating it. Learn how to calculate the proper resistance for your LED, then let's connect it and program it to blink.
Step 3: Arduino Tutorial - Part 3: Switch Input and Serial Output
Now that we have an LED up and running on an external breadboard, let's learn how to create an input and attach a switch. This way we can have it do something different when we press a button.
The Arduino IDE has a great serial feature... it allows us to send out a text message or data and read it on a screen. Back in the "old days" when I was younger, there were "dumb terminals"... all they did was display any text that came in on a serial line. We will take a look at these, and how the serial display on the Arduino is very similar. (And very useful too!)
We will learn how to connect a switch... and this is something that I see done incorrectly WAY TOO OFTEN.
If you don't take the time to properly connect a switch... and you have some programming errors... it is possible to damage your Arduino when you press the switch. If you don't have a resistor connected to hold the level either high or low... when you are not pressing the switch... you can get incorrect readings. Let's learn how to properly do this so that our circuits work very well every time!
Step 4: Arduino Tutorial - Part 4: Analog Input
I had intended to connect a simple potentiometer (variable resistor) to the analog input to show how it worked, but at the time I was filming this, I was in a hotel without a soldering pencil... so I couldn't get the potentiometer to fit on the breadboard. There is a great little temperature sensor in the kit... so we simply swap the sensor for the potentiometer... and now we will be able to read temperature instead. Don't worry... when I make the second part of this series, we will go over some of the concepts again to be sure that you are familiar with all the components.
We already have a spiffy circuit with an LED and a switch... let's add the temperature sensor and get some readings. Once we do that... I discovered that the Arduino IDE has a serial plotter which will actually display our data in a graphical plot. this way we can see the temperature changes in real time.
I am doing the circuits that you see using Fritzing, it is a very useful tool for documenting your work... it's free and available here: http://fritzing.org/home/
I used the following code in this step, so I wanted to be sure to give proper credit. You can go to the page and download it here: http://playground.arduino.cc/Main/LM35HigherResolution
Be sure to build and experiment with this circuit... it covers a few useful concepts that you will need for more advanced projects further in this series.
- Breadboard Layout
- Setting up an Analog input.
- Using the serial plotter.
- Laying out circuits in Fritzing.
Step 5: Arduino Tutorial - Part 5: the 7-Segment Display
The seven segment display is nothing more than seven LEDs arranged into a shape so that we can create numbers. There are actually eight LEDs on the display... one for the decimal point. There are two kinds of seven segment displays... the common anode and the common cathode.
An anode is a positive point while a cathode is the negative point of a circuit. This means that if you have a common anode display, the common point will be connected to power and each of the display segments will be switched to ground (minus) to make them illuminate.
The kit comes with a common cathode type display. In this case, the cathode (common point) is connected to ground, and voltage is applied to each segment to cause it to light up. These are just simple LEDs in a plastic case... so we still need to take precautions that we do not overload the current on them or we will destroy the LEDs.
The kit comes with an ample supply of 220 ohm resistors which work quite well to limit the current. If you look at the circuit, you will see that each LED has it's own resistor.
Why not just connect one resistor to the common cathodes?
If you only connected a single resistor, the LED would be fine when you lit up only one segment... but when you lit the next segment, the current flowing though both LEDs would be doubled... add another, and it triples... and soon POOF! So remember... one resistor per every LED to keep the circuit balanced.
As an added bonus... we learn to connect a piezo speaker to the circuit and make some noise.
What is the fun in a circuit if it doesn't have blinking lights and/or a noisemaker right?
Step 6: Moving Forward...
That is all I have for now... but I should have at least another five videos when I get time to complete them. Once the videos are online, I will create the PART TWO of this series, and edit this page with the link so you can continue to learn as I do. Next up will be the shift register... I need to pull my friend Riley into this for some help.
Stay tuned for more!
If you are just starting out, be sure to look up the KT003 Arduino UNO Starter Kit and use the promo code
GBDADD for a discount. If you already have an Arduino, be sure to set your IDE to the proper type so that it programs properly. You may notice some pin changes or different capabilities depending on the Arduino that you have. Using a genuine Arduino UNO R3 will ensure that you can follow along with this series.
If there is something specific you would like to see... please let me know in the comments below and I will try to include it in the next section if the components are in the kit. If not... I may do a Part 3... and continue this series further.
The complete Arduino Playlist can be found here:
YouTube Channel: http://youtube.com/askjerry
On the web: http://askjerry.info
We have a be nice policy.
Please be positive and constructive.