2010年6月10日木曜日

Useful information to understand "tone"

http://web.media.mit.edu/~leah/LilyPad/07_sound_code.html

tone is a commend that enable you to play a sound from buzzer.


LilyPad Arduino



Testing LilyPad Arduino

http://arduino.cc/en/Guide/ArduinoLilyPad






test based on a webpage

http://web.media.mit.edu/~leah/LilyPad/06_rgb.html

instead of using 9,10,11 and 5V pins I use 3,5,6 and 13 pins.

The pins 3,5,6,9,10, and 11 have a function of pwm.

From the test, I conform that the function of pwm is available.



LilyPad + LEDs + Buzzer

I added following cords.

int soundPin=2; 

int frequency;

pinMode(soundPin,OUTPUT);


frequency=random(800,3000);
tone(soundPin, frequency,5000);
delay(100);

I did a test of temp. sensor but I do not know whether temp. sensor works properly or not.


Stand alone lilypad

 




Accelerometer test

instruction

Connect X,Y, and Z of the accelerometer to the analog input 0, 1, and 2 respectively.

Also connect 5V and ground.

int pinX=0;
int pinY=1;
int pinZ=2;
int dataX,dataY,dataZ;

void setup()
{
Serial.begin(9600);
}
void loop()
{
dataX=analogRead(pinX);
dataY=analogRead(pinY);
dataZ=analogRead(pinZ);
Serial.print(dataX);
Serial.print("-");
Serial.print(dataY);
Serial.print("-");
Serial.println(dataZ);

delay(100);
}





Reading

Getting Started with Arduino by Massimo Banzi

I read through the book.

It is about basic electronics and Arduino programings.

I think that the contents of the book were done in a week one and two of the project.

2010年6月9日水曜日

Sensor 04 Photosensor with digital input

This exercise is based on http://www.ladyada.net/learn/sensors/cds.html

 

Since I tried photosensor with analog input,this tutorial going to explain how to build a circuit and program for photosensor with digital input.

The circuit for photosensor with digital input is same as what we made for Boe-Bot.

 We will use Capacitor and measure the pulses that are sent from it with digital pin.

Actually, if we use analog input for photosensor, it is going to be 5 time easier than do a same thing with digital input. Especially, the program will be more complex. However, it is good to learn.

Requirements

Photosensor

Capacitor(I use a capacitor took out from Boe-Bot)

Wires

Arduino

 






Circuit







Program

This program read a interval of signals that send from capacitor as a darkness of the room.

More detail go http://www.ladyada.net/learn/sensors/cds.html

Basically, photosensor is a variable resistor so that changes the amount of electric supply to a capacitor by the darkness, so that interval of the signal from the capacitor will change. 


int photoPin = 2; // declare valiable 
int val;

void setup(void)
{
Serial.begin(9600); // setup serial speed 
}
void loop(void)
{
val = Reading();  // this cord is very similar with GOSUB that we used in Boe-Bot 
 Serial.println(val);//send back data from Arduino
delay(100);
}

//the following cord is similar with "Subroutine"
int Reading()
{

int time=0;
int pin = 2;
pinMode(pin, OUTPUT); //setup pin . This step is important.
digitalWrite(pin, LOW); //set the pin to ground. This step is also important. 
pinMode(pin,INPUT);//set the pin to read a signal 

while (digitalRead(pin)==0)//make a timer 
{
time++;
if(time==30000)//in case nothing is connected 
{
break;//return to "void loop" 
}
}
return time;//return the value to variable "Reading" 
}



2010年6月8日火曜日

Sensor 03 Motion sensor

This tutorial is based on http://www.ladyada.net/learn/sensors/pir.html

In this tutorial enable you to use motion sensor (PIR sensor) in your art work.

I figure out that my room has some problems that causes bad effect for a motion sensor.

Therefore, the program of motion sensor works better in my room but you can change it for your purpose,  such as change the sensibility of the sensor.

Requirements

PIR sensor

LED

wires

Arduino



Circuit






detail of the circuit



Setup jumper in H


Program


The following program is made for my room to use motion sensor. However, this program takes continuous 3 second movements in order to light up LED.

If you have a same trouble same as  me. Try following  program.

/*

This program is designed for my room's situation.

What I did is that I ignore the pulse that send from PIR sensor

if it is less than 3 second continuous pulse(continuous motion).

You can change that section as sensibility of PIR sensor.

*/


int motion=2;

int light =13;
int val,count;

void setup()
{
Serial.begin(9600);
pinMode(motion, INPUT);// for PIR seonsor 
pinMode(light, OUTPUT);// for LED 
}
void loop()
{

val = digitalRead(motion); //get data from pin.

if ( val == 1) //to ignore the noise pulse 
{
count++;//counter for the number of noise pulse 
Serial.println(count);
delay(500); //regulate the frequency of activating sensor
if (count >=6) //threshold for the continuous pulses 
{
digitalWrite(light, HIGH);
delay(300);
Serial.print("the object is moving");
Serial.println(count);// just for check whether the program works properly or not. 
}
}

else//no motion is detected
{
digitalWrite(light, LOW);
delay(10); // If this delay is shorter the sensor react more quicker 
count =0; // reset counter. 
Serial.println("reset");
delay(10);// If this delay is shorter the sensor react more quicker 
}
}