Analog Outputs

Analog Outputs (AO) are one of the four contexts or types of circuits that are core to tangible.

If you have not yet looked at the tangible matrix Building Block, you should check it out now. It will introduce you to all four contexts.

Context :: Analog Output

Analog refers to signals, circuits, or logical systems that are variable or graded. They can be the top or bottom of the waterfall and every shade in between.

Input and Output are defined from the perspective of our Arduino.

Electrical signals generated by the Arduino and sent out to circuits are OUTPUTS.

So, Analog Outputs are variable signals (V) that move OUT of the Arduino.

PWM — How Digital Becomes Analog

The Arduino Uno is a strictly digital device. Given this, how is it going to make an analog signal?

The Arduino approximates analog output signals using a process called pulse width modulation or PWM. PWM is achieved by turning a selected pin HIGH and LOW very, very quickly. By altering ON (HIGH, 1) time and OFF (LOW, 0) time one can alter average current delivered to a circuit. We call the ratio of ON:OFF time the duty cycle.

Duty Cycle: A deeper look at PWM

We can use a concept called duty cycle to imagine how this works. A deep look at duty cycle is beyond what we need at this level — but I will cover it in general here. Follow links below for details.

First imagine an LED blinking on a digital pin. The duration of time the pin is HIGH (1) is called ‘ON’ time. And conversely, the amount of time the pin spends ‘LOW” (0) is known as ‘OFF’ time. The blink can be asymmetrical, it can be ON for more or less time than it is ‘OFF”.

We will call one cycle the amount of time it takes to go from the start of the HIGH, through the LOW and just back to the start of the next HIGH.

The percentage of time spent in the HIGH state during one cycle is called the duty cycle.

So a 50% duty cycle would be HIGH (on) for half the time and OFF for the other half. A 75% duty cycle would be on 3/4 of the time and off for 1/4.

A 100% duty cycle is the same as setting a pin HIGH while 0% is equivalent to settinga pin LOW.

Image source

Read more about duty cycle and PWM here.

PWM: Controlling LEDs and Motors

The pulses of a PWM cycle are incredibly fast (brief) — the individual blinks are too fast to see with the naked eye. But they are very real.

When an LED is powered by a pin using PWM, reductions in duty cycle reduce LED brightness. The outcome is a an ON/OFF cycle that dims an LED. This effect is grounded in the same principle that makes video and film look like moving images — not stuttering stills.

We will also use PWM to control speed of motors and the positions of servos.

Card

Your kit contains a reference card for analog outputs.

Each card indicates the context, command, circuit and offers a code sample.

Video :: Analog Outputs

Get the Slides

Classic Example

The classic example of a analog output is a fading LED.

Circuit

The classic circuit for exploring an analog output is a simple LED and current limiting resistor. Yup — it is the same circuit we used for digital outputs.

Command :: analogWrite()

The code that creates an Analog Output is:

    analogWrite(pin, state);

where:
pin = 3,5,6, 9,10,11
state = 0 – 255

Note 1: these pins are marked with a tilde ~

The line of code above means:

Use PWM to set the duty cycle of ~pinX to state = 0 to 255. Where 0 = 0% and 255= 100% duty cycle.

How Does it Work?

As indicated above, analogWrite quickly blinks ~pinX. The variable state defines the duty cycle.

The result is a staircase like change in brightness as state increases from 0 to 255.

Important in Arduino, we Write outputs.

Check the Arduino Docs for this topic

Code Sample

int ledPIN = 6;
int state = 0;

void setup() {
  pinMode( ledPIN, OUTPUT );
}
void loop() {
  analogWrite( ledPIN, state );
  state++;
  delay(50);
}

Once you have this basic code running, try also cycling through the range of possible states with a for loop instead of the counter.

Going Further

Read more about duty cycle and PWM from sparkfun.

Lots of in depth (too much?) info on PWM at wikipedia

Some follow up Arduino references:

pinMode

int — variable declarations

++ increment

Digital Outputs

Digital Outputs (DO) are one of the four contexts or types of circuits that are core to tangible.

If you have not yet looked at the tangible matrix Building Block, you should check it out now. It will introduce you to all four contexts.

Context :: Digital Output

do matrix

Digital refers to signals, circuits, or logical systems that only have two states; ON, OFF.

Input and Output are defined from the perspective of our Arduino.

