Digital

"Arduino boards contain a multichannel, 10-bit analog to digital converter."

So, what happens when we put a voltage across two pins of the arduino?

What's a bit?

The bits of Morse Code

Magentic Domains as bits

"Arduino boards contain a multichannel, 10-bit analog to digital converter."

Digital Ramp ADC

This device generates a reference signal (in a step-like fashion). When it equals the input, it registers the digital value.

Arduino board have a similar method known as Successive Approximation ADC

What we measure

We're measuring bits.

Digital Output

The Duty Cycle

Instead of making a range of voltages, the digital output works by changing how often 5 V is sent to the output. This is called the duty cycle.

sim

On the board

The Two Sides of the board

Arduino Codes


// set up the pins

// our digital PWN output is set to Digital Out 9
const int outPin = 9;

// we start with an output of 0 and declare this variable as an integer
int outputLevel=0;
 
void setup() {

  //define the pin mode for the digital output
  pinMode(outPin, OUTPUT);
  
  Serial.begin(9600);
}


void loop() {

  // make an oscillating value 
  // output = Sin(omega * t)
  
  float omega = 2*3.1415;
  outputLevel = 255*sq(sin(millis()*.001*omega));

  // write the outputLevel variable to our digital output pin
  analogWrite(outPin, outputLevel);

  delay(1);
}

    

The Duty Cycle

LED

Connecting an LED

LED: Light Emitting Diode

Warning: One leg is longer - that goes to the positive voltage

Use a resistor in series to make sure not too much current passes. (220 Ω is fine)

Power

If current passes through a resistor, there will some energy dissipation.

\begin{equation} P = I V = I^2 R \end{equation}

Make a heater!

We will use the digital output to send a current to a resister, and then use our thermistor module to measure that change in temperature of the resistor.

To do:

  1. Make a temperature controller. This will be a potentiometer (essentially a voltage divider)
  2. Get the value from the controller and use that to set the heater level.
  3. Connect the resistor to a digital out.
  4. Measure the temperature with a thermistor (and voltage divider)

Arduino Specific

Connecting an LED


/* LED BRIGHTNESS CONTROL */

// our potentiometer will go to Analog Input 1
const int PotInputPin = A1;

// our digital PWN output is set to Digital Out 9
const int outPin = 9;

// we start with an output of 0 and declare this variable as an integer
int outputLevel=0;
    
void setup() {
    //define the pin mode for the digital output
    pinMode(outPin, OUTPUT);
}

void loop() {
    int potValue = analogRead(A1);

    // use the map() function to scale the potentiometer input from 0-1023 to 0-255
    outputLevel = map(potValue,0,1023,0,255);

    // write the outputLevel variable to our digital output pin
    analogWrite(outPin, outputLevel);

    delay(1);
}