Arduino is a versatile open source platform for electronics prototyping. It’s a fun, simple and powerful way for anyone to start experimenting with creating interactive projects. Here’s how to get started writing and uploading your first Arduino program, called a sketch. You can follow this link to download the developer.
What Equipment You Will Need
For this project, you will just be using the components on board and won’t require any wiring or additional electrical components.
What You’ll Need:
- Arduino (Uno is used in this project) – Buy Here
- USB A to B Cable – Buy Here
- A Computer (PC or Mac are supported)
When looking at the board, you’ll notice that there are strips of pin sockets down each side which are numbered. These pins are used by the Arduino to interact with the connected components. On the Uno board, there are 13 digital pins which can be set to on or off and used as input or outputs as well as 5 analogue pins, these are used for proportional inputs like detecting the temperature or measuring something. The remaining pins are for power supplies and then a few other functions you will most likely never need.
The Arduino Uno has a small LED attached to pin 13. As a first program, we will make this LED flash continuously.
How To Use The Arduino Software
Start by opening the developer:
When you open the developer, you will be presented with a new, blank sketch. A sketch is a program which can be uploaded onto the Arduino in order to tell it what to do.
A basic sketch consists of two primary functions, the setup function which is run once when the Arduino is powered up and the loop function which is then run continuously. The setup function is therefore where you would write any setup steps and the loop function is where you would write the steps which you wish to have repeated.
To get the LED to flash, we start by assigning a pin to each function. In this case we have the LED attached to pin 13 so we declare the variable ledPin as an integer 13. In the setup function we need to tell the processor that the ledPin is an output pin, each digital pin on the Arduino can be assigned as an input or output pin.
Finally we write the loop function. We want the LED to come on, which is done by setting the output of the ledPin to HIGH. Wait one second, 1000 milliseconds and then turn off by setting the output to LOW. We then need to wait one second again before turning the LED back on. The reason we use delays between on and off instructions is that the Arduino can run hundreds of instructions per second, without the delays it would turn the LED on and off so quickly we wouldn’t even notice it flickering. It would just appear a bit dimmer. Try this out once you have the first program running.
//The DIY Life
//25 August 2016
int ledPin = 13;
pinMode(ledPin,OUTPUT); //Assign pin 13 as an output
digitalWrite(ledPin,HIGH); //Turn the LED on
delay(500); //Wait 1 second (1000 milliseconds)
digitalWrite(ledPin,LOW); //Turn the LED off
delay(1000); //Wait 1 second (1000 milliseconds)
You can download the program used in the example here so that you don’t have to write it out: LED Code.
Once the code is complete, you need to upload it onto the Arduino. First go to Tools > Board and make sure that your specific board is selected. In this case the board is the Arduino Uno.
Next you need to plug the board into one of your computers USB ports using a USB A to B cable. Once the device has been detected by your computer, select the serial port on which your board is connected by going to Tools > Serial Port. If you are not sure, start from the top and try to upload the code on each. You will just get an error message about establishing communication if you select the wrong one. Alternately, go to your computers device manager, under com ports it will list your Arduino Uno and in brackets the com port on which it is connected.
Finally go to File > Upload and your developer should say compiling in the bottom left and a progress bar shows up on the bottom right. In this stage the developer is compiling your instructions into machine code which the Arduino understands. As soon as this is complete (provided there are no errors in your code), the TX and RX lights will flash on your Arduino, the developer will say uploading and the program will be uploaded. If the upload is successful, a message will be displayed in the bottom section of the developer which says Done Uploading.
As soon as the program finishes uploading, it will run the code. The TX and RX lights will go off and you should see the LED on pin 13 turning on and off every 1s.
The TX and RX lights flash during communication with the computer and finally the LED begins flashing as per the code:
Try and play around with different length delays once this program is working.
Congratulations, your just wrote and uploaded your first program onto an Arduino. Let us know if you have any queries or issues in the comments section below, we would love to help you out.