Wednesday, June 17, 2009

Arduino Projects

To check out some other project some classmates did using an arduino board check out our wiki page: http://damm-net.org/wiki/index.php?title=SS09:Arduino_Workshop_Projekte
There is also great information and links to helpful software, hardware suppliers, and script to encourage more fiddling around with the arduino board.

Tuesday, May 26, 2009

Distance Sensing LED Wall Sculpture Art Project


Distance Sensing LED Wall Sculpture Art Project
Using Sonar Range Finder Sensor and BlinkM’s with an Arduino



The idea behind this project is to create something that is not only using technology, but also works as an interesting piece of wall art.

Supplies:
Wire: red, black, yellow, white (you’re going to need approx. 12 feet of wire)
1 LED
8 BlinkM’s
1 LV-MaxSonar®-EZ0™ High Performance Sonar Range Finder
2 512 Resistors
Bread Board
Arduino
Balsa Wood of assorted thicknesses
Vellum: 4 sheets of a heavy weight so it is durable
Hot Glue Gun
Tape: electrical, masking

Before you begin:
Download the data sheets for the BlinkM and the Sonic Sonar
Download BlinkM_funcs.h file and add it to the Arduino Library to be called in the script later.

Building the Light fixture:
What I did was soaked the balsa wood in hot water for an hour in the bathtub so it became flexible.
Then I took the balsa wood and formed curves and what not on wine bottles and other circular objects, taping it down with masking tape. And let it dry.
Then I glued the wood together using a hot glue gun.
Made a stencil of one of the wine bottles and cut the vellum to match. Hot glued the vellum to the wood and then the light fixture is set. You can check on flicker to see the steps I took to build the lamps.
Programming the Devices
1. Test the Ultra Sonic Sensor. Connect the TX and RX, Ground, 5V and Analog 0 to the Sensor. Plug an LED into Pin 13.
a. Run this script to see the digital read of the sensor to make sure its running.
/*MaxBotix1simple
ver 29 Mar 08
http://sheepdogguides.com/arduino/aht1a.htm
================*/
#define anIn 0
#define LEDpin 13
int iAnVal;

void setup() {
Serial.begin(9600);//See note at the Serial.write line.
pinMode(LEDpin, OUTPUT); // prepare the pin "LEDpin" for output
} //end of setup

void loop() {
iAnVal = analogRead(anIn); // read a value from the sensor
delay(150);
Serial.println(iAnVal);
digitalWrite(LEDpin,HIGH);
delay(150);
digitalWrite(LEDpin,LOW);

}



2. Set up the BlinkM’s each one needs to be named. See BlinkM datasheet for how to connect a BlinkM to an Arduino board. Since BlinkM is an 12C slave, for more information on controlling 12C devices read this: http://www.best-microcontroller-projects.com/i2c-tutorial.html It’s important to understand this because we are going to be running multiple BlinkM on the same bus, this allows each one to have its own identity so we can program them individually.

3. Since the Default name is 09, I named my blinkM’s in sets of 2 from 10 to 13.
Here is the code to name 1 Blink M:
void setup()
{
if( BLINKM_ARDUINO_POWERED )
BlinkM_beginWithPower();
else
BlinkM_begin();
delay(100); // wait a bit for things to stabilize
byte newAddress = 0x09; // change one by one
BlinkM_setAddress(newAddress);
Serial.begin(19200);
help();
byte addr = BlinkM_getAddress(blinkm_addr)
if( addr != blinkm_addr ) {
if( addr == -1 )
Serial.println(“\r\nerror: no response”);
else if( addr != blinkm_addr ) {
Serial.print(“\r\nerror: addr mismatch, addr received: “);
Serial.println(addr, HEX);
}
printProgStr( badAddrStr );
}
Serial.print(“cmd>”);
}
4. So, set up your numbered BlinkM’s, plug them all in now.
5. And this is the point where you open up the code and try it for yourself.


4. So in the BlinkM data sheet there are a list of preprogrammed light scripts, for this project we will use a few of these to save some time, and they look really good them selves. So, set up your numbered BlinkM’s, plug them all in now.
5. And this is the point where you open up the code and try it for yourself.


#define anIn 0 //input for the sensor
#define LEDpin 13 //loop check led

#define Thresh0 30 //(no ; here)
#define Thresh1 70 //(no ; here)
#define Thresh2 100 //(no ; here)
#define Thresh3 150 //(no ; here)

#include "Wire.h"
#include "BlinkM_funcs.h" //BlinkM function document

#include // for progmem stuff

#define BLINKM_ARDUINO_POWERED 1

byte blinkm_addr = 0x09; // the default address of all BlinkMs

char serInStr[30]; // array that will hold the serial input string

const char helpstr[] PROGMEM =
"\nBlinkMTester!\n"
"'c' fade to an rgb color\n"
"'h' fade to an hsb color\n"
"'C' fade to a random rgb color\n"
"'H' fade to a random hsb color\n"
"'p' play a script\n"
"'o' stop a script\n"
"'f' change fade speed\n"
"'t' set time adj\n"
"'g' get current color\n"
"'a' get I2C address\n"
"'A' set I2C address\n"
"'B' set startup params to default\n"
"'Z' get BlinkM version\n"
"'i' get input values\n"
"'?' for this help msg\n"
;
const char badAddrStr[] PROGMEM =
"BlinkM not at expected address. Reset address with 'A' command\n";

// Sometimes we can't use the obvious Serial.println(str) because
// the string is PROGMEM and Serial doesn't know how to deal with that
void printProgStr(const prog_char str[])
{
char c;
if(!str) return;
while((c = pgm_read_byte(str++)))
Serial.print(c,BYTE);
}

void help()
{
printProgStr( helpstr );
}

int iAnVal;

void setup() {
if( BLINKM_ARDUINO_POWERED )
BlinkM_beginWithPower();
else
BlinkM_begin();

delay(100); // wait a bit for things to stabilize

Serial.begin(19200);

help();


} //end of setup

void loop() {
iAnVal = analogRead(anIn); // read a value from the sensor

if (iAnVal{
BlinkM_playScript(0x10, 2,0,0 ); // command for set 10
}
else {
BlinkM_playScript(0x10, 13,0,0 );
};

if (iAnValBlinkM_playScript(0x11, 12,0,0 ); // command for set 11
}
else {
BlinkM_playScript(0x11, 13,0,0 );
}

if (iAnValBlinkM_playScript(0x12, 11,0,0 ); // command for set 12
}
else {
BlinkM_playScript(0x12, 13,0,0 );
}

if (iAnValBlinkM_playScript(0x13, 12,0,0 ); //command for set 13
}
else {
BlinkM_playScript(0x13, 13,0,0 );
}

delay(150); /* Stop the program for a moment.*/

Serial.println(iAnVal); //shows distance

}

Hope this works for you, feel free to tweak it as you want!
Best of luck!