Soldering is a core tangible skill. This post will walk you through the basics by showing you how to solder wires onto a speaker and a single color LED. These introductory tasks should help you get comfortable with the soldering work stations and opens up numerous pathways for further exploration. Soldering can become a practice in itself and often reflects a deep commitment to tangible as a creative pursuit.
Soldering is one of those skills that people can really get lost in (in the best sense of that phrase). It can be very meditative and relaxing. Some students really enjoy the process and find ways to maximize developing the skill by including it in projects throughout the term.
We want you to solder a few connections to get some experience, understand the process and get comfortable holding hot tools.
tangible students will find soldering stations in the makerSpace (card access required). There are 4 permanent stations and we have many more portable stations when things get busy.
Video
Going Further
*Through-hole soldering is not shown above but is another soldering skill that you may want to explore. This sparkfun tutorial is a great intro to soldering basics and through hole soldering in particular. Unfortunately, it has a ton of ads and product placements. However, you can jump to the associated video.
The new Arduino IDE has a lot of powerful features. Unfortunately the plotter app is not one of them. It can be frustrating, but there is a fix.
Out of the box the Arduino 2.x plotter only displays 50 data points at a time. This is not enough for seeing many trends in sensors and other contexts.
This post is all about making the 2.x plotter wider so you can get the most out of this tool.
You have to do this every time you update your Arduino software!
The posts above gives us the strategy, but the path to the file we need to mod has changed since the solution was first shared. The above solution worked until at least Aug 2023. But as of October 2023 the needed file has moved.
The rest of this post is based on above using the current file structure.
What we need to do
Our goal is to make the plotter 500 points wide not 50. We are going to track down the serial plotter software inside Arduino IDE and mode the file so that 500 points are displayed.
Test COde
Cut, paste and upload the following code using IDE 2.x to test your plotter as you work through this mod. (This is not needed in IDE 1.x).
// simpleSquareWave generator
// plotter test code
unsigned long interval = 50;
unsigned long start = 0;
unsigned long now = 0;
int STATE = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
now = millis();
if ( (now - start) > interval){
STATE = 1 - STATE;
start+= interval;
}
Serial.println(STATE);
delay(10);
}
Video
Here are video instructions — text follows with search terms and paths spelled out.
[thanks David Bouchard for confirming the path and the search tip.]
File to FIND:
Once you get to the .js file you are looking for:
main.35ae02cb.chunk.js
Copy it — to back it up.
Then,
Open the original file in a text editor and find/search for the following line:
U=Object(o.useState)(50)
change that line by adding a zero (0) in the brackets to make 50, 500
U=Object(o.useState)(500)
Save the file. Do not change the name.
With some computers / setups you may need to change permissions to save. It will be ok. Go for it.
At this point the plotter is modded — you can test.
Permissions and Saving
You may need to enable ‘Write’ permission on the file to save your changes. If you try to save and it throws a warning about not being allowed, try the following:
OSX
In FINDER, right click the file and click Get Info or simply highlight the file and on keyboard click BUTTERFLY-I (butterfly is command).
The bottom of info window is permissions. Unlock the window (bottom right icon — enter password if you need to) – then for your user name OR everyone select Read and Write. Re-lock window for good measure.
You should now be able to save.
Windows
Navigate to the file we are modding and open settings. Different Windows versions may do this differently …
In File Explorer click on the file and then on keyboard press Alt-ENTER or with mouse ALT-Double-click this should give a settings window.
Once you have the settings window open … select SECURITY tab.
In that tab — select USERS in Group or user name frame, click EDIT (i don’t know which of those comes first), click the box for WRITE, ALLOW which should now be visible and click OK to save changes.
That should do it (i hope). You should be able to save.
Thanks to Rosalind P from tangible 2023 for help explaining the windows fix and sending along the images. All errors are mine.
Back to Arduino
In the Arduino IDE, with the above test code running, reopen the plotter and if all is well, you will see the 500 point wide plotter dancing before you.
Nailed it. Applaud self — get on with day.
If you have trouble opening the plotter, restart Arduino. And try again.
If it has really gone wrong — i did mess this up once to see what a worst case scenario might look like — you can reinstall Arduino 2.x.x and start again. No harm done.
In this post I explore and describe the connections, libraries and code required to connect grove accelerometers to our Arduino Unos.
We are using a Seed Studio’s Grove 3-axis digital accelerometer (LIS3DHTR). There are a couple of little details that might slow you down at first, but once you have things sorted you should find this an easy sensor to interface.
Accelerometers measure the acceleration (motion) of the sensor body along the X,Y,Z-axis. Acceleration is the rate of change of velocity (speed) of a moving body. At this point it is acceptable to think of it as movement.
All kinds of playful interfaces become possible when you add acceleration to sensory capacity of a controller or object.
Parts required
Arduino Uno
breadboard
accelerometer
grove to header pin connector
hookup wire (for power)
Serial not Voltage
This grove sensor is unique in our kits. It uses a serial protocol to send sensor readings into the Arduino. The data sent over serial uses a specified protocol called I2C (said eye-squared-see — tho I often incorrectly say eye-two-see ; learned it wrong, can’t shake it).
This course is not about serial protocols, so I will be light on details. I2C is serial — and in this way similar to the Serial object and port we have been using in many of the tangible videos and in class. I2C is an example of synchronous serial. This means data transmission is regulated by a clock. The basic command Serial.println() and similar, that we use all the time, is a-synchronous — there is not clock — just a baud rate.
Once up and running, the sensor sends a data stream to the Arduino (over I2C). We can unpack that data with the help of a library. This is very different than the simple sensors such as buttons, photocells and pots we have been using in class. The simpler sensors create changes in voltage that are sent to the Arduino and we read these changing voltages directly.
Video
Get the Library
As indicate above, in addition to hardware, you will need to install a free library that will simplify the use of the sensor.
To do this, in Arduino software, navigate to Arduino-> Sketch-> Include Library-> Manage Libraries
A Library Manager window will open. In the search box (upper right) type LIS3DHTR
This should result in the GROVE library for the LIS3DHTR sensor being displayed. Select and install the latest version (1.2.4 at time of writing). Make SURE you get thegrove version (not the adafruit one).
Once the library installs you can close the library manager window.
Add Some Code
When the code below is uploaded you should see X,Y,Z values returned in the serial monitor or plotter. But on first try you may get gibberish in the serial monitor. This is because the provided sample code uses a fast baud rate for communication between your Arduino and programming computer.
Set Baud
You need to match the baud rate set in the serial monitor and/or plotter with the baud rate set in code. In the setup(), of this example the baud (communication rate between Arduino and your computer) is set to 115200 (not the default 9600 we generally use).
Serial.begin(115200);
You need to use the BAUD drop down in the serial plotter/ monitor to match that code setting.
The image below shows drop down for baud setting in serial monitor.
The image below shows drop down for baud setting in serial plotter.
Now, upload the following code, open plotter or monitor and tilt the sensor in various directions to see how the values change.
// Simplified example -- see video for details.
// This example shows the 3 axis acceleration.
#include "LIS3DHTR.h"
#include <Wire.h>
LIS3DHTR<TwoWire> LIS; //IIC
#define WIRE Wire
void setup() {
Serial.begin(115200);
while (!Serial) {};
LIS.begin(WIRE, 0x19); //IIC init
delay(100); // give it a moment to start
LIS.setFullScaleRange(LIS3DHTR_RANGE_2G); //sensitivity
LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ); // data rate
LIS.setHighSolution(true); //High solution enable
}
void loop() {
if (!LIS) {
Serial.println("LIS3DHTR didn't connect.");
while (1);
return;
}
//3 axis
Serial.print("x:"); Serial.print(LIS.getAccelerationX()); Serial.print(" ");
Serial.print("y:"); Serial.print(LIS.getAccelerationY()); Serial.print(" ");
Serial.print("z:"); Serial.println(LIS.getAccelerationZ());
delay(50);
}
Comparing positional (180) and continuous (360) servos.
Last updated on October 4th, 2024
In the intro to servos post, I describe how to setup, center and point a 180-degree, positional servo. In this post we are going to extend that knowledge and explore how to use continuous rotation, 360-degree servos.
Both servos accept the same signal from Arduino, but they behave in very different ways. These differences arise from the servo hardware itself. Positional servos have physical stops that prevent movement beyond 180 degrees and accept signals as position. Continuous servos rotate 360 degrees and accept signals as indicators of speed and direction.
Required Parts
positional (180-degree) servo (check label — ends with 9g)
continuous (360-degree) servo (check label — it says 360 at end)
arduino
breadboard
wire ( dupont or hookup)
The Circuit
Here is a circuit diagram and simulation of the work we are about to do physically.
pos = 90; // center servos -- do this once then comment out
The line sets the servo pos to 90 for each loop. This will stop the continuous servo and center the positional servo. You can now attach the servos horns.
Now, comment out line 24, allowing the increment to change position.
// continuous and postional servos
#include <Servo.h>
Servo positional_180;
Servo continuous_360;
int pos = 90;
int increment = 1;
void setup()
{
positional_180.attach(3);
continuous_360.attach(4);
Serial.begin(9600);
}
void loop()
{
// movement from 90 to 180
pos = 90; // center servos -- do this once then comment out
positional_180.write(pos);
continuous_360.write(pos);
delay(50); // it takes time to physically move
pos+=increment;
// use the following one at a time
// 90 to 0 (right side, clockwise)
if ((pos <= 0) || (pos>=91)) {increment *= -1; delay(1000); }
// 90 to 180 left side, counter clockwise
//if ((pos >= 180) || (pos<=90)) {increment *= -1; delay(1000); }
// full swing 0-180, start at 90
//if ((pos <= 0) || (pos>=180)) {increment *= -1; delay(1000); }
Serial.println(pos);
}
If you don’t have a Glitch account, get one. BTW, Glitch chose to update its entire interface in January 2022 — this broke a ton of tutorials and functions. They are working on it — but it reduces the value of this platform for now. We were always going move beyond glitch — this may just force us to do it sooner.
Regardless — a glitch account can make some things easier.
shiftr.io
shiftr.io is a public facing, mostly free MQTT broker. We will begin with it fairly early on. I have set up some public facing brokers — but you will probably want your own account for playing around.
Download and install Atom for your platform. Atom is a text editor that will allow us to do much of the course work. I will use it A LOT.
It can be used for Arduino, P5js and Node.js development. It also crosses over with a lot of Glitch functions.
Once you have Atom installed, we will extend its functionality with some additional Packages. Packages add additional functionality to the base editor allowing you to customize for different workflows
This should open the Core Settings tab with many menu options. On the left select+ Install.
This will switch to the Install Packages view. On the right you should now see a search bar along with other functions. Make sure that the Packages button to the right of the search bar is selected. You will type package names into this bar and once a Package is found, click install (blue button) in the lower right of the Package description.
In the image above you can see two package descriptions. The top one, atom-live-server is installed on my system so the bottom options are Uninstall and Disable. This allows one to turn various Packages on and off to test functionality.
Immediately below this is a package I do not have installed — atom-live-server-plus v3.0.1. In this case, note that the bottom right button is for install.
As you begin to work with Atom you will notice there are lots of variations on some Packages. It worth playing with different ones from time to time to see what they add to your life. Some forks of main packages are vanity projects and you will find yourself uninstalling them immediately.
Package list
Here are some Packages we will need to get us started (these are ones I use — these are not endorsements, and I don’t claim they are the best — they just get it done for me. If you find better ones, let me know and I will add here):
atom-live-server (v2.3.0)
teletype (0.13.4)
markdown-preview (0.160.2)
github (0.36.10)
snippets (1.6.0)
terminal-tab (0.6.0)
If it spell check does not come installed as part of base, then also add one — I use:
spell-check (0.77.1)
That should tons to get us rolling.
Github
We will be using Github to varying degrees. You will need an account to use teletype in Atom. There are several layers and interfaces to using Github. We will build this up slowly over the course of term.
NOTE: At some point we may add command line Github functionality — but not yet.
Node.js
We will use Node.js to build servers. To do this we need to install the engine.
Node is largely a a command line tool — we will get to that in a few weeks. Good to have it on hand.
Install here. For this course it makes most sense to install the LTS ( long term support ) release. at time of writing that would be v16.13.2. If you want grab the current release. We are not that bleeding edge tho.
CoolTerm
At some point we will need a terminal program fancier than the one installed with Arduino. It will be used for viewing and debugging serial communication. Most operating systems have a built in version — but this will give us some cross platform consistency, making it easier to teach.
Download coolTerm here. Scroll down, on last access (Jan 2022) coolTerm is still the first program available a this link.
Almost everyone is familiar with joysticks. They have been ubiquitous on game controllers for 40+ years.
But how do they work? How are They wired? How do we use them in a project?
The joystick in our kit is from Seeed Studio’s (three e’s is on purpose) Grove line of components. You can check their demo and helps files for tips that go beyond this post.
How they Work
Electrically most joysticks are a combination of two potentiometers and a button. Full game controllers expand on this basic pattern considerably.
The potentiometers are permanently arranged at 90 degrees (right angles) to one another allowing for input on the X- and Y-axes. The button can be integrated with the joy stick control as it is with this grove device or positioned separately.
We have already seen how to read values from a POT with analogRead() and a BUTTON with digitalRead() — so the basic connections and code for using a joystick are really review!
The grove stick throws a clever bit of wiring at their joystick and the button is read in conjunction with the analogRead(). We will look at that in detail below.
Let’s explore.
Parts Required
For the basic setup we will connect the joystick directly to the Arduino.
joystick
connector ( grove plug to male headers)
Arduino
Video
in its way.
The Circuit
Grove uses a platform specific plug –called a grove plug — which has 4 pins. The cable that comes with the joystick packaging assumes you have a product called a grove shield which offers sockets for plugging devices. In our context the shield is overly constraining. So we will set the double plug connector that came with the joystick aside ( hang onto it, you never know when it will come in handy).
For this first test we will connect the joystick to the Arduino with the grove-to-header cable. These will be in the sensor bag — you should have several if these connectors.
Make the first connection. The grove plug inserts into the joystick with the lock facing out from the board.
Once connected flip the board over and look at the labels on the bottom. They are labelled X,Y,Vcc,Gnd.
The header pins are then connected as follows: RED (Vcc) –> 5V Black (GND) –> ground Yellow (X) –> Ai White (Y) –> Ai
Where: Ai = any of the Analog input pins A0-A5
The power connections can go directly to the Arduino for quick setups. Or to a breadboard with power rails connected to 5V and GND for setup with multiple devices.
Add Code
Let’s begin by reading the analog inputs on X and Y and seeing how they react in the serial plotter.
As already indicated the X- and Y- axis are just potentiometers that are read with analogRead(). So the code that follows is just the basic analog input code set up for two circuits.
// tangible 2021, steve daniels
// simple read of grove joystick
int xPin = A1;
int yPin = A2;
int xVal, yVal;
void setup() {
// put your setup code here, to run once:
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
xVal = analogRead(xPin);
yVal = analogRead(yPin);
Serial.print(xVal);
Serial.print('\t');
Serial.print(yVal);
Serial.println();
}
What to Expect
Upload this code and open the serial plotter. Once you have scrolling traces move the joystick to it’s X (left -right) and Y (up-down) limits. Watch the traces.
Note: We can also refer to these positions by the cardinal directions of a compass rose: N,S,E,W.
You should see the traces for each axis extend to their limits. The exact shape will depend on how fast you are moving the joystick.
Physical orientation of the device will impact how you interpret the numbers. I am holding mine with the connector to the left.
In this case, moving my thumb right (away from the connector) causes the X-trace (blue) to go to max. Moving my thumb left — toward the connector causes the blue trace to go low.
Similarly, moving my moving my thumb up causes the Y-trace (red) to go to max. Moving my thumb down causes the trace to go low.
Seeking Corners You can also move in two directions simultaneously — and sort out where you went by reading the two traces at the same time. Remember, X is blue; Y is red.
In the image above we can clearly see that we need to consider both traces simultaneously to determine the ‘corner’ we have pushed the joystick.
In code this could be sorted with if/and statements.
Interpreting With Thresholds
I find it easiest (at least initially) to interpret joystick data through the use of Thresholds.
So let’s look at 3 positions and the associated limits visible in the joystick traces. First notice that both axis are centered around roughly 512 — the midpoint of the analogRead() scale, not zero (0). Second notice that pushing the joystick to the cardinal directions leads to a max and min range of about 200 to 800. This range is narrower than a full analogRead() of 0-1023.
Given these boundaries, let’s set some thresholds for high and low values. As we did with thresholds previously we want to set the thresholds with in the range of the sensor — i.e. between min and max. Because the traces are very stable ( a characteristic of POTs ), we can set the thresholds closer to the max and min limits than we would if we averaged max or mix with the centre value. .
To add a threshold in code we have to add the variable declaration and the necessary Serial.print() lines. Since we want to see the output in the plotter, we will format our Serial outputs as print(), followed by tab (‘\t’), not println.
We will add the following above setup():
int maxThreshold = 700;
int minThreshold = 300;
Insert the following into loop(), as a part of the existing Serial.print statements, BEFORE the Serial.println():
We can then make determinations of direction with a series of if statements.
if ( xVal < minThreshold) Serial.print("LEFT");
if ( xVal > maxThreshold) Serial.print("RIGHT");
if ( yVal > maxThreshold) Serial.print("UP");
if ( yVal < minThreshold) Serial.print("DOWN");
Serial.println();
Modified Code
// tangible 2021, steve daniels
// simple read with thresholds of grove joystick
int xPin = A1;
int yPin = A2;
int xVal, yVal;
int maxThreshold = 700;
int minThreshold = 300;
void setup() {
// put your setup code here, to run once:
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
xVal = analogRead(xPin);
yVal = analogRead(yPin);
// for plotter
Serial.print(xVal);
Serial.print('\t');
Serial.print(yVal);
Serial.print('\t');
Serial.print(maxThreshold);
Serial.print('\t');
Serial.print(minThreshold);
Serial.print('\t');
Serial.println();
// for monitor
if ( xVal < minThreshold) Serial.print("LEFT");
if ( xVal > maxThreshold) Serial.print("RIGHT");
if ( yVal > maxThreshold) Serial.print("UP");
if ( yVal < minThreshold) Serial.print("DOWN");
Serial.println();
}
What to Expect
Upload the threshold code and this time open the serial monitor. You will see readings and labels mixed. If you want to only see the directions, comment out the blocks under the comment //for plotter that print the readings and thresholds. I am leaving them in because I still want to use the plotter.
In the serial plotter view you may see the direction labels in the top left corner. This is not readily controlled so it may not happen for you.
Read the BUTTON
The makers of this joystick added an interesting way to read the button. The button is wired such that when it is pressed the X-axis reading jumps to 1023; the maximum value of analogRead(). This means we can detect button presses with the basic wiring above and the addition of one more threshold.
Below is a trace of a the joystick when held in the RIGHT (East) position (small peaks) and when the button is pressed (tall peaks).
We can read this value directly since the button sets the analogRead() to 1023 — but let’s explore reading the button with thresholds.
We can add one more threshold to our code. This time we need the threshold between joystick max (800) and analogRead() max (1023). I am going with 950. We will also need one more if statement.
if ( xVal > buttonThreshold) Serial.print("BUTTON!");
Final code:
// tangible 2021, steve daniels
// simple read, threholds and button of grove joystick
int xPin = A1;
int yPin = A2;
int xVal, yVal;
int maxThreshold = 700;
int minThreshold = 300;
int buttonThreshold = 950;
void setup() {
// put your setup code here, to run once:
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
xVal = analogRead(xPin);
yVal = analogRead(yPin);
// for plotter
Serial.print(xVal);
Serial.print('\t');
Serial.print(yVal);
Serial.print('\t');
Serial.print(maxThreshold);
Serial.print('\t');
Serial.print(minThreshold);
Serial.print('\t');
Serial.print(buttonThreshold);
Serial.print('\t');
Serial.println();
// for monitor
if ( xVal < minThreshold) Serial.print("LEFT");
if ( xVal > maxThreshold) Serial.print("RIGHT");
if ( yVal > maxThreshold) Serial.print("UP");
if ( yVal < minThreshold) Serial.print("DOWN");
if ( xVal > buttonThreshold) Serial.print("BUTTON!");
Serial.println();
}
What to Expect
Open both the plotter and the serial monitor to explore this variation.
In the plotter look for the new upper threshold and button presses exceeding that limit.
In the serial monitor, look for the word BUTTON when you press the joystick down (press firmly). It is nearly impossible to press perfectly straight down, so you will likely see some directions along with the BUTTON message.
Monitor view of button threshold code.
Notice here that you get both RIGHT and BUTTON messages printed. This indicates that two IF statements are true at the same time.
Let’s consider the trace one more time.
In this image the zones created by the thresholds are tinted. The area defined by the low threshold is orange, the center area is white, the max threshold region is yellow (and extends to the very top of the image) and the button threshold region is blue. The green area along the top arises because in this zone blue (button threshold) and yellow (max threshold) overlap.
Because of this overlap, when you press the button on the joystick the analogRead() value of the X-axis goes to 1023. It should be clear that 1023 is bigger than both the maxThreshold AND the buttonThreshold (green overlap in image above.) So both of the following IF statements are true.
if ( xVal > maxThreshold) Serial.print("RIGHT"); if ( xVal > buttonThreshold) Serial.print("BUTTON!");
So, with the code above, every button press triggers BUTTON AND RIGHT — even when you pushing the joystick in a different direction! This is common with multiple IF statements.
This needs a fix.
We need to constrain the yellow zone so that it does not cross into the blue region. This will ensure that the top section will be blue, not green.
Modify the IF statement that prints RIGHT such that is does not trigger when the sensor reading exceeds buttonThreshold.
if ( xVal > maxThreshold && xVal < buttonThreshold) Serial.print("RIGHT");
This line of code constrains the yellow zone to be between maxThreshold and buttonThreshold. When uploaded and viewed in the monitor, button presses only trigger the label BUTTON.
A color coded trace reflecting this newly constrained region is below.
Going Further
Advanced interpretation of joystick values will be dealt with in a later post.
I find current to be one of the trickiest concepts to grasp in introductory electronics. Part of this is because current does not behave the same way in all components. Part of it is because current flow is tied to both your power supply, the thing being powered ( fancy term == load) and the total impact of all parts in a circuit.
Current Flows in LEDs
This Building Block explores how current flows through an LED. It also explains why we use current limiting resistors with LED and how to calculate their size.
Recall Ohm’s Law
Resistors follow Ohm’s law
Current flows through a resistor following Ohm’s law (V=IR). For a fixed resistor — say one of our favourites like a 1K Ω (brown, black, red) — Ohm’s law tells us that if we increase voltage across the resistor, we will proportionally increase current.
LEDs are Different
LEDs act differently. They are diodes — Light Emitting Diodes! And diodes are semiconductors. So, they follow slightly different rules (for a deeper dive into this).
We have seen that our LEDs block current and do not light up when placed in a circuit ‘backwards’ (fancy term == reverse biased). We have also seen that they glow delightfully when placed in circuits with their flat sides to ground (fancy term == forward biased).
Characteristic Forward Voltage
The amount of voltage required to turn an LED on, or make it glow, is called the characteristic forward voltage (VF). The exact value is dependant on the diode — it differs slightly for each color — but is usually 1.4-4V. At the maker / creative level of electronics, that we are exploring, most people assume 2V.
Break Down VOltage
If you exceed the characteristic voltage and give the LED more V than it takes to turn on, then the resistance of the LED drops very fast. When this happens Ohm’s law tells us that LED will use (fancy term == draw) a whole bunch of current. This can, in some cases, lead to LED burn out; along with electric melting smells, LED caps occasionally becoming projectiles and a total lack of glow.
Avoiding LED meltdowns
In addition to a forward voltage spec, LEDs have a characteristic forward current or recommended operating current that should not be exceeded. We can protect our LEDs from the rapid current increases by placing a resistor in series (one after the other) with the LED. We call these resistors current limiting resistors. Note any resistor can be current limiting as long as its placed in series with the LED — its the placement of the component not its brand or type or materiality that makes it current limiting.
Calculating Resistor Size
With this bit of background understood we can jump into determining the size of resistor we need to protect our LEDs.
Let’s assume we are using our basic LED circuit. In this circuit we have a power supply (V), an LED with a set operating (forward) current (I) and a series resistor (R) that limits the current.
We can use Ohm’s law to calculate the size of resistor needed.
In the image above, cover the R and see that resistance (R) is calculated by dividing V / I. Simple. But what V and what I?
We should know V for the circuit — it will be a battery pack of known voltage (9V from out kits) or from Arduino pin (5V for an Uno). If you power up with other sources make sure you know the voltage!
The Power of Data Sheets
Current limits can only be reliably found in the data sheet of the LED you are using. To find this you need to know what LED you have in hand, i.e. what part you bought.
Data sheets are technical documents that outline everything you could want to know about a component. The data sheet for our RED LEDs is mercifully short; only 3 pages. The data sheet for the microcontroller on an Arduino Uno is longer than 300 pages.
The first page of the red LED sheet tells us everything we need to know. It includes the following chart:
Recall that two values are needed for our calculation — forward voltage (turn on voltage – red), and operating current (sometime called forward current- blue).
Forward voltage is listed as being between 1.7 and 2.6V with 2.1V indicated as typical.
Operating current is 10 mA or 0.010A. Max listed as 50mA ( 0.050A). If you exceed the max of 50mA, the LED is a goner.
Formal Calculation
For our basic circuit we can calculate resistor size using the following formula:
where:
R == size of resistor we need Vs == source voltage ( battery or Arduino for us) Vf == forward (turn on) voltage of the LED I == operating current of LED — in AMPS (A). Often this current is listed in mA (milliAmps). If so, you will have to divide mA by 1000 to convert to amps (A).
Battery Powered Resistor
For the battery powered LED and resistor circuit that we started this course with (Alligator Clip Circuit) we would have the following values in the formula:
Which gives a resistance of 690Ω. (You can confirm with a calculator or back of an envelope).
We do not have a 690Ω resistor in our kit (though they exist — what would their color bands be ? ). Instead, we go to the next size up; which in our case is 1KΩ.
Quick and Dirty Calculation
Given that we are making experiences and creatively applying electronics, not making heart rate monitors, we can take a few short cuts. Engineers close your eyes for a moment.
You can simplify this calculation — and I do this all the time — by ignoring the forward voltage of the LED. If you don’t have a data sheet you could also use 2V and apply rule above.
The resulting simplified formula looks like this:
And for our red LEDs with a recommended current of 10mA (.010A) — we would calculate R = 9/0.010 == 900Ω. The closest, next bigger resistor in our kit is 1KΩ. This is the same result as above!
When you ignore forward voltage you end up with a calculation that OVER ESTIMATES the resistance needed. In other works you will use a bigger than needed resistor. The trade off is a circuit with a slightly less bright LED (usually undetectable) in a circuit with too much protection. I think its a good trade-off when data sheets aren’t handy.
What if we don’t know LED current?
It is common in maker tutorials to see people assume the LED current is 20mA (.020A). This a compromise / guess — and it happens because most kits and parts you buy online will not have readily available links to component data sheets.
If you don’t have a data sheet this is generally a good point of departure for LED current. If you use this and things get hot or you melt an LED, get the next bigger resistor in your kit.
This simplified formula for cases when LED current and LED voltage are both unknown is:
For our 9V circuit we would calculate R= 9V/0.020A == 450Ω.
Closest, next largest resistor in our kit is 470Ω. This is smaller than the 1K predicted above.
Current flow with a red LED would be I = V/R == 9/470 == 0.019mA — which is much less than peak current limit. So, you may shorten its life but it won’t explode.
Arduino Pin Considerations
When we connect any circuit to an Arduino pin we need to also consider the current limits of the Arduino.
Each individual pin can handle an absolute limit of 40mA (0.040) based on data sheet (Arduino site says 20mA). However, the Arduino Uno as a whole — all the current, in all the connected circuits, added up, can not exceed 200mA (0.20A).
As our circuits get more complex, we will need to pay attention!
What resistor do we need if we have a 5V I/O pin and unknown LED current and voltage limits.
In his case we use the simplified formula and assume 20mA through the LED. This is less than the Arduino pin limit and should be LED safe.
R == 5V/0.020 == 250Ω. Bigger than our 100Ω resistor, but less than 470Ω — so use at least a 470Ω kit resistor.
If we account for LED forward voltage and use data sheet current.
R == 5-2.1 / 0.01 == 290Ω.
Again, select at least 470Ω.
Playing Safe, Protect your Arduino = 1KΩ
Because of the Arduino hard limit of 200mA — I generally build simple LED circuits with 1kΩ resistors. This means slightly dimmer LEDs than may be possible, but helps keep total current low.
At 5V and 1000Ω (1k) the current supplied by a pin is <5mA. You could safely put one of these on every i/o pin and not exceed the total device limit!
The Arduino platform is made up of a combination of microcontroller boards (hardware) and the Arduino IDE (Integrated Development Environment, software). There are countless variations on boards that have a wide range of capabilities. There are several official options for the code environment and several other platforms that support programming Arduinos.
In this course we will be using Arduino UNO microcontrollers and the latest version (2.x) of their desktop IDE.
Part 1 – Hardware :: What’s an Arduino ?
Microcontrollers are small computers designed to respond to and control connected circuits. These are distinct from microprocessors (the kind of computer chip inside your laptop of desktop). The microcontroller included in your kit is an Arduino Uno.
The Uno is a microcontroller chip (Atmega328) and some related hardware (USB, power regulation, breakout headers) all attached to a single board making it easy to use and program. The Uno is very popular in creative and maker communities. It is an excellent way to start exploring tangible.
Like all of our hardware components we need to be able to identify the device — or in this case it various hardware features, know if electrical limits and learn its representations.
Representation(s)
The Arduino symbol is complex, reflecting the sophistication of the device. We will come to understand all the parts over several weeks.
Arduino Power Limits
One must take care when powering the Arduino. It is a 5V max device. It can be very safely powered by USB — which is designed to provide 5V, 1A to connected devices.
When powered by your battery packs (9V) — the only safe way is to use your battery clip with the barrel jack.
Getting to know your Uno
Required Parts
Arduino UNO
USB cable
Battery Clip with Barrel
UnoUSB cableBarrel Jack Battery Clip
Landmarks
The Uno has several features that you should take the time to get familiar with. They are highlighted in the image below.
The second component of the Arduino system is the programming environment or IDE.
Context of tangible Coding
Before we download and set up the Arduino environment, we should take a moment to think about how it relates to other code contexts you may have used in the past.
Different computer languages and platforms have been developed to solve different problems.
The problems we want to explore in this course revolve around themes of tangible computing: how can we build an experience that knows when people are present? How can I make that thing move? How can I built an object that responds changes in temperature?
All of these examples exist in the real world (not in a web browser or on a screen). The Arduino platform was developed to explore exactly these real world experiences.
Where is the code?
Arduino code is compiled and embedded. As a result, there are a few programming steps that you may not have experienced on other platforms. This is especially true if you are coming from a web (P5JS) background, or from P5JS’s parent platform Processing.
Like many other platforms you will write code in a glorified text editor. However, to make your code run you need to get it inside your Uno (microcontroller).
The first step in this process is compiling. Compiling is an automated process that takes the Arduino-language syntax that you typed and converts it into a machine readable format. Syntax error checking happens at this stage. So typos and language bugs will often be caught here.
Once compiled, the code is UPLOADED into the Uno. Uploading literally moves the compiled machine code from your programming computer into the chip on the Uno board. Once uploaded it runs automatically. You will solve semantic or experience errors and bugs at this stage.
Required Software
You can download the required free software from the Arduino site.
Arduino software is open source and donations are requested. But you can hit the <Just Download> button.
Here is a quick walk through of the process (2024).
Once you have the software downloaded and installed you should test your tool chain.
Comparing Arduino 1.x and 2.x
Make sure you get the latest Version 1.X desktop IDE for your platform (at time of writing this was 1.8.16). We will not be using the Web Editor or the Version 2.0 IDE — which is in Beta. (You are encouraged to check out the V2.0 IDE as it will be standard very soon, but i will teach from 1.X).
As of 2024 we will use Arduino IDE 2.x in our introductory class. This version is a fork of the VSCode environment, so if you have experience there you will see some similarities (and a few differences).
This means that moving forward, older videos use a different interface than the one we are using in class. Some things are in different places. At first you may find the translation between versions a bit overwhelming – but it should be quick to overcome.
To help in this transition, I have made a video which highlights the difference between V1.x and V2.x for board selection, port selection, serial monitor access and functioning, and serial plotter access. You may want to watch it now or later as you move through this introduction.
As mentioned in the video — this is a bit chicken and egg — seeing the comparison before you know the tasks. You may decided to come back to this video at various times through out the course.
GET to know the Arduino SOftware (IDE)
This video was made in 2020. The above video will help you figure out differences if you are unsure.
There is a section in this video (below) that shows you how to turn on line numbers and code folding — these are both enabled by default in the 2.x versions. So nothing to do there. On OSX you can’t turn them off anymore, I assume that is the same across platforms ( let me know if I am wrong, or if your platform is different).
Toolchain overview, Upload code, Blink an LED.
In this video near the end, there is a reference to an assignment called a Circuit Selfie. In 2024 these are now called ARTifacts … check D2L for specific course tasks, because these have changed since the pandemic years.
Checkout the Arduino language
The Arduino language is a subset of C and C++ with some hardware specific (contextual) additions. Take a few minutes to check it out. It has many structures that should be familiar.
Advanced Considerations
If you are new to all of this, feel free to ignore this paragraph.
If you have coded C or C++ or even C# for screen based contexts (apps, phones, gaming) you will notice some features are not available. Arduino Unos are a very basic, single threaded, 8-bit RISC architecture. They do not support screens or multitasking. There is also no math co-processor so INTs largely rule the day.
Going Further
There are thousands of pages and sites dedicated to learning Arduino. Google is your friend but there are caveats. A lot of information dates very quickly. Older posts are very likely no longer current. These may be great for background, but specifics often change. If you search instructables — and you absolutely should — note that info there is not fact checked — not all instructables are complete, nor do they always make sense or even come to the conclusion suggested by their titles. That said, I am learning new stuff there all the time.
The Arduino Getting Started page gives a great overview of all the available boards (when we first used Arduino in this course there was only one board!)
Check out the official Arduino Playground for loads of detailed information. It will go well beyond this course.
If you want to go beyond our kits Sparkfun has lots of Arduino info. BUT BE AWARE that they are US based so buying directly comes with border broker and currency costs. Perhaps use this link for info only and check out some buying tips here before ordering form the states.
This is a list of resources for buying additional parts if you so desire. You should have most ( all?) of what you need in your kit but there are tons of other parts out there and you may want to explore some. these are not endorsements — simply provided for reference. Comparative shopping pays in this space.
Canadian (shipping but no duty or import)
Sometime in 2024 – Creatron seems to have crumbled. This is a big loss – they could be a bit socially cold and occasionally condescending, but they had a great range of products. Creatron (Toronto) — https://www.creatroninc.com/ — post pandemic I think they are down to one store in Toronto.
As of sometime in 2022 or 2023 Elmwood Electronics has merged with pishop.ca This has resulted in slightly higher ticket price — but Canadian dollars and no exchange. Elmwood — https://elmwoodelectronics.ca/ — sell US suppliers (Sparkfun) without the direct import costs — slightly higher prices than you will see on US site — cause they paid import/ shipping for you, and exchange.
You can still go to Supremetronic. 290 College St, Toronto, ON – (just west of Spadina)
Note: Supremetronic is part of Home Hardware and is located in the basement of this Home Hardware location. AFAIK they are not online — but post-COVID they are an adventure and are totally worth a trip — i have not gone recently — let me know how it goes.
This is a good list — I have not used all suppliers listed here but give them a try. http://makercanada.ca/
Warehouse Suppliers
These companies are massive suppliers who sell to individuals. Its an epic experience but you can save some money if you know what you want — these places take a bit search practice. These have Canadian and US sites — check your location when shopping.
Shipping, duty and exchange are all ADDED costs for these. If you find something on these sites, search the suppliers above before you buy and compare prices.
— this site has great tutorials and supports. They are worth a look. Arduino used to be their bread and butter but they have created their own product line — so older tutorials are more relevant to this course than newer ones, but may be dated in some cases.