Showing posts with label Electronics. Show all posts
Showing posts with label Electronics. Show all posts

Friday, October 2, 2009

Arduino 2: Buttons, Switches, and The Pull-Down Resistor

Last post, we had a blinking LED responding to a connection between two pins on the Arduino board. Of course, something that connects or disconnects a part of a circuit is a switch, and this is what we used. As in last week's lab, we have a resistor and a 150ohm resistor connected between pin 10 and ground. This time, we used a breadboard like this to make our circuit:


The circuit also had a switch from the +5v supply to a SPST (single pole, single throw) microswitch, the other side was connected to a 10k pull-down resistor, to avoid the problem of the flip-flopping voltage we had last time, and this was connected to both pin 5 and ground, thus keeping it at digital 0. We used the same code as last time, so here are some photos of the board taken in the lab.




Once it was connected, the code uploaded, and the board initialised, the program worked as expected, once the button was pushed, the LED began to flash.

Arduino Part 1... Blinking LEDs!



An introduction from the homepage, Arduino.cc:

"Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments.

Arduino can sense the environment by receiving input from a variety of sensors and can affect its surroundings by controlling lights, motors, and other actuators. The microcontroller on the board is programmed using the Arduino programming language (based on Wiring) and the Arduino development environment (based on Processing). Arduino projects can be stand-alone or they can communicate with software on running on a computer (e.g. Flash, Processing, MaxMSP)"

Affordances

The Arduino we use has six 10bit analogue inputs, 14 configurable digital pins, which can act as inputs or outputs; pins 0 and 1 are reserved for serial communication, pins 2 - 13 can be configured for digital in/out, and pins 9 -11 can be configured as a psuedo-analogue output, which is capable of PWM (Pulse Width Modulation).

The first exercise was to make an LED blink, and then make it blink using different code and a different circuit layout, using the Arduino to test if a connection was made between two pins on the board. Here is the idea, again from the the page http://arduino.cc/en/Tutorial/Blink

Blink

"In most programming languages, the first program you write prints "hello world" to the screen. Since an Arduino board doesn't have a screen, we blink an LED instead.

The boards are designed to make it easy to blink an LED using digital pin 13. Some (like the Diecimila and LilyPad) have the LED built-in to the board. On most others (like the Mini and BT), there is a 1 KB resistor on the pin, allowing you to connect an LED directly. (To connect an LED to another digital pin, you should use an external resistor.)

LEDs have polarity, which means they will only light up if you orient the legs properly. The long leg is typically positive, and should connect to pin 13. The short leg connects to GND; the bulb of the LED will also typically have a flat edge on this side. If the LED doesn't light up, trying reversing the legs (you won't hurt the LED if you plug it in backwards for a short period of time). "

The code I used for this looks like this:

void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}

This was then uploaded to the board using the Arduino IDE software. The LED was placed between Pin 13 9which has the required resistor built in, so as o avoid burning out the LED) and ground, and after 8 seconds, it began to blink.
The code is in two parts, the initial 'void setup()' section, which declares constants, and the 'void loop()' which runs over and over until the unit is stopped.

The second exercise used different pins, namely 5 and 10, and a wire was connected to the +5v on the board, and could be connected to pin 5. The LED was this time connected to pin 10, with a 150ohm resistor in front of it to prevent overload.
The second method's code was thus:

void setup()
{
pinMode(10, OUTPUT);
pinMode(5, INPUT);

}

void loop()
{
int state = 0;
state = digitalRead(5);

if (state == 1)
{
digitalWrite(10, HIGH);
}

else{
digitalWrite(10, LOW);
}
}
The loop here means that if pin 5 recieves a 1 (i.e., 5v) the output at ten will be high, and the LED will come on. The issue here is that, with the wire on pin 5 not connected to anything, it's state will wander randomly between 0 and 1, which is undesirable. Next post describes how to make this circuit in a more practical and correct fashion, using a switch....
And so, we have an Arduino working! Quite exciting!

Thursday, October 1, 2009

Analogue Electronics 102: Potential Dividers And Sensors

Voltage Drop Across A Resistor, The Potential Divider

Consider these circuits:




Quite simply, what is happening here is that the resistors are dividing the voltage (or potential). For an more indepth look, see:
http://www.electronics2000.co.uk/data/itemsmr/potdiv.php

This is a useful phenomenon, especially when we know that resistors do not have to have a fixed value. These are called Variable Resistors, and have many shapes and forms. These are the symbols used:

These are what some of them look like:


Variable resistors may be actuated by a movement of part of the device, like the knob on a radio, or the fader on a mixer, or by light, temperature, pressure, bending, etc. These latter forms are used as sensors,but we will return to these devices shortly.
Using a variable resistor of some kind, the potential divider circuit can convert a varying resistance into a varying voltage. This is a very useful control mechanism, as we shall see when we get to the discussion on the Arduino.
Sensors

Light Dependent Resistors

The resistance of an L.D.R. changes in response to the amount of light falling on it, where the less light recieved, the higher the resistance. This is what they look like:


Thermistors
The resistance of a thermistor changes proportionally to the temperature of the device. There are two forms, NTC and PTC, where NTC thermistors' resistance decreases proportionally with increases in temperature, while PTC thermistors' resistance increases proportionally with increases in temperature


Force Sensing Resistors:
These are a type of resistor whose resistance changes when a force or pressure is applied. The resistance is inversely proprotional to the force applied, i.e. the resistance decreases as the force gets increases.


Flexion /Bend Sensor:
These devices' resistance drops when the component is bent.

Wednesday, September 16, 2009

Analogue Electronics 101

In relation to analogue electronics, we have three initial variables to deal with, namely:
-Voltage
-Current
-Resistance

Voltage is measured in Volts (V) and is measured using a voltmeter. Voltage is also known as Potential Difference (p.d.) Voltage is analogous to pressure in a hydraulic system. A battery is an example of a source of voltage and current. Here is the circuit symbol for a battery, where the longer of the unjoined bars is the positive terminal:


Current is measured in Amperes (A) and is measured using an Ammeter. Current is a measure of the amount of electricity flowing in a circuit, analogous to flow rate of water, i.e., Litres/second.

Resistance is measured in Ohms (omega symbol) and is measured using an ohmmeter. It is a measure of how well a substance or object resists the flow of electricity, analogous to a narrowing in a pipe of water. Resistors may be made from graphite, like pencil lead,or metal film or other compounds. The symbol can be either of these:




Ohm's law
(From http://www.the12volt.com/ohm/ohmslaw.asp)
"Ohm's Law defines the relationships between (P) power, (E) voltage, (I) current, and (R) resistance. One ohm is the resistance value through which one volt will maintain a current of one ampere. "

For our purposes, it is sufficient to know that the voltage of a circuit can be found by multiplying the current by the resistance, giving us:

V = I x R
So, in a circuit with a 5v battery, and a 4000 ohm (4k) resistor, the current will be: V/R = I, 5/4000 = 0.00125A, which is 1.25 mA (milliamps, or one thousandth of an ampere)

There is also a convenient method of remembering the arithmetic of Ohm's law, pictured here:

The variable sought is simply covered, leaving the formula required.
For more examples, go to: http://seattlerobotics.org/guide/electronics.html


Resistors In Series
When one resistor is placed after another in a circuit, their resistances are added, so two 1000 ohm resistors will add to 2000 ohms, i.e., R1 + R2 = Rtotal


http://www.hobby-hour.com/electronics/resistor_color_code.php