Session 2 - Arduino Basics in Tinkercad
Session 2 - Arduino Basics in Tinkercad
Basics in Tinkercad
TABLE OF CONTENTS
What is Arduino?
Hackster.io
Basics
Breadboards
Breakout Group 1
Breakout Group 2
Breakout Group 1
Breakout Group 2
What is Arduino?
Arduino is an open-source development board used for projects and prototyping. There
are a number of boards with different features, but the Arduino Uno is the most popular
and the one we will be using.
Written in 1 / 20
Arduino Uno R3
You can see the microprocessor on the Arduino in the picture above. It is the main black
rectangle with silver pins. This is where the code that we write will be stored. Each of the
pins on the microprocessor are routed to the black plastic holes on each edge of the
Arduino. You can think of the microprocessor as the brain of our system and whatever we
plug into these holes will become our arms, legs, feelers, etc. We will refer to these holes as
Input/Output pins or IO pins.
Connecting various sensors, buttons, lights, and motors to the pins will allow us to bring in
information, process it in the microprocessor, and move or display information based on
those inputs.
People can create amazing things using an Arduino. There's an entire online community
devoted to sharing devices they have made using an Arduino.
Hackster.io
Written in 2 / 20
How do these devices work? The developer has connected the Arduino to a circuit and
written code to control the circuit. Many of the programs are simply turning things on or off
based on input from a switch or sensor. It's easy to get started and the more you learn, the
more and more complex your projects can get.
Use your first name and last initial as your nickname for the class. i.e. Derrick Henry would
be Derrick H. If you need the class code, it is QSNN UV56 UFI6
Once you are logged in. You should see a page like this. Let's start out by clicking on
Circuits on the left menu bar.
Now click Create new circuit. It should take you to something that looks like the screenshot
below.
Written in 3 / 20
This is the circuit editor. Here we can connect different components to our Arduino, add
code, and simulate what it would be like if we uploaded the code to our Arduino circuit.
Let's take some time to point out some important things on this screen.
Basics
At the very top left is the Tinkercad icon. Clicking this will take you back to your dashboard
where you can see all of your circuits.
Next to that is the name of your circuit. A random name is generated for new circuits, but
you can click on it to change the name.
The scroll box to the right is the component selector. You can click once and click in the
open space to place a component.
Type Arduino into the search bar on the right. Click on the Arduino Uno R3 and then click
in the empty space to the left to place the component.
Written in 4 / 20
Finding and placing an Arduino Un
To move around, click in a blank space and drag the direction you want the screen to go. To
zoom in or out scroll up or down.
Let's check out the buttons in the upper left (highlighted below).
All the way to the left is the rotate tool. Click on a component and click this button to rotate
it.
Written in 5 / 20
Beside that is the delete button. Clicking a component and clicking this button will delete it.
Next to that is undo button. Use this to undo if you accidentally delete something or
connect a wire to the wrong pin.
We also have the redo button next to that. This is helpful if you undo one too many times.
Next is the add annotation button. This allows us to pin a note onto the circuit. This will
allow us to make note of which components do what.
Breadboards
Electricity is a lot like water. To move it around and route it to where we want it, we have a
number of tools, just like we have different size and shape pipes to route water. One of the
tools we use to route our circuits is a breadboard. Let's try using one.
Type breadboard into the search bar and place a small breadboard next to your Arduino
Uno as shown below. Zoom out by scrolling if you need more space.
If you need to move any of the components, click on a spot that is not a hole and drag it
where you want it. Clicking on a hole will begin placement of a wire piece. Press the Esc
key to cancel wire piece placement.
Breadboards are designed to make it easier to connect components together. Let's see
how they work by taking some time to understand a breadboarded circuit.
Written in 6 / 20
Example breadboard circuit
On each side, we have the power and ground rails. The red(+) is used for power and the
black(-) is used for ground. These are connected vertically. I can connect a wire to row 1 on
the left power rail and it will be connected inside of the breadboard to all of the other holes
on that rail. The power and ground rails on the left are not connected to the power and
ground rails on the right. These rails also do not provide power themselves, you must
connect power and ground to them from the Arduino or other power source using wire
pieces.
The middle area is where we connect the majority of our wires and components. In each
row, columns a-e are connected internally and columns f-j are connected internally. There is
a gap in the middle where they are not connected inside. In the picture shown above, the
green wire connects the power rail to the first pin of row 4 (a4) so that we can get power to
Written in 7 / 20
the resistor. Notice that the wire does not need to be connected directly to the end of the
resistor, since it is connected internally.
We typically place components either across the middle gap or from row to row, since we
want to keep each end of the component separate. Look at picture above and notice that
the resistor is placed across the gap and the LED is placed from row to row.
Turning on and off an LED is about as simple as Arduino programs can get. Let's start
building that.
Place a resistor and change it to 220 Ohms. Rotate it and place it across the gap in the
middle of your breadboard. Resistors are not polar, so it does not matter which end goes
on the left and which goes on the right.
Written in 8 / 20
Placing a resistor
Then we want to place an LED on our breadboard. LEDs are polar, so we have to place it a
certain way. In this circuit, we want the anode to be connected to the resistor and the
cathode to be connected to ground. Rotate the LED and place it such that the anode is in a
hole in the same row as the right side of the resistor.
Written in 9 / 20
Placing the LED
Now we need to route some electricity to our resistor and LED. Lets connect the resistor to
the power rail and the LED cathode to ground rail like in the breadboard example circuit.
Then, let's connect the rails to the Arduino. Connect the power rail to the pin on the bottom
row that says 3.3V. Connect the ground rail to any of the pins that say GND.
What happens when we simulate that? The electricity is routed from the 3.3V pin, through
the resistor, through the LED, and back to the ground pin. This is kind of like hooking up a
battery to our LED. To actually control the LED, we have to control the power that gets to
the circuit, and we can do that with a digital IO pin.
Let's connect the resistor to Digital Pin 13 (D13) instead of the power rail.
Written in 10 / 20
Coding the Arduino
Now we're ready to write some code for the Arduino. Click the Code button in the upper
right.
To start off, let's just turn the LED on, wait one second, turn it off, and wait another second.
You will find the wait code blocks under control.
Press the Start Simulation button to simulate uploading your code to the Arduino. If it
works, your LED will blink.
Breakout Group 1
Written in 11 / 20
Objective:
1. Each student should have a successfully running blink circuit made from scratch by the
end of this breakout group.
Extra Content:
1. We put a 220 Ohm resistor between the LED and power in this circuit. What happens if
we increase the resistance to 10k Ohm? What if we decrease to 10 Ohm? Click on the
resistor to edit the value and run the simulation again.
2. We decided we want the LED to blink faster and faster as it runs. Look in the Control
and Variable code block categories for a way to do this.
3. What if we want to vary the brightness of the LED while the Arduino is running? A
potentiometer is a component with a knob that controls a variable resistance. Find it
in the component selector and place it in your circuit such that Terminal 1 is connected
to the same row as the LED anode and the Wiper pin is connected to the 220 Ohm
resistor. You may have to move the resistor down a row and reconnect it to power. Play
around with turning the knob while the simulation is running by clicking and dragging
the knob after you start the simulation.
Answers
Written in 12 / 20
Controlling the LED with a button
Now that we know how to control a digital output pin with code, let's add a button and make
it so that we can toggle the LED using the button.
The green lines drawn on the buttons show where electicity flows
Find the pushbutton component in the component selector and rotate it so that it looks like
the one in the picture above (minus the green lines). Place it in the middle of the board so
that it straddles the middle area like the picture below.
Written in 13 / 20
Pushbutton placement
Then, let's connect one of the button prongs to the Arduino. Let's use Digital Pin 2 (D2). I
changed the color to blue just to make it easier to differentiate from the other green wire.
Written in 14 / 20
How is this button going to interact with the Arduino? Remember the thermostat example I
gave earlier? If the temperature is below the set temperature, turn on the heater. If the
temperature is at the set temperature, turn off the heater. If our LED was a heater, we would
just need to connect a thermometer-type sensor to D2. Remember, this is a Digital IO Pin,
and the IO stands for Input Output, which means it can function as an input or an output.
We could then write the code to read D2 as an input and decide whether we wanted to turn
on the heater or not. For our example, we are going to use how the pushbutton routes
electricity to sense whether it is pushed or not.
Earlier when we wrote the code to blink the LED, we used the following code block:
That turns the LED on. Then we used the code block that sets pin 13 to LOW to turn it off.
What this is actually doing when it sets the pin to HIGH is connecting the pin to 3.3V
internally. When it sets the pin to LOW, it is disconnecting the pin from 3.3V and connecting
it to GND internally. So, we can think of 3.3V as HIGH and GND as LOW.
Now, let's use this pushbutton to route D2 to HIGH when it is pressed and to LOW when it
isn't pressed. Let's look at the pressed/unpressed picture again.
Written in 15 / 20
D2 is connected to the top right. So, we can just connect the top left to GND and the top
right to 3.3V, right? Unfortunately, if we do that, it will create what's known as a short circuit
when we press the button. A short circuit is when power(3.3V) is connected directly to
ground. Basically, there's nothing to limit the flow of electricity, and it will not only shut down
your Arduino, but can actually damage it.
The way to get around this is to put a resistor in between the top left pin of the button and
the GND. Resistors limit how much electricity can flow through the circuit, and will prevent a
short circuit in this case, so let's put a 10k Ohm resistor between the button and the ground
rail.
Inserting a 10k Ohm resistor between the pushbutton and the ground ra
Once the bottom right pin is connected to the power rail, we're ready to code!
Written in 16 / 20
2. If D2 is HIGH, set D13 to HIGH.
3. If D2 is LOW, set D13 to LOW.
Breakout Group 2
Objective:
1. Each student should have a circuit that turns on the LED when their button is pressed
and turns off the LED when the button is released, controlled through the code written
on the Arduino.
Extra Content:
1. What code block can we add to keep the LED on for 2 seconds after we press the
button?
2. We decided we want to use this push button and LED as a bedside light. We don't
want to have to hold down the button to keep our light on! Rewrite the code so that the
LED turns on when the button is pressed, and turns off when the button is pressed
again, as seen below.
Written in 17 / 20
2. This is the code to make the LED blink faster as it runs (until after about 11 seconds,
then it repeats).
3. This is what the potentiometer circuit looks like and how it performs when running (The
above code is running on it).
Written in 18 / 20
Breakout Group 2
1. The wait code block can be adjusted for 2 seconds and added after pin 13 is set to
HIGH.
2. To toggle the LED when the button is pressed, we need the following code:
Written in 19 / 20
We made the variable ledOn to keep track of whether the LED is on or off. When we check
D2, and it is HIGH (the button is pushed), we check ledOn to see if the LED is on or off. If
ledOn is 0, the LED is off, so we set pin 13 to HIGH to turn it on and set the variable ledOn
to 1. If ledOn is not 0, that means the LED is on, so we do the opposite.
Written in 20 / 20