Difference between revisions of "Arduino"

From Idea Shop Wiki
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  
 
== About ==
 
== About ==
 +
 +
----
 +
 
Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online. You can tell your board what to do by sending a set of instructions to the microcontroller on the board. To do so you use the Arduino programming language (based on Wiring), and the Arduino Software (IDE), based on Processing. [https://www.arduino.cc/en/Guide/Introduction Source]
 
Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online. You can tell your board what to do by sending a set of instructions to the microcontroller on the board. To do so you use the Arduino programming language (based on Wiring), and the Arduino Software (IDE), based on Processing. [https://www.arduino.cc/en/Guide/Introduction Source]
  
- More stuff about Arduino-
+
The company manufactures single board micro-controllers and micro-controller kits for building digital devices and interactive objects that can sense and control objects in the physical world.
  
 +
Here is a [https://www.youtube.com/watch?v=_ItSHuIJAJ8 Video Tutorial] for an Introduction to Arduino
 +
 +
<!-- More stuff about Arduino
 +
Uno, mega, fio-->
 
===Hardware components===
 
===Hardware components===
blah blah blah
+
Arduinos connect to individual electrical components via a total of 29 "pins". The physical pins on an arduino are small hole that line the edges that are similar to breadboard holes. Though some pins are reserved for specific purposes, most are GPIO (General Purpose Input-Output) pins. There are 14 digital GPIO pins and 6 analog GPIO pins. Each of the 20 GPIO pins can be controlled by the code running on the Arduino's ATmega328P chip. The Arduino also has a barrel plug so that it can be powered by an outside source (such as a "wall wart" plug) and a USB-B port for connecting to a computer for power and programming. Finally, each Arduino is equipped with a reset button, to start it's program over from the beginning. A full pinout diagram for the arduino can be found [https://www.circuito.io/blog/arduino-uno-pinout/ here].
  
 
===Software components===
 
===Software components===
stuff about code
+
Since it is less important to know about the details of the Arduino's software, here is a brief explanation. The Arduino runs on an ATmega328P chip, which can be seen clearly on the Arduino itself. Once a program is written for the Arduino in the IDE, it is compiled to machine code to be run on the ATmega328P and uploaded. When the Arduino is first powered on, or when a new sketch is uploaded, or when the reset button is pressed, the ATmega328P's bootloader runs the program that is written to it.
 +
====Memory====
 +
The Arduino has 3 types of internal memory, each with a specific use.<br>
 +
&emsp;-The Flash memory is where the program is stored. On the Arduino Uno, the Flash memory is 32kB (only 27kB is available to the programmer)<br>
 +
&emsp;-The SRAM(Static Random Access Memory) is where variables are stored. The Arduino Uno has 2kB of SRAM<br>
 +
&emsp;-Finally, the Arduino Uno has 1kB of EEPROM. EEPROM can be used for long-term variable storage, similarly to the hard drive of a normal computer. However, EEPROM is not as capable or reliable as normal disk memory. Details of the pros and cons of EEPROM can be found [https://randomnerdtutorials.com/arduino-eeprom-explained-remember-last-led-state/ here]
  
 
== Uses of Arduino ==
 
== Uses of Arduino ==
  
-Examples of projects-
+
----
 +
 
 +
<!--Examples of projects-->
 +
Here is a Lab Manual intended to provide a basic introduction to Arduino and the concepts we use here at the Idea Shop.  This lab manual was created for people with basic programming knowledge, but no Arduino experience.  The topics covered are; digital input and output, operating servos, and Serial communication.
 +
 
 +
This lab manual may not answer all the questions you have about a topic, but many of the challenges include reference links.  Don’t forget; you can always ask the lab mentors for help.
 +
 
 +
===Challenge 1: Blink an LED===
 +
If you’ve done this before feel free to continue to the next challenge.
 +
====Hardware Required====
 +
&emsp;-Arduino Uno<br>
 +
&emsp;-LED<br>
 +
&emsp;-220 Ohm Resistor (Red-Red-Brown-Gold color bands)<br>
 +
&emsp;-USB-A Cord<br>
 +
&emsp;-Computer with Arduino program installed<br>
 +
 
 +
====Instructions====
 +
This challenge is simple, use an Arduino Uno to blink an LED on and off.  An LED is an electronic component that emits light when it’s fed power.  However, this component can only be connected to a circuit one way, in other words it only allows current to flow in one direction, which makes it a diode.  This is how we derived the name LED, or Light Emitting Diode. 
 +
 
 +
Before we try to make the LED blink, let’s test our circuit on a breadboard.  A breadboard is a device that allows us to test our circuits easily by inserting/removing wire connections and components easily.<br>
 +
[[File:Arduino Fig 1-1.png]]<br>
 +
Breadboards have connections between horizontal holes on either side of the middle divider (see above).  We use this to connect components and create circuits.  The two columns on either side are connected to each other, and we usually use them to distribute power and ground,
 +
 
 +
To test your LED you’ll neNow, we will get into our first bit of Arduino programming.  Make sure you have the Arduino IDE downloaded on a computer before we start.  Open it up and go to File<Examples<Basics<Blink.  Upload the Sketch to the Arduino by clicking the right-facing arrow in the top left corner.  When it’s finished uploading your LED should begin to blink. 
 +
 
 +
Feel free to mess around with the program so you can get a feel for how it works before we move on to the next step. 
 +
 
 +
Check out these links if you want to learn more about the ‘Arduino’ structure of coding:
 +
ed to make a circuit running from the Ground to 5v on the Arduino.  First place the LED on the board, and make sure the feet are in two different rows.  Next, attach a wire from the 5V pin on the arduino to the anode end of the LED (the longer wire).  Then add the 220 ohm resistor in series with the LED, and connect the ground on the Arduino to that.  Your circuit should look like the picture below.<br>
 +
[[File:Arduino Fig 1-2.png]]<br>
 +
Okay, now to apply power to the circuit, plug the Arduino into a usb socket with a USB-A cord.  The LED should light up.
 +
 
 +
Congratulations! You’ve just taken the first step towards mastering Arduino.  Next, we will use the digital pins on the Arduino to control the flow of power to the LED.
 +
 
 +
The digital pins on the Arduino can be configured as either inputs or outputs, for this purpose we will use them as outputs.  For this step, let’s reuse the circuit we just created.  Simply move the 5V wire from 5V to pin 13 on the Arduino, like below.  The digital pins actually operate at 3.3V so the resistor is not required, but we will leave it in for safety.<br>
 +
[[File:Arduino Fig 1-3.png]]<br>
 +
Now, we will get into our first bit of Arduino programming.  Make sure you have the Arduino IDE downloaded on a computer before we start.  Open it up and go to File<Examples<Basics<Blink.  Upload the Sketch to the Arduino by clicking the right-facing arrow in the top left corner.  When it’s finished uploading your LED should begin to blink. 
 +
 
 +
Feel free to mess around with the program so you can get a feel for how it works before we move on to the next step. 
 +
 
 +
Check out these links if you want to learn more about the ‘Arduino’ structure of coding:<br>
 +
[https://www.arduino.cc/reference/en/#structure Arduino Website Refrence]<br>
 +
[https://startingelectronics.org/software/arduino/learn-to-program-course/01-program-structure-flow/ Tutorial from startingelectronics.com]<br>
 +
Remember, it’s okay to mess up.  If you blow up an LED or two, just remember you are learning along the way.
 +
===Challenge 2: Blink an LED with a button===
 +
====Hardware Required====
 +
&emsp;-Arduino Uno<br>
 +
&emsp;-LED<br>
 +
&emsp;-220 Ohm Resistor (Red-Red-Brown-Gold color bands)<br>
 +
&emsp;-USB-A Cord<br>
 +
&emsp;-breadboard push-button<br>
 +
&emsp;-Computer with Arduino program installed<br>
 +
====Instructions====
 +
There are a couple ways we could blink an LED with a button.  First, we could connect it in series so current won’t flow through the circuit when the button isn’t pressed.  Second, we could use input from the digital pins, and some light programming on the Arduino, and output from the digital pins to control the LED.
 +
 
 +
Feel free to try both of these by yourself before you read the tutorial.
 +
 
 +
Let’s try the series method first.  Build your circuit like this, using a push-button.<br>
 +
[[File:Arduino Fig 2-1.png]]<br>
 +
Basically, we are just adding the button component in the circuit to act as a break,  Make sure the anode (longer side) of the LED is connected to the 5V side.
 +
 
 +
The breadboard push-button will complete a circuit between two of it’s closer pins when it’s depressed.  When it’s not feeling depressed, the circuit will be incomplete.  Try testing the properties of the push-button by experimenting with different positions.
 +
 
 +
Now let’s try using the push-button as input on the Arduino.  Complete the circuit below, and open and upload the sketch at File<Examples<Digital<Button.<br>
 +
[[File:Arduino Fig 2-2.png]]<br>
 +
When you’re assembling this circuit you may notice the extra resistor connected to ground. This is a pull-down resistor, it keeps the logic signal at zero when the circuit is incomplete.  Try taking it out and see what happens to the light.
 +
 
 +
If you want to learn more about if statements and Arduino syntax, check out the following resources:<br>
 +
[https://www.youtube.com/watch?v=tpIctyqH29Q&list=PL8dPuuaLjXtNlUrzyH5r6jN9ulIgZBpdo Crash Course Computer Science]<br>
 +
[https://playground.arduino.cc/uploads/Main/arduino_notebook_v1-1.pdf Arduino Programming Language Basics PDF]
 +
 
 +
===Challenge 3: Controling the LED with your keyboard===
 +
====Hardware Required====
 +
&emsp;-Arduino Uno<br>
 +
&emsp;-LED<br>
 +
&emsp;-220 Ohm Resistor (Red-Red-Brown-Gold color bands)<br>
 +
&emsp;-USB-A Cord<br>
 +
&emsp;-breadboard push-button<br>
 +
&emsp;-Computer with Arduino program installed<br>
 +
====Instructions====
 +
For this challenge, we will use the Serial Monitor function of the Arduino.  Let’s test it out with a simple ‘Hello World’ program.
 +
 
 +
Write the following simple program in the Arduino IDE and upload it to your Arduino.<br>
 +
<code>
 +
<br>
 +
void setup()<br>
 +
{<br>
 +
Serial.begin(9600);<br>
 +
Serial.println(“Hello World!”);<br>
 +
}<br>
 +
<br>
 +
</code>
 +
Serial, or UART (standing for universal asynchronous receiver-transmitter), is used for communication between the Arduino and other devices.  An Arduino Uno has two pins (0 and 1) that it can use to communicate with other hardware, they are also tied to the USB adapter on the board.  For now, we will use the latter.
 +
 
 +
The number after Serial.begin indicates the baud rate.  The baud rate is the measure of speed of communication between those two devices.  The baud rate will need to be set to be the same on both devices or the data received will be different. Usually we use 57600 as our baud rate, the higher the number the faster information is transmitted.
 +
 
 +
Test this program by going to Tools and Serial monitor in the Arduino IDE.  You should see your message appear!  FYI, when you open the Serial monitor your Arduino will reset, just like hitting the reset button on the board.
 +
 
 +
Now let’s try to give the Arduino some input with our computer.  Write the following code in the Arduino IDE:<br>
 +
<code>void setup() {
 +
  Serial.begin(9600);
 +
}
 +
void loop() {
 +
  if (Serial.available() > 0) {
 +
    // get incoming byte:
 +
    Serial.print((String)Serial.read() + “ echo echo echo”);
 +
  }
 +
}</code><br>
 +
Test the code as we did before in the Serial Monitor.  This time, type in a message at the top of the Serial Monitor window.  Notice however that each character is printed separately. This is because Serial.read() only returns a single character.
 +
 
 +
 
 +
This program uses Arduino Serial Communication as a basis too. The if statement in the loop will only activate when the Arduino gets input from the computer.  Then the Arduino reads the input and returns it, just like the Hello World program.
 +
 
 +
Based on this, and the button sketch from earlier we will now try to control an LED using the Serial Monitor window.  Feel free to try this yourself before reading the instructions.
 +
 
 +
Here’s how I did it:
 +
 
 +
First I set the circuit up just like the blink project<br>
 +
[[File:Arduino Fig 3-1.png]]<br>
 +
Then I wrote the following code<br>
 +
<code>int led_pin = 13;
 +
char input;
 +
 
 +
void setup() {
 +
pinMode(led_pin,OUTPUT);
 +
Serial.begin(9600);
 +
}
 +
 
 +
void loop() {
 +
 
 +
  if (Serial.available() > 0) {
 +
    // get incoming byte:
 +
    input = (char)(Serial.read());
 +
 
 +
    if(input == ‘1’)
 +
    {
 +
      digitalWrite(led_pin, HIGH);
 +
    }
 +
    else if(input == ‘0’)
 +
    {
 +
      digitalWrite(led_pin, LOW);
 +
    }
 +
 
 +
  }
 +
}</code><br>
 +
Like before, the first if statement will trigger when the Arduino detects input from the Serial Monitor.  Then the Arduino checks if “1” or “0” was sent to decide if it should turn the LED on or off.
 +
===Challenge 4: Move a Servo===
 +
====Hardware Required:====
 +
&emsp;-Arduino Uno<br>
 +
&emsp;-22 Gauge Wire<br>
 +
&emsp;-Servo<br>
 +
&emsp;-USB-A cord<br>
 +
&emsp;-Computer with Arduino Program<br>
 +
====Instructions:====
 +
A servo is a device with a rotating shaft that can be controlled with electrical signals.  The Arduino sends an electric pulse, with variable width to the servo, which interprets the signal as angular position.  This method of communication is called pulse-width modulation.  Only pins with a tilde next to them on the Arduino will be able to use PWM.
 +
 
 +
To control the servo we will use a premade library, called Servo (pretty easy to remember).  An Arduino library provides extra functionality.  For example, you may need a library to control an LED screen.
 +
 
 +
If you need to install the Servo library click [https://playground.arduino.cc/ComponentLib/Servo here.]
 +
Click [https://www.arduino.cc/en/Guide/Libraries here] to learn how to install additional libraries.<br>
 +
[[File:Arduino Fig 4-1.png]]<br>
 +
Attach a servo to your Arduino as shown, and upload the sketch at File<Examples<Servo<Sweep
 +
 
 +
Your servo should begin to move!  Try messing around with the code, or read the documentation on this sketch [https://www.arduino.cc/en/Reference/servo here] to figure out how it works.
 +
===Bonus Challenge: Move a Servo with your keyboard===
 +
Try adapting the code we wrote for challenge 3 to move a servo using the Serial Monitor function.

Latest revision as of 16:43, 22 April 2020

About


Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online. You can tell your board what to do by sending a set of instructions to the microcontroller on the board. To do so you use the Arduino programming language (based on Wiring), and the Arduino Software (IDE), based on Processing. Source

The company manufactures single board micro-controllers and micro-controller kits for building digital devices and interactive objects that can sense and control objects in the physical world.

Here is a Video Tutorial for an Introduction to Arduino

Hardware components

Arduinos connect to individual electrical components via a total of 29 "pins". The physical pins on an arduino are small hole that line the edges that are similar to breadboard holes. Though some pins are reserved for specific purposes, most are GPIO (General Purpose Input-Output) pins. There are 14 digital GPIO pins and 6 analog GPIO pins. Each of the 20 GPIO pins can be controlled by the code running on the Arduino's ATmega328P chip. The Arduino also has a barrel plug so that it can be powered by an outside source (such as a "wall wart" plug) and a USB-B port for connecting to a computer for power and programming. Finally, each Arduino is equipped with a reset button, to start it's program over from the beginning. A full pinout diagram for the arduino can be found here.

Software components

Since it is less important to know about the details of the Arduino's software, here is a brief explanation. The Arduino runs on an ATmega328P chip, which can be seen clearly on the Arduino itself. Once a program is written for the Arduino in the IDE, it is compiled to machine code to be run on the ATmega328P and uploaded. When the Arduino is first powered on, or when a new sketch is uploaded, or when the reset button is pressed, the ATmega328P's bootloader runs the program that is written to it.

Memory

The Arduino has 3 types of internal memory, each with a specific use.
 -The Flash memory is where the program is stored. On the Arduino Uno, the Flash memory is 32kB (only 27kB is available to the programmer)
 -The SRAM(Static Random Access Memory) is where variables are stored. The Arduino Uno has 2kB of SRAM
 -Finally, the Arduino Uno has 1kB of EEPROM. EEPROM can be used for long-term variable storage, similarly to the hard drive of a normal computer. However, EEPROM is not as capable or reliable as normal disk memory. Details of the pros and cons of EEPROM can be found here

Uses of Arduino


Here is a Lab Manual intended to provide a basic introduction to Arduino and the concepts we use here at the Idea Shop. This lab manual was created for people with basic programming knowledge, but no Arduino experience. The topics covered are; digital input and output, operating servos, and Serial communication.

This lab manual may not answer all the questions you have about a topic, but many of the challenges include reference links. Don’t forget; you can always ask the lab mentors for help.

Challenge 1: Blink an LED

If you’ve done this before feel free to continue to the next challenge.

Hardware Required

 -Arduino Uno
 -LED
 -220 Ohm Resistor (Red-Red-Brown-Gold color bands)
 -USB-A Cord
 -Computer with Arduino program installed

Instructions

This challenge is simple, use an Arduino Uno to blink an LED on and off. An LED is an electronic component that emits light when it’s fed power. However, this component can only be connected to a circuit one way, in other words it only allows current to flow in one direction, which makes it a diode. This is how we derived the name LED, or Light Emitting Diode.

Before we try to make the LED blink, let’s test our circuit on a breadboard. A breadboard is a device that allows us to test our circuits easily by inserting/removing wire connections and components easily.
Arduino Fig 1-1.png
Breadboards have connections between horizontal holes on either side of the middle divider (see above). We use this to connect components and create circuits. The two columns on either side are connected to each other, and we usually use them to distribute power and ground,

To test your LED you’ll neNow, we will get into our first bit of Arduino programming. Make sure you have the Arduino IDE downloaded on a computer before we start. Open it up and go to File<Examples<Basics<Blink. Upload the Sketch to the Arduino by clicking the right-facing arrow in the top left corner. When it’s finished uploading your LED should begin to blink.

Feel free to mess around with the program so you can get a feel for how it works before we move on to the next step.

Check out these links if you want to learn more about the ‘Arduino’ structure of coding: ed to make a circuit running from the Ground to 5v on the Arduino. First place the LED on the board, and make sure the feet are in two different rows. Next, attach a wire from the 5V pin on the arduino to the anode end of the LED (the longer wire). Then add the 220 ohm resistor in series with the LED, and connect the ground on the Arduino to that. Your circuit should look like the picture below.
Arduino Fig 1-2.png
Okay, now to apply power to the circuit, plug the Arduino into a usb socket with a USB-A cord. The LED should light up.

Congratulations! You’ve just taken the first step towards mastering Arduino. Next, we will use the digital pins on the Arduino to control the flow of power to the LED.

The digital pins on the Arduino can be configured as either inputs or outputs, for this purpose we will use them as outputs. For this step, let’s reuse the circuit we just created. Simply move the 5V wire from 5V to pin 13 on the Arduino, like below. The digital pins actually operate at 3.3V so the resistor is not required, but we will leave it in for safety.
Arduino Fig 1-3.png
Now, we will get into our first bit of Arduino programming. Make sure you have the Arduino IDE downloaded on a computer before we start. Open it up and go to File<Examples<Basics<Blink. Upload the Sketch to the Arduino by clicking the right-facing arrow in the top left corner. When it’s finished uploading your LED should begin to blink.

Feel free to mess around with the program so you can get a feel for how it works before we move on to the next step.

Check out these links if you want to learn more about the ‘Arduino’ structure of coding:
Arduino Website Refrence
Tutorial from startingelectronics.com
Remember, it’s okay to mess up. If you blow up an LED or two, just remember you are learning along the way.

Challenge 2: Blink an LED with a button

Hardware Required

 -Arduino Uno
 -LED
 -220 Ohm Resistor (Red-Red-Brown-Gold color bands)
 -USB-A Cord
 -breadboard push-button
 -Computer with Arduino program installed

Instructions

There are a couple ways we could blink an LED with a button. First, we could connect it in series so current won’t flow through the circuit when the button isn’t pressed. Second, we could use input from the digital pins, and some light programming on the Arduino, and output from the digital pins to control the LED.

Feel free to try both of these by yourself before you read the tutorial.

Let’s try the series method first. Build your circuit like this, using a push-button.
Arduino Fig 2-1.png
Basically, we are just adding the button component in the circuit to act as a break, Make sure the anode (longer side) of the LED is connected to the 5V side.

The breadboard push-button will complete a circuit between two of it’s closer pins when it’s depressed. When it’s not feeling depressed, the circuit will be incomplete. Try testing the properties of the push-button by experimenting with different positions.

Now let’s try using the push-button as input on the Arduino. Complete the circuit below, and open and upload the sketch at File<Examples<Digital<Button.
Arduino Fig 2-2.png
When you’re assembling this circuit you may notice the extra resistor connected to ground. This is a pull-down resistor, it keeps the logic signal at zero when the circuit is incomplete. Try taking it out and see what happens to the light.

If you want to learn more about if statements and Arduino syntax, check out the following resources:
Crash Course Computer Science
Arduino Programming Language Basics PDF

Challenge 3: Controling the LED with your keyboard

Hardware Required

 -Arduino Uno
 -LED
 -220 Ohm Resistor (Red-Red-Brown-Gold color bands)
 -USB-A Cord
 -breadboard push-button
 -Computer with Arduino program installed

Instructions

For this challenge, we will use the Serial Monitor function of the Arduino. Let’s test it out with a simple ‘Hello World’ program.

Write the following simple program in the Arduino IDE and upload it to your Arduino.

void setup()
{
Serial.begin(9600);
Serial.println(“Hello World!”);
}

Serial, or UART (standing for universal asynchronous receiver-transmitter), is used for communication between the Arduino and other devices. An Arduino Uno has two pins (0 and 1) that it can use to communicate with other hardware, they are also tied to the USB adapter on the board. For now, we will use the latter.

The number after Serial.begin indicates the baud rate. The baud rate is the measure of speed of communication between those two devices. The baud rate will need to be set to be the same on both devices or the data received will be different. Usually we use 57600 as our baud rate, the higher the number the faster information is transmitted.

Test this program by going to Tools and Serial monitor in the Arduino IDE. You should see your message appear! FYI, when you open the Serial monitor your Arduino will reset, just like hitting the reset button on the board.

Now let’s try to give the Arduino some input with our computer. Write the following code in the Arduino IDE:
void setup() {

 Serial.begin(9600);

} void loop() {

 if (Serial.available() > 0) {
   // get incoming byte:
   Serial.print((String)Serial.read() + “ echo echo echo”);
 }

}
Test the code as we did before in the Serial Monitor. This time, type in a message at the top of the Serial Monitor window. Notice however that each character is printed separately. This is because Serial.read() only returns a single character.


This program uses Arduino Serial Communication as a basis too. The if statement in the loop will only activate when the Arduino gets input from the computer. Then the Arduino reads the input and returns it, just like the Hello World program.

Based on this, and the button sketch from earlier we will now try to control an LED using the Serial Monitor window. Feel free to try this yourself before reading the instructions.

Here’s how I did it:

First I set the circuit up just like the blink project
Arduino Fig 3-1.png
Then I wrote the following code
int led_pin = 13; char input;

void setup() { pinMode(led_pin,OUTPUT);

Serial.begin(9600);

}

void loop() {

 if (Serial.available() > 0) {
   // get incoming byte:
   input = (char)(Serial.read());
   if(input == ‘1’)
   {
      digitalWrite(led_pin, HIGH);
   }
   else if(input == ‘0’)
   {
      digitalWrite(led_pin, LOW);
   }
 }

}
Like before, the first if statement will trigger when the Arduino detects input from the Serial Monitor. Then the Arduino checks if “1” or “0” was sent to decide if it should turn the LED on or off.

Challenge 4: Move a Servo

Hardware Required:

 -Arduino Uno
 -22 Gauge Wire
 -Servo
 -USB-A cord
 -Computer with Arduino Program

Instructions:

A servo is a device with a rotating shaft that can be controlled with electrical signals. The Arduino sends an electric pulse, with variable width to the servo, which interprets the signal as angular position. This method of communication is called pulse-width modulation. Only pins with a tilde next to them on the Arduino will be able to use PWM.

To control the servo we will use a premade library, called Servo (pretty easy to remember). An Arduino library provides extra functionality. For example, you may need a library to control an LED screen.

If you need to install the Servo library click here. Click here to learn how to install additional libraries.
Arduino Fig 4-1.png
Attach a servo to your Arduino as shown, and upload the sketch at File<Examples<Servo<Sweep

Your servo should begin to move! Try messing around with the code, or read the documentation on this sketch here to figure out how it works.

Bonus Challenge: Move a Servo with your keyboard

Try adapting the code we wrote for challenge 3 to move a servo using the Serial Monitor function.