Electrical signals generated by the Arduino and sent out to circuits are OUTPUTS.

So, Digital Outputs are ON/OFF signals (V) that move OUT of the Arduino.

Card

Your kit contains a reference card for digital outputs.

Each card indicates the context, command, circuit and offers a code sample.

digital output card

Video :: Digital Outputs

This first video is from a project that I completed with David Bouchard. An alternate course specific video can be found below.

tangible introduction to digital outputs. Please note — I extend the first build with an RGB LED in this video. If you have not looked at RGB LED you can just use 2 single color LEDs. It simplifies the circuit. I will post an RGB video ASAP.

Code samples from the video can be found below.

Get the Slides

Classic Example

The classic example of a digital output is a blinking LED.

Circuit

The classic circuit for testing a digital output is a simple LED and current limiting resistor. Circuit on left when state = 0, LOW, circuit on right when state = 1,HIGH.

Command :: digitalWrite()

The code that creates a Digital Output is:

    digitalWrite(pin, state);

where:
pin = 2 – 13 (inclusive)
state = LOW (0, Ground) OR HIGH (1, 5V)

Note 1: pin can also include 0,1; but these are reserved for communication, so best to avoid them. Note 2: pin 13 has the built in LED attached

The line of code above means:

Write a digital (on/off) signal to pin at level = state (0/LOW or 1/HIGH).

How Does it Work?

If a 1 or HIGH is written, then the voltage (V) at the pin is set to 5V.

If a 0 or LOW is written, then the voltage (V) at the pin is set to 0V (ground).

Important

In Arduino, we Write outputs. Image creating waterfalls on the selected pin.

Check the Arduino Docs for this topic

Code Sample – SINGLE LED

int ledPin  = 5 ; // led on pin 5

void setup() {
  pinMode ( ledPin , OUTPUT) ; // set direction
}

void loop() {

  digitalWrite ( ledPin , 1 ) ;   // turn LED on
  delay ( 1000 ) ;  // wait a bit == 1 second

  digitalWrite ( ledPin, 0 ) ;  // turn LED off  
  delay ( 1000 ) ; // wait a bit

}

CODE Sample – 2 colors of RGB LED

// code sample using B and R, of RGB led

int blueLED  = 5 ;  // connect PIN 5 to BLUE pin of RGB LED
int redLED   = 10 ; // connect PIN 10 to RED pin of RGB LED

void setup() { 
  // put your setup code here, to run once:
  pinMode ( blueLED , OUTPUT) ;   
  pinMode ( redLED  , OUTPUT) ; 
}

void loop() { 
  // put your main code here, to run repeatedly:

  //  blue
  digitalWrite ( blueLED , HIGH ) ;   // turn LED on 
  delay ( 1000 ) ;  // wait a bit == 1 second 
  digitalWrite ( blueLED, LOW ) ;  // turn LED off  
  delay  (1000 ) ; // wait a bit 

  //  red
  digitalWrite ( redLED , HIGH ) ; 
  delay ( 1000 ) ;  // wait a bit == 1 second 
  digitalWrite ( redLED, LOW ) ;  // turn LED off  
  delay  (1000 ) ; // wait a bit 
}

Going Further

Some follow up Arduino references:

pinMode

Serial

Digital Inputs

Digital Inputs (DI) are one of the four contexts or types of circuits that are core to tangible.

If you have not yet looked at the tangible matrix Building Block, you should check it out now. It will introduce you to all four contexts.

Context :: Digital Input

Digital refers to signals, circuits, or logical systems that only have two states; ON, OFF.

Input and Output are defined from the perspective of our Arduino.

Electrical signals generated in circuits and sent into the Arduino are INPUTS.

So, Digital Inputs are ON/OFF signals (V) that move INTO the Arduino.

Card

Your kit contains a reference card for digital inputs.

Each card indicates the context, command, circuit and offers a code sample.

Video :: Digital Inputs

Get the Slides

Classic Example

The classic example of a digital input is a button.

Circuit

The classic circuit for testing a digital input is a simple push button (tho any two wires could do). The circuit on left indicates electrical state (state = 0, LOW) when a button is unpressed . The circuit on right indicates electrical state (state = 1,HIGH) when button is pressed.

Command :: digitalRead()

The code that creates a Digital Input is:

    state = digitalRead(pin);

where:
pin = 2 – 13 (inclusive)
state = 0 OR 1 (gnd or 5V)

