What is an Arduino?
from the Arduino.cc website:
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 and the Arduino development environment.
Arduino projects can be stand-alone or they can communicate with software on running on a computer. The boards can be built by hand or purchased preassembled; the software can be downloaded for free.
First Project
For my first project I looked though what I had available in my kit:
- Arduino Uno SMD w/Atmega328 - The latest and greatest Arduino revision, assembled and ready to go, including 4 rubber feet
- 3' USB cable - Perfect for connecting your Arduino to a computer
- Protoshield Kit - One of ladyada's designs, its got everything you need to make prototype designs using an Arduino. Note that this comes unassembled
- Tiny Breadboard - Fits on top of the protoshield, easy to use
- 9V DC regulated wall adapter - You can power your Arduino from any wall socket. This switching regulator is efficient and small and works with US (110V) and European (220V) power.
- 9V Battery case with switch and a 2.1mm plug- so you can power your arduino using a 9V battery. This case is much sturdier than just a battery clip and it has an on/off switch too! Note that this comes unassembled
- Tutorial starter pack parts - Includes a 10K potentiometer, 1K potentiometer, 2 small pushbuttons, 5 red diffused bright LEDs, one each of red, green and blue ultra-bright LED, 5 100 ohm resistors, 5 1K resistors, 5 10K resistors, and a CdS photocell sensor.
- Also includes 75 flexible breadboard wires in 8 colors, perfect for use with the solderless breadboard.
After playing around with the LCD tutorial and getting simple outputs, I then started playing with the photocell sensor. Simply, a photocell is a resistor (resistors being devices that "resist" the flow of electricity), whose resistance decreases the brighter things get. After playing with the tutorials, i wondered if i could combine the two on my own and customize the output into something more unique. So thats what i did, i wired up the two devices just like in the tutorial.
Then I merged the code and made some modifications based on what I wanted as an output. Here is an example of the code I used.
Basically whats going on is the photocell is giving us a integer value via the analog input on the Arduino board. The Arduino board then looks at that integer and asks a few questions. Is the number less the 5? If yes, print out the the string of text "Dark-" then print the number. If not, is the number less then 20? And so on. Then the program waits one second to clear the screen and then repeats itself.
Im kinda proud of myself on this one. I borrowed some code (the if/else portion) but the rest I did from memory or by looking up the language reference. Since doing this, I've come up with three new projects ideas but i'll explain them in my next post.
http://burntelectonics.blogspot.com/2011/02/getting-started.html
This is what i ended up getting. (note: the picture was taken before the final version of the code was done.)/*
Light Sensor!
Reads Analog data from a light sensor and outputs the data in a form we can understand
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int photocellPin = 0; // the cell and 10K pulldown are connected to analog pin 0
int photocellReading; // the analog reading from the sensor divider
void setup(void) {
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
}
void loop(void) {
lcd.print("It is currently:"); // Prints the defult message to the LCD.
lcd.setCursor(0, 1); // changes cursor position
photocellReading = analogRead(photocellPin); // dumps the analog data into my varable
if (photocellReading < 5) { // start of if else statments to covert the analog intergers to text and output both.
lcd.print("Dark-");
lcd.print(photocellReading);
} else if (photocellReading < 20) {
lcd.print("Dim-");
lcd.print(photocellReading);
} else if (photocellReading < 100) {
lcd.print("Light-");
lcd.print(photocellReading);
} else if (photocellReading < 200) {
lcd.print("Bright-");
lcd.print(photocellReading);
} else {
lcd.print("Very bright-");
lcd.print(photocellReading);
}
delay(1000); // delays 1sec
lcd.clear(); // clears the screen, acting as a refresh
}
Basically whats going on is the photocell is giving us a integer value via the analog input on the Arduino board. The Arduino board then looks at that integer and asks a few questions. Is the number less the 5? If yes, print out the the string of text "Dark-" then print the number. If not, is the number less then 20? And so on. Then the program waits one second to clear the screen and then repeats itself.
Im kinda proud of myself on this one. I borrowed some code (the if/else portion) but the rest I did from memory or by looking up the language reference. Since doing this, I've come up with three new projects ideas but i'll explain them in my next post.
http://burntelectonics.blogspot.com/2011/02/getting-started.html
No comments:
Post a Comment