Let's look at digital and analog pins.
[Intro music]
If you were to turn a light on and off with
a switch, this is similar to a digital signal.
There are two states.
If we were to use a dimmer dial, it would
be similar to an analog signal.
We can chose to turn the circuit on, off,
or any brightness in-between.
To look at how to send and receive digital
and analog signals without having to write
any code, we are going to us a Photon, a phone,
and a multimeter.
The pin layout on my phone matches that of
the Photon.
If we tap on any of the pins, we have a few
options.
All the pins are able to read and write digital
signals.
Instead of using on and off or 0 and 1, we
use a high and low.
In our last video, we said that the Arduino
only reads and writes in voltages.
This means that LOW means 0 volts and HIGH
for the Photon is 3.3 volts.
We connect one side of the multimeter to ground
and the other to pin D0 (digital 0).
If we chose digitalWrite and pick HIGH, you
will see the multimeter gets to about 3.3V.
If we switch it to LOW, it will drop back
down to zero.
This works for any other the pins.
Let’s try this trick with something more
exciting.
If we connect a resistor and LED between pin
D0 and ground, we can turn it on and off.
Now if we change this to pin to analogWrite
we can alter the brightness of the LED as
we slide the values up and down.
The LED needs a certain voltage to turn on
and then we can slowly increase its brightness.
If we hookup, the multimeter again, we can
gradually change the voltage output from this
pin.
To turn something on or off, we use digitalWrite.
For a more granular voltage output, we use
an analogWrite.
We can also get information from our circuits
by using the read option.
Using digitalRead, we look for a zero or 3.3V
coming into a pin, again this is LOW and HIGH.
Let’s hook up a limit switch.
On this diagram, you can see common, which
is ground.
The NC means normally closed.
This is the path electricity normally takes.
The NO, means normally open.
When we hit this button, the piece of metal
inside will be pushed down and the electricity
will flow through the bottom half of the switch.
We hooked the Com to D5, which will read the
voltage value.
We hooked NC to D3, which we will use to send
3.3V into the switch.
When it is hooked up, and we press refresh
on D5, we can see that it reads high, because
it is getting the 3.3V.
When we push the button, we see D5 goes to
low, because the path was diverted to NO.
Now if we hook up D5 to the NO part of the
switch, we can see that it reads LOW when
the button isn’t pressed and it reads HIGH
when the button is pressed.
Using analogRead, we are looking for numbers
in a range.
So we need something that is going to change
its value.
We are going to use a photoresitor, also know
as a LDR . It changes its resistance as the
brightness in the room is altered.
If we just went from the D0, which supplies
3.3V, to the LDR to the analog input, we’d
read the max voltage no matter how much or
how little light we used.
We have to make a voltage divider using a
resistor.
Now we see as the light intensity goes up,
the voltage goes up.
As the light intensity goes down, the voltage
reading goes down.
In the next episode we will discuss why the
values for analog go from 0-255 or 0-4095
and not from 0% to 100%.
We will go over pulse-width modulation, analog
and digital converters, pull-up, and pull-down
resistors.
If you have any comment or questions, you
can talk with us down below or on social media.
You can support us at Patreon.com/SciJoy.
And as always, keep exploring.