Note 1: pin can also include 0,1; but these are reserved for communication, so best to avoid them.

Note 2: pin 13 has the built in LED attached

The line of code above means:

Read the digital (on/off) state of pinX and store that reading in a variable called state.

How Does it Work ?

If the button is pressed, a 5V signal reaches pinX and a 1 ( conceptually a HIGH) is stored in state.

If the button is not pressed (released), a 0V or GND signal reaches pinX and a 0 ( conceptually a LOW) is stored in state.

Important

In Arduino, we read inputs.

Check the Arduino Docs for this topic

Code Sample

int buttonPIN = 12;
int state = 0;

void setup() {
  pinMode( buttonPIN, INPUT ); 
  Serial.begin(9600);
}
void loop() {
  state = digitalRead( buttonPIN ); 
  Serial.println(state);
}

Going Further

Some follow up Arduino references:

pinMode

Serial

First Circuit :: Breadboard Edition

In this exploration we are going to take your Alligator Clip Circuit as a starting point and move it onto a breadboard.

Before you Begin

Before you start his build you should have completed the Alligator Clip Circuit — and all associated Building Blocks. You should also review the Breadboard Building Block.

Breadboard Logic

Let’s quickly review the inner workings of breadboards (complete the Breadboard Building Block if you need more details). The surface of the breadboard is covered in small holes called tie points. These holes accept wires and component legs allowing quick, temporary and stable connections among parts.

It is vital that you memorize the internal pattern of connections of your breadboards.

Bread board and its internal connections.  Front and Back views of a BB.

Power Rails ( Busses )

Power rails run full width, top and bottom. They are labelled with blue and red silk screen. These labels indicate power connections. By convention RED rails get connected to the POSITIVE side of your battery pack or power supply and blue rails receive GROUND connections.

The Great Divide

I like to call the gap in the middle of the board the great divide. It is spaced so that integrated circuits (chips) can be easily fit onto the breadboard. the tie points above and below the great divide are associated with numerous terminal strips.

Terminal Strips (Middle)

The array of tie points in the middle of your breadboard cover rows of terminal strips. The terminal strips are arranged side by side. They do not cross the great divide and they do not connect directly to power rails.

Circuit Representations

During this course I will share circuit representations in several formats.

Schematics

The most reliable of these is the schematic. This representation gives a topological (relational) map of the components in a circuit and how they should be connected. Schematics do NOT described the physical orientation of parts, what sort of wire or conductive material to use, how much of that wire to use, nor where on a breadboard to place your parts. Schematics only describe electrical connections.

Diagrams and Photos

I also use photos and diagrams (the later usually made with software called fritzing). These hold the same basic information as a schematic but also define a specific instantiation of the circuit. These will show specific placement of parts and real world orientations.

circuit representations, photo, diagram,schematic

Lets Build

We are now ready to start building our first circuit :: breadboard edition. This circuit is the hello world of electronics. It is a proof of concept circuit as well as a placeholder circuit — as we will learn later in term.

schematic of LED wit current limiting resistor

Our first circuit is a simple LED with current limiting resistor.

Goal of this build.

Remember, circuits are circles of conductors. The goal of this build is to get your LED glowing on a breadboard.

Parts you will need

  • battery holder — loaded with AA batteries.
  • wire battery clip
  • LED-single color ( red OR green OR blue )
  • fixed resistor (1k — what color bands is that?)
  • resistor chart or worksheet
  • a breadboard

Video :: First Circuit Breadboard Edition

Get the slides

Is it Glowing ? Celebrate!

Take a moment to celebrate if you got to this point and your LED is glowing. This may be a happy candy moment — your call. It is a simple circuit but it has a ginormous learning curve. Bask in the light of your little LED and know that it is just the start of big things to come.

Troubleshoot — mine didn’t glow 🙁 — Yet.

