Friday, May 2, 2014

Circuit #8 Single Servo Notes

Goal: Sweep a servo back and forth through its full range of motion.

Servo - Servomotor, a motor that includes feedback circuitry that allows it to be commanded to move to specific positions

#include<Servo.h> - Servo library. *This library disables PWM on pins 9 and 10!*

Servo servo1 - Servo control object

servo1.attach(pin) - Attach tells the Arduino to begin sending control signals to the servo. Servos require a continuous stream of control signals, even if you are not currently moving them.

servo.detach(pin) - Detaches servo. Servos cannot turn a full 360 degrees, but they can move between o degrees and 180 degrees.

servo1.write(degrees) - Tells the servo to move some number of "degrees."

Sources:
Vilros Ultimate Starter Kit Tutorial Sketches 1-12

Friday, April 18, 2014

Circuit #7 Temperature Sensor Notes

Goal: Use the "serial monitor" window to read a temperature sensor.

TMP36 - Temperature sensor that outputs a voltage that is proportional to the ambient temperature.

Serial.begin(baud rate) -Initialize Arduino's serial port and set communications speed. Speed is measured in bits per second, aka baud rate. 9600 transfers ~10 characters per second

float - Floating point variable. Can handle fractional numbers.

Serial.print("text") - Prints "text"

Serial.print(variable) - Prints variable value

Serial.println( ) - Print prints text to the same line and println inserts a carriage return.

Challenge: Make a thermostat
Solution: Connect a potentiometer between circuit and A0.
Connect j6 through the bottom pin of the potentiometer (e22). Connect top pin of the pot to "+." Connect middle pin of the pot to A0.
No change to Sketch needed.

Challenge: Turn on/off an LED if the temperature is above or below a value
Solution: Left the potentiometer in to better control the temperature. Attached an LED and 330 Ohm resistor between GND and pin 9.
Additional code added to the Sketch.

Sources:
Vilros Ultimate Starter Kit Tutorial Sketches 1-12

Thursday, April 17, 2014

Circuit #6 Photo Resistor Notes

Goal: Use a photo resistor (light sensor) to control the brightness of an LED.

PWM - Pulse Width Modulation. The Arduino uses PWM to fake an output analog voltage. It does this by blinking a pin on and off as fast as 1000 times per second. PWM goes one step further by varying the amount of time that the blinking pin spends HIGH vs. LOW. If mainly HIGH, LED appears bright. If mainly LOW, LED appears dim.

map( ) - Will change one range of values into another range. If we tell map( ) our "from" range is 0-1023, and our "to" range is 0-255, map( ) will squeeze the larger range into the smaller range. ie. lightLevel = map(lightLevel, 0, 1023, 0, 255);

constrain( ) - map( ) could still return numbers outside the "to" range (if they're outside the "from" range), so constrain( ) will "clip" the numbers into a given range. If above the range, resets the highest number to the highest number in the range. If below the range, resets the lowest number to the lowest number in the range. If in range, stays in range. ie. lightLevel = constrain(lightLevel, 0, 255);

analogWrite( ) - Writes an analog value (PWM wave) to a pin. Can be used to light an LED at varying brightness or to drive a motor at various speeds. After a call to analogWrite( ), the pin will generate a steady square wave of the specified duty cycle until the next call to analogWrite( ) (or a call to digitalWrite( ) or digitalRead( ) on the same pin).
Frequency of PWM: ~490 Hz.
On the Uno, pins 5 and 6 have frequency ~980 Hz.
You do not need to call pinMode( ) to set the pin as an output before calling analogWrite( ).
analogWrite( ) has nothing to do with the analog pins or analogRead.
analogWrite(pin, value)

  • pin - Pin to write to 
  • value - Duty cycle between 0 (always off) and 255 (always on)

analogRead( ) - Reads the value from the specified analog pin. The Arduino board contains a 6 channel, 10 bit analog to digital converter. This means it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. This yields a resolution between readings of 5 volts/1024 units, or 0.0049 volts (4.9 mV) per unit. The input range and resolution can be changed using analogReference( ). It takes about 100 microseconds (0.0001 s) to read an analog input, so the max reading rate is about 10000 times per second.
analogRead(pin)

  • pin - Number of the analog input to read from
  • Returns - int(0 to 1023) 


Sources:
Vilros Ultimate Starter Kit Tutorial Sketches 1-12

Circuit #5 Push Buttons Notes

Goal: Use push buttons for digital input

Floating - When the digital pin is disconnected from everything. Is the pin HIGH or LOW? Hard to say because there's no solid connection to either 5 volts or ground. The pin can be read as either one.

Pullup resistor - To deal with the above issue, connect a small resistor (10k Ohm) between the pin and 5 volts. This ensures the pin will have a weak connection to 5 volts and will be read as HIGH.

Sources:
Vilros Ultimate Starter Kit Tutorial Sketches 1-12

Wednesday, April 16, 2014

Circuit #4 Multiple LEDs Notes

Goal: Make eight LEDs dance. Dance LEDs, dance!

Array - An array lets you store a group of variables and refer to them by their position, or "index." ie. int ledPins[ ] = {2,3,4,5,6,7,8,9}; 2 = index 0, 9 = index 7

random(#) - Generates a random number between 0 and (# - 1).

Sources:
Vilros Ultimate Starter Kit Tutorial Sketches 1-12

Circuit #3 RGB LED Notes

Goal: Make an RGB LED display a rainbow of colors.

const - "Constant" variable that will never change. Placed in front of variable declarations. ie. const int RED_PIN = 9

for( ) - Has three statements

  1. Something to do before starting
  2. A test to perform; as long as it is true, it will keep looping
  3. Something to do after each loop, usually increase a variable
RGB base numbers:
  • 0 = pure red
  • 255 = pure green
  • 511 = pure blue
  • 767 = pure red
Sources:
Vilros Ultimate Starter Kit Tutorial Sketches 1-12

Circuit #2 Potentiometer Notes

Goal: Measure the position of a potentiometer and use it to control the blink rate of an LED. Turn the knob to make it blink faster or slower!

Serial.print("text") -- Control knob that changes resistance as it is turned. By using it as a "voltage divider," the Arduino can sense the position of the knob and use that to control whatever you want (ie. the blink rate of an LED). A potentiometer is a three terminal resistor with an adjustable voltage divider. A voltage divider, or potential divider, is a linear circuit that produces an output voltage (Vout) that is a fraction of its input voltage (Vin). If only two terminals of the potentiometer are used, one end and the wiper, it acts as a variable resistor or a rheostat. Potentiometers have three pins. When using as a voltage divider, connect the outside pins to ground and power. The middle pin will be the signal (a voltage which varies from 0 volts to 5 volts depending on the position of the knob).

Function - A named block of code that performs a specified function

Variable - A named number. Often used to store numbers that change. Variables must be declared before they are used. Variables are case sensitive, and if declared outside a function are global variables.

Int - Integer, can range from -32768 to 32767.

Serial.print("text") -(# pin) - The Arduino can read external voltages on the analog input pins using the built in function analogRead( ). this function takes one input value, the analog pin we are using and returns an integer number that ranges from 0 (0 volts) to 1023 (5 volts).

Circuit #2 retrieves a value from the potentiometer from 0 to 1023 (0 to 5 volts). This value is then used as the delay time for the LED blinking.

Sources:
Vilros Ultimate Starter Kit Tutorial Sketches 1-12
http://en.wikipedia.org/wiki/Voltage_divider
http://en.wikipedia.org/wiki/Potentiometer