# Electronics 101

With Robert Hart

[Presentation info](https://tourlomousis.pages.cba.mit.edu/fabclass-recitation-electronics/)

* Part numbers are on the lab webpage
* Can plug part # in to digikey, get datasheet PDF

* Capacitors, resistors, phototransistors - we'll be using surface mount versions

* Phototransistors - generates current when illuminated
* 3 lead transistors (FET - n-type field effect transistor)

Mental model: current is the flow of a fluid, voltage is pressure/energy to make it go

Originally "conventional" current flow (Franklin): - electrons flowing + to -. In reality, electrons move - to +.

Current measured in Amperes (A). 1 amp is a lot of current. Old fashioned lightbulbs take 1A, nowadays, 1/10A. LED today draws 10 mA (1/100).

Negative part of battery - 0 (ground). Positive: battery energized flow of current

Resistors resist flow of current. Resistance - ratio of voltage . Current through resistor = voltage drop across resistor / resistance

Power is energy loss per unit time

## Switches

* Pulldown - ground until you hit switch, goes up
* Pullup voltage -> resistor -> digital in -> switch (when you release, current goes to 0). Up until you hit switch, goes ground
* Microcontroller has built in internal pullup

## Other Notes

* Voltage Divider - middle wire has half the voltage
    * Potentiometer (dial) - lead (middle wire) contacts resistor at different places
     
## Diodes

* Let current go in only one direction
* Like a tube with a spring loaded door. Blocks it in reverse direction

Zener diode: breaks down at a certain voltage

SMB Switching diode (looks a lot like resistor)

* Bar is on cathode (negative) side
* Cathode - negative, anode - positive

## Capacitor

* Like a reservoir (battery)
* Filter capacitors on power rails: smooth out signal (glitch removal)

* Low pass filter - resistor (branch) capacitor (off branch) out
- High pass filter - capacitor (branch) resistor (off branch) out

* **Capacitive loading**: capacitors as sensors.
  * charge with a square wave (0-5V). Accumulation of + on one side, - on other side.
  * can detect water between plates - larger spikes. Can detect WHAT'S in between the plates (e.g. a hand, water, "dialetric")

## Transistors

- 3 terminal devices
- *FETs* - field effect transistors
  
- N-MOSFET. Control big current with a tiny current
    - Microcontroller limited in amount of current it can put out
    - Drive gate of transistor using microcontroller (allow 1-2A through load)

## Regulators 

- 3-pin Regulators: change 9V to 3.3v. Look like transistors, just give regulated voltage.

## Inductors

- Like capacitors, but store energy in magnetic field instead of electric
- Use when driving motors (since they're inductive devices)
- You can see spark when opening switch. Spark can actually kill transistors. Use "flyback diode" to shunt voltage back to battery.
    - Important with the MOSFETS we use

## Microcontrollers

[ATtiny45](https://datasheet.octopart.com/ATTINY45-20SU-Atmel-datasheet-41301906.pdf) - 8-pin microcontroller

- Works from 2.7-5.5v
- Attach power (+) to VCC, - to ground
- Digital - yes or no, low/high, 0/1
- Digital inputs can look at 0-5V (0-2.3 low, 2.3-5 high)
- ADC - analog to digital converters (0-5V to 0-1023)
- Pulse-width Modulation (PWM) - convert square-y waveforms.
    - Average it out to get 0/1
    - LEDs - 50hz, eye won't see flickering, dim and brighten
    - or low-pass capacitor filter to get something like analog voltage
    
## Simulator for Circuits

falstad.com/circuit - 

## Later on 

Later we'll talk about motor driving with H-bridges.