If your LED is not yet glowing don’t despair. Most circuits don’t work on the first try. Here are some things to try to test and troubleshoot your circuit.

  • Disconnect your battery
  • Is the battery hot ?
    • feel it and make sure its cool. If its HOT you have a short circuit — a direct path from battery positive (battery clip red wire) to battery ground (clip black wire). FIND the SHORT solve it before you continue. This is not always obvious — and shorts can be dangerous — if you can’t find the error and your battery keeps getting hot — disconnect and reach out for help (see below).
  • Is the battery cool?
    • assuming your battery is cool to touch, you likely just have a misplaced connection on the breadboard OR your LED is in the wrong way.
    • FLIP the LED — remember LEDs have polarity, and act as gates. Current can only flow through them one way. IF that doesn’t solve it flip it back (make sure flat side, short leg faces ground).
    • If LED is right, this is next big point of error — Check that the LED and resistor legs that are supposed to connect are in the same terminal strip. And that they are on the same side of the great divide. They should be side by side in one short row.
    • check your battery pack did you put each battery in properly? Make sure each battery is alternating direction with the +ve on each battery aligned with +ve in the holder? Check the battery clip — is it securely connected and seated (did you hear it ‘snap’ on). Check the wire ends of your battery clip — are they frayed? Do they insert easily? Try the other clip in your kit.
  • Still not Working?!
    • Double check the whole circuit — Start at red wire on your battery clip, make sure it is connected to a red rail on your breadboard.
    • Check that the long leg of the LED is in the RED rail and is seated well.
    • Confirm that the short leg of the LED is securely placed in a tie point.
    • Confirm that the first resistor leg is on the same terminal strip as the short LED leg. (Resistors do NOT have polarity so flipping it won’t change anything — but good idea).
    • Confirm that the second resistor leg in securely connected to the ground rail on your breadboard.
    • Confirm that the ground wire is connect to the same rail as the resistor leg.
  • Really, still not working … ok, let’s change some parts.
    • try a different LED there is a slim chance the one you have is broken.
    • try a different breadboard — sometimes these just don’t hold wires right. If this fixes it — throw the first breadboard out.
    • try your other battery holder — move all the batteries to the other holder try again. Keep the first one it may have just been improperly loaded.
  • Still? #$%^@$%! I feel your frustration
    • eat one of the candies in your kit (its time).
    • reach out — ask a friend, hit discord, go to the virtual makerspace, email steve

Code of Conduct

tangible is a community of learners. One of our core beliefs is that everyone has something to share. Comments and forums provide one channel for engagement and dialog. Your actions must meet our basic expectations outlined below.

0. Kindness: Be kind to everyone and treat them as they want to be treated. Virtual space is not an excuse to be a jerk. EVER. Online spaces still have real world consequences (outlined in school policies).

1. Inclusion: Be committed to decolonization and antiracist practice. Be open to listening & learning.

2. Boundaries: Respect the boundaries of everyone in the comment sections of this site.

3. Take care: Get outdoors, drink water – 8 cups, sleep – 8 hours. It makes everything tangible so much better.

4. Feedback: When offering critical feedback, do so with the belief that people are here to learn; when receiving critical feedback, listen to others with a willingness to learn.

5. Support: Do your best to support each other — think about what you are saying BEFORE you post.

First Circuit :: Alligator Edition

In this Exploration you are going to make your first simple circuit. The goal is to make an LED glow.

Some of you are going to shoot straight to the video and get building. IF that’s your tactic — make sure you also come back and complete the Building Blocks listed below, if you have not already done so.

Before you begin

Before you start this build you should have reviewed the following Building Blocks:

I suspect some of you will just dive right in — if that’s your plan, make sure you come back and review the info above — it will really help you to understanding this build — and all that follow.

Parts you will need

  • battery holder
  • 6 ‘AA’ batteries
  • wire battery clip
  • LED-single color — your choice, Red or Green or Yellow.
  • fixed resistors – 1kΩ ( what are the color bands ) ?
  • alligator clips

Video :: First Circuit – Alligator Edition

Troubleshooting :: I didn’t glow 🙁 YET)

Some ( ok, a lot, or most, maybe all ) of the time, circuits just don’t work on your first try. This is not a give up moment — this is a check your work moment!

The single biggest skill you will need to master in the world of tangible making is troubleshooting. Circuits fails are not because I have evilly planned to give you something dysfunctional (tho we may do that together live) — but because electronics is often an all or nothing event — either you build it right, or you don’t. When you are starting out lots of things can go wrong. That is OK. Check the video below to see how you can solve your circuit and get your glow on.

The take away — tenacity matters.

Still stuck ? Reach-out — hit discord, come to hackNight, ask in class.

Going Further

Reflect: Which side of your LED faced ground when it successfully glowed?

Did you try all the LED colors in your kit?

Can you make a version of this that uses ALL of your alligator clips to make a giant circuit-hoop?