Welcome
This class is a two-session immersive introduction to digital electronics using the Arduino platform.
We'll learn how to use this microprocessor board to read digital and analog inputs, interface it to some sensors, and to high-current actuators like motors and relays (using transistors).
What is Arduino?
Installation Instructions
arduino.cc/en/Guide/HomePage - click Mac OS X, Windows or Linux..
A Few Important Concepts
The terms we'll most often use in talking about electronics and electricity are Current (I), Voltage (V) and Resistance (R). Current is the flow of electrons through the wire of an electronic circuit. Voltage is the force that causes electrons to move and create current and Resistance is something that opposes the flow of current through a circuit.
Water analogy is helpful in understanding these concepts. The height of the water in a tank can be thought of as Voltage. The flow of water through the tube is Current. The crank that controls the flow is like a Resistor.

Fundamental law of electricity (Ohm's law) is that the Current is directly proportional to the applied Voltage:
V = IR
Basic Electronic Parts
Resistor is an electronic component designed to oppose an electric current. We can buy them with preset resistance
(Ohm) values indicated by colored stripes.

LED (light-emitting diode) is an electronic part that produces light. We can change the LED brightness by
setting the current that flows through it using a Resistor, according to Ohm's law.

Breadboard
Solderless, reusable prototyping board for assembling electronic circuits. Use holes within one column to connect
parts together. Top and bottom rows are interconnected across the whole board and used for Power and Ground.

The First Program
In Arduino environment, open File > Sketchbook > Examples > Digital > Blink
int ledPin = 13; // LED connected to digital pin 13
void setup() // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop() // run over and over again
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
}
Digital Input
We can use a Button or Switch as digital inputs to the microprocessor.

int ledPin = 13; // LED connected to digital pin 13
int inputPin = 2; // connect digital inputs to this pin
int val;
void setup() // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
pinMode(ledPin, INPUT); // sets the digital pin as input
}
void loop() // run over and over again
{
val = digitalRead(inputPin);
if(val == 1)
digitalWrite(ledPin, HIGH);
else
digitalWrite(ledPin, LOW);
delay(1000);
}
Analog Input
We'll use a Potentiometer as an input to our program.
Potentiometer is simply an adjustable Resistor. This is a part you can find behind a knob on your stereo. Instead of changing the volume of sound, we'll use it to change the brightness of an LED.

int ledPin = 13; // LED connected to digital pin 13
int inputPin = 2; // connect analog inputs to this pin
int val;
void setup() // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop() // run over and over again
{
val = analogRead(inputPin);
digitalWrite(ledPin, HIGH);
delay(val/50);
digitalWrite(ledPin, LOW);
delay((1023-val)/50);
}
Communication
Let's get our microprocessor talking to the computer. We'll transmit the analog value of the potentiometer to the Arduino environment over USB.
int ledPin = 13; // LED connected to digital pin 13
int inputPin = 2; // connect analog inputs to this pin
int val;
void setup() // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
Serial.begin(9600); // establish serial communication at 9600 baud
}
void loop() // run over and over again
{
val = analogRead(inputPin);
digitalWrite(ledPin, HIGH);
delay(val/50);
digitalWrite(ledPin, LOW);
delay((1023-val)/50);
Serial.println(val); // print val to serial
delay(1000);
}
Sensors
There are many sensor that behave just like variable resistors. For example, photo-resistor (aka cadmium sulfide or CdS cell) is a sensor that changes resistance based on the amount of light that hits it.
Using a photo-resistor to create analog voltage input (by making a voltage divider):

Thermistor is a sensor that varies resistance with a change in temperature. We need a relatively large temperature change to see the difference.

Flex Sensor changes its resistance by bending. This is the sensor that was apparently used in the original Nintendo Power Glove.

Some complicated sensors are designed to produce analog voltage as an output, making them easy to interface to Arduino. For example, some infra-red (IR) sensors produce a voltage level proportional to distance to an object in front of the sensor.

Transistors
So far we've discussed electronic components that can be directly manipulated by microcontroller's pins. Each digital output pin on the Arduino can provide about 25mA of current. This is enough to light an LED, but to control something that requires more current (e.g. motor), we can use a Transistor.

Transistors are devices that amplify electronic signals. There are two standard types, NPN and PNP. Transistors have three leads, base (B), collector (C) and emitter (E). The rule is that small base current in a transistor controls a larger collector current.
Relays
To control AC circuits using the Arduino, we use a transistor and a part called Relay, which is an electrical switch operated by an electromagnet.


Putting it all together
Let's design a circuit that uses a sensor as an input and a standard electric bulb as an output.

www.allelectronics.com - local surplus resource!
www.digikey.com - huge electronics distributor, quick USPS shipping to LA
www.mouser.com - another fat electronics catalog, sometimes better prices than above
www.jameco.com - big selection somewhat focused on discounted pricing
www.goldmine-elec-products.com - pretty wide range of surplus components
www.sparkfun.com - great resource for certain parts, sensors and custom PCBs