-
Notifications
You must be signed in to change notification settings - Fork 0
Notes
Note
On Blog docs: Use videos to show interactive parts!! Don't say "then the light blinked" and not show the light blinking :(
Arduino sketches have two main functions: setup() and loop().
-
setup(): runs once at the start of the program. -
loop(): runs continuously oncesetup()has finished.
- Are one of two states,
HIGHorLOW! - Can act as inputs or outputs using the
pinMode()function.
Tip
Pins can be set to input or output mode using the pinMode() function.
pinMode(13, OUTPUT) tells the Arduino to use pin 13 as an output.
Digital output pins can be set using the digitalWrite() function.
digitalWrite(13, HIGH) tell the Arduino to turn pin 13 on.
Digital input pins can be read using the digitalRead() function.
digitalRead(13) reads whether pin 13 is HIGH or LOW.
Tip
Programs can be temporarily stopped using the delay() function.
delay(250) will stop the program for 250ms or one quarter-second.
Resistors use bands to show resistance. Each color corresponds to a number:
| color | number |
|---|---|
| Black | 0 |
| Brown | 1 |
| Red | 2 |
| Orange | 3 |
| Yellow | 4 |
| Green | 5 |
| Blue | 6 |
| Purple | 7 |
| Grey | 8 |
| White | 9 |
The first band is the first digit, the second band is the second digit, in a five-band resistor the third band is the third digit.
The second-last band is the multiplier (×10 ^ value).
The last band denotes tolerance:
| color | tolerance |
|---|---|
| brown | ± 1% |
| red | ± 2% |
| gold | ± 5% |
| silver | ± 10% |
Tip
Resistors are not polarized. You can place them in any direction.
Week 4 is all about sound!
To create sound, we can fake analog output again with pulse width modulation. However, instead of changing the duty-cycle to fake less voltage, we'll change the period to fake frequency!
Tip
We can play audio tones using the tone() function.
tone(9, 440, 500) tells the Arduino to play a 440 hz tone on pin 9 for 500 ms.
We can stop audio tones using the noTone() function.
noTone() tells the Arduino to stop playing a tone, if one is playing.
But the Arduino can't make noise by itself..
A piezo (or piezoelectric speaker) uses the piezoelectric effect to create audible tones. Some piezos are polarized, but not all. Piezos can also be used in reverse, to detect sound/vibration rather than produce it.
So far, we've been using delay() to control time. However, this pauses execution, which isn't always what we want. We can use a different function millis() to get the time since the program began without stopping execution.
Caution
millis() will overflow back to zero after about 50 days.
Tilt switches help determine the orientation of something. Accelerometers are a type of tilt sensor that gives out much more information. If you just want to know if something is up or down, a tilt switch works great!
Motors spin when the electrical energy is converted into a magnetic field. This magnetic field causes the motor to turn. However, in the same way, motors can also be used to convert motion back into electrical energy. Moving things takes a lot of energy, so a 9V battery is a must! Motors have an optimal operating voltage and will work from -50% to +50% of that voltage.
A transistor is an electronic switch. It's like a lever or a button but it uses an electrical signal to open and close the switch instead of a physical action. Transistors have a source, a gate, and a drain. The source is the source of power from the arduino, the gate controls if it gets through or not, and the drain is where the power flows out to the motor or other component.
Warning
When you stop powering a motor, it will continue to spin to a stop. This spinning will generate power that feeds back into the arduino. We can use a diode to prevent energy from traveling back through.
Week 6 is all about integrated circuits!
Integrated circuits are small compact circuits that are mass-produced so you don't have to create your own huge breadboard circuits. With integrated circuits we can create more complicated projects! Integrated circuits are like the electrical version of programming libraries. This week we'll be using H-bridges in LCD displays.
Logic chips are the simplest ICs. They represent logic gates, buffers, counters, latches, and other functions.
The first IC that we will use is a H-bridge. An H-bridge allows you to control the polarity of the voltage applied.
Tip
We could construct an H-bridge using discrete components, but it would probably take an entire second breadboard!
Tip
When in doubt about how to hook up an IC, always consult the spec sheet!
When the crystals are angled the right way, light can pass through. The special crystals are polarized such that when electricity is applied, they orient one way or the other.
Tip
LCD displays have a lot of pins for many different uses, but not all of them are necessary. Always consult the spec sheet to see what abilities you need for your project.
Warning
A schematic may group the IC pins by what they do, rather than ordering them as they appear on the real IC. Always make sure you're really connecting each pin to the right LCD pins!
Tip
We can use the LiquidCrystal library to avoid having to get too in the weeds with the commands!