ラベル Circuit の投稿を表示しています。 すべての投稿を表示
ラベル Circuit の投稿を表示しています。 すべての投稿を表示

2012年1月29日日曜日

Reference for XBee

The price of XBee Explorer Dongle is too expensive. $24

If you have a FTDI Basic Breakout($14) you can use it as a replacement. You can save $10.



To connect FTDI and XBee for PuTTY.

Connect

GND-GND

3.3V-VCC

TXO-DIN

TRI-DOUT


In the PuTTY terminal

type +++ without ENTER

XBee will return

OK



2010年7月7日水曜日

Transistor switch

Requirement

NPN Transistor( I used 2N3904 bought from Radio Shock )

LEDs

Arduino

Arduino program

wires

1k Ohm resistor

220 Ohm resistor

Computer


Circuit




Program

You can use sample program "Blink"

You just need to change 

int = 13;

to

int = 2;









2010年7月4日日曜日

7 segment with Shift Resistors

I did a test of controlling 7 segment with Shift resistor 8-Bit - 74HC595.

I finally control two 7 segment with two Shift resistor 8-Bit - 74HC595.


Tutorial

Shift resistor 8-Bit - 74HC595 is very useful since Arduino have only 13 digital pins we may need more pins to make a more complex controller.

7 segment is one of a example that need a lot of pins to control.

So that I will explain Shift resistor 8-Bit - 74HC595 with two 7 segment.



Requirement

Shift Resistor 8-Bit - 74HC595

Two 7 segment

A lot of wires

14 220Ohm resistors

Breadboards(At least you need one large  Breadboard) I use one  Breadboard and two small  Breadboard.

Arduino

Arduino program

computer with USB

Calculator (you need to change decimal to binary)

Circuit

latchPin is 8.

clockPin is 12.

dataPin is 11.



When you send a value with ShiftOut, the value which transformed into
a binary data will conrespond to the red pin(Q0 ~ Q7).
Since this is a 8 bit shift resistor, the range of the value will be 0~255.
(2x2x2x2x2x2x2x2)
For example, if you send a value 96, it will transformed to 011000000.
Since number 0 means off and number 1 means on, in this case Q6 and Q5
will be HIGH.






Program


//Original program is http://arduino.cc/en/Tutorial/ShftOut11


//**************************************************************//
// Name : shiftOutCode, Hello World
// Author : Carlyn Maw,Tom Igoe, David A. Mellis
// Date : 25 Oct, 2006
// Modified: 23 Mar 2010
// Version : 2.0
// Notes : Code for using a 74HC595 Shift Register //
// : to count from 0 to 255
//****************************************************************


//I modified slightly


//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;

void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}

void loop() {
//count up routine

//ground latchPin and hold low for as long as you are transmitting
digitalWrite(latchPin, LOW);

//You can change the value.

// If you use the same circuit

// TO DISPLAY   1 is 96, 2 is 220, 3 is 244, 4 is 104, 5 is 182, 6 is 62, 7 is 226, 8 is 254, 9 is 230, 0 is  250.
shiftOut(dataPin, clockPin, MSBFIRST, 254);
   

// second shift resister

//Same as the hear
shiftOut(dataPin, clockPin, MSBFIRST, 226);


//return the latch pin high to signal chip that it
//no longer needs to listen for information

digitalWrite(latchPin, HIGH);
delay(1000);

}






2010年7月3日土曜日

Practical Tutorial of How to make Aii (Arduino + Wii Nunchuk) and use it

This is a tutorial of How to make Aii(Arduino and Wii Nunchak).

This exercise enables you to connect Wii Nunchuk to Arduino.

You will also learn how to connect Aii to Isadora and how to send a OSC data over the Internet(Wi-Fi).

Wii Nunchuk is a great tool for us. It has 7 different input device(two button, two potentiometer like function and one XYZ accelerometer)

Having an Accelerometer is really great, because the cost  of accelerometer is from 19.95 to $39.95.(SparkFun.com) However, if you order Wii Nunchuk from Amazon.com, it costs only from $3.25 to $19.95. 

I connect Nintendo Will Nunchuk to Arduino and made Aii.

The program was based on the information of http://www.windmeadow.com/node/42

I added little more cords so that it works with Isadora.

To make a circuit, I referred http://todbot.com/blog/2007/10/25/boarduino-wii-nunchuck-servo/

For the information of OSC transmission with Isadora, I referred http://vjskulpture.wordpress.com/2010/01/14/basic-open-sound-control-osc-isadora-mac/

Requirement

Arduino

Arduino program

Isadora

Wii Nunchuk

Wires(you may need alligator clips and soldering iron)

Two computer that is connected to a same router.

Red LED



Circuit









Program

You can use a program from http://www.windmeadow.com/node/42

But you have to change the function of void print() in the program to following.

void
print ()
{
int joy_x_axis = outbuf[0];
int joy_y_axis = outbuf[1];
int accel_x_axis = outbuf[2] * 2 * 2;
int accel_y_axis = outbuf[3] * 2 * 2;
int accel_z_axis = outbuf[4] * 2 * 2;

int z_button = 0;
int c_button = 0;

// byte outbuf[5] contains bits for z and c buttons
// it also contains the least significant bits for the accelerometer data
// so we have to check each bit of byte outbuf[5]
if ((outbuf[5] >> 0) & 1)
{
z_button = 1;
}
if ((outbuf[5] >> 1) & 1)
{
c_button = 1;
}

if ((outbuf[5] >> 2) & 1)
{
accel_x_axis += 2;
}
if ((outbuf[5] >> 3) & 1)
{
accel_x_axis += 1;
}

if ((outbuf[5] >> 4) & 1)
{
accel_y_axis += 2;
}
if ((outbuf[5] >> 5) & 1)
{
accel_y_axis += 1;
}

if ((outbuf[5] >> 6) & 1)
{
accel_z_axis += 2;
}
if ((outbuf[5] >> 7) & 1)
{
accel_z_axis += 1;
}

// This is a section that is actually modified.

Serial.print(1,DEC);
Serial.print (joy_x_axis, DEC);
Serial.println();

Serial.print(2,DEC);
Serial.print (joy_y_axis, DEC);
Serial.println();

Serial.print(3,DEC);
Serial.print (accel_x_axis, DEC);
Serial.println();

Serial.print(4,DEC);
Serial.print (accel_y_axis, DEC);
Serial.println();

Serial.print(5,DEC);
Serial.print (accel_z_axis, DEC);
Serial.println();

Serial.print(6,DEC);
Serial.print (z_button, DEC);
Serial.println();

Serial.print(7,DEC);
Serial.print (c_button, DEC);
Serial.println();

Serial.print ("\r\n");
}

// Encode data to format that most wiimote drivers except
// only needed if you use one of the regular wiimote drivers
char
nunchuk_decode_byte (char x)
{
x = (x ^ 0x17) + 0x17;
return x;
}


For more information check my tutorial of Isadora + Arduino

http://art-research2010summer.blogspot.com/2010/06/tutorial-01-isadora-and-arduino.html


Isadora

You do not do something special for Isadora but you have to make a lot of "Serial in Watcher".

Check below again to know how to do it.

http://art-research2010summer.blogspot.com/2010/06/tutorial-01-isadora-and-arduino.html

You need 7 "Serial in Watcher" to get all of the benefit of Wii Nunchuk

All of the "Serial in Watcher" need ideal number to identify each other.

Program for Isadora's Serial in Watcher(double click and open a window)

Serial in Watcher 1

"1"

StickA: integer = 4 digits

Serial in Watcher 2

"2"

StickB:integer = 4 digits

Serial in Watcher 3

"3"

Acc1: integer = 4 digits

Serial in Watcher 4

"4"

Acc2: integer = 4 digits

Serial in Watcher 5

"5"

Acc3: integer = 4 digits

Serial in Watcher 6

"6"

ButA:interger= 4 digits

Serial in Watcher 7

"7"

ButB: integer = 4 digits


Go to the OUTPUT and Setup Serial (choose Serial such as COM4 Speed 9600) and check Enable Serial 





You can play around with Aii to see how these value will change.


Make "OSC transmit"

Setup IP address of the computer that you want to control and connect the value of the "OSC transmit" to the "Serial in Watcher" which you like.


Setup your another computer

If you do not know how to check your IP address, see my blog post about Arduino Server (below address).

http://art-research2010summer.blogspot.com/2010/06/arduino-ethernet-shield.html

Run Isadora in your another computer(in my case it is a Laptop).

Make a OSC listener, that it!.

You will get a value and you can use this value for anything that you want to use.

I use "Calculator" to adjust a value and connect it to "Dot" size.





You DONE



2010年6月30日水曜日

Sensor 08 IR Receiver Breakout


This is a tutorial of How to use IR Receiver Breakout.

Requirement 

IR Receiver Breakout

Arduino

Arduino program

computer

Three wires

Something that can emit IR (Regular remote controller is fine)





Program

/* regular program for a circuit that use analog pin #0

to get a data from sensor.

*/ 


void setup(){

Serial.begin(9600); // Serial connection setup

}

void loop(){

Serial.println(analogRead(0)); //get data and send data

delay(100); // regulate a time

}




2010年6月28日月曜日

Basic three 7-segment control

This is a example of how to show a digit to a 7-segment.

This example display a digit, which is sent from computer on one of three 7-segments.


To do it, you need

Arduino

Arduino program

Computer

Three 7-segments

Eight 220 Ohm resistors

Lot of wires (more than 20)


Circuit


Basically 7-segment is a bunch of LEDs. You need to put a resistor as the same as regular LED.

You have to connect Anode pins of the 7-segments to digital pin number from 2 to 13, no 1 or2 .

You need to connect each 7-segment in parallel. 

In the case of my 7-segment, there is two common cathodes on the 7-segment.

We do not need two, but one of them and connect it to a ground for the case of mine.

If you have a different 7-segment you may have to connect differently. If so, you cannot use program on this tutorial.

However, instead of using a regular ground we will use regular digital pin as a ground.

We will turn several digital pins to ground with a program. It will enable us to control three 7-segments respectively.




Program

you may need to change some cord for your circuit.

I messed up my circuit so that this program is little bit messed up.

//reguler variable
int LEDpin = 13;
int c;
int seg1=10;
int seg2=11;
int seg3=12;

//controller variables
int refleshT=10;

void setup()
{
Serial.begin(9600);
for (int i=2; i<10; ++i){
Serial.print("set OUTPUT to digital pin");
Serial.println(i);
pinMode(i,OUTPUT);
}
for (int i=10; i<13; ++i){
Serial.print("set INPUT to digital pin");
Serial.println(i);
pinMode(i,INPUT);
}

pinMode(LEDpin,OUTPUT);
Serial.println("LED is ready to use");
for (int i=10; i<13; ++i){
Serial.print("set pin");
Serial.print(i);
Serial.println("to Ground");
digitalWrite(i,HIGH);
digitalWrite(i,LOW);
}
Serial.println("OK pins are ready");
}
void loop()
{
if(Serial.available()>0){
c=Serial.read();
Serial.print("get Serial");
Serial.println(c,BYTE);
if(c=='8'){
reset();
pinMode(seg3,OUTPUT);
eight();
}
else if(c=='0'){
reset();
pinMode(seg2,OUTPUT);
zero();
}
else if(c=='1'){
reset();
pinMode(seg1,OUTPUT);
one();
}
else if(c=='2'){
reset();
pinMode(seg1,OUTPUT);
two();
}
else if(c=='3'){
reset();
pinMode(seg3,OUTPUT);
three();
}
else if(c=='4'){
reset();
pinMode(seg2,OUTPUT);
four();
}
else if(c=='5'){
reset();
pinMode(seg1,OUTPUT);
five();
}
else if(c=='6'){
reset();
pinMode(seg2,OUTPUT);
six();
}
else if(c=='7'){
reset();
pinMode(seg2,OUTPUT);
seven();
}
else if(c=='9'){
reset();
pinMode(seg3,OUTPUT);
nine();
}
else{
for (int i=10; i<13; ++i){
Serial.print("reset");
pinMode(i,INPUT);
Serial.print(i);
Serial.println("pin");
}
nothing();
}
}
}

//The following commends are needed to modify for your circuit
void zero(){
nothing();
digitalWrite(2,HIGH);
//digitalWrite(3,HIGH); disabled
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
//digitalWrite(6,HIGH); disabled
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
delay(refleshT);
}
void one(){
nothing();
//digitalWrite(2,HIGH); disabled
//digitalWrite(3,HIGH); disabled
//digitalWrite(4,HIGH); disabled
//digitalWrite(5,HIGH); disabled
//digitalWrite(6,HIGH); disabled
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
//digitalWrite(9,HIGH); disabled
delay(refleshT);
}
void two(){
nothing();
//digitalWrite(2,HIGH); disabled
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
//digitalWrite(6,HIGH); disabled
//digitalWrite(7,HIGH); disabled
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
delay(refleshT);
}
void three(){
nothing();
//digitalWrite(2,HIGH); disabled
digitalWrite(3,HIGH);
//digitalWrite(4,HIGH); disabled
digitalWrite(5,HIGH);
//digitalWrite(6,HIGH); disabled
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
delay(refleshT);
}
void four(){
nothing();
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
//digitalWrite(4,HIGH); disabled
//digitalWrite(5,HIGH); disabled
//digitalWrite(6,HIGH); disabled
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
//digitalWrite(9,HIGH); disabled
delay(refleshT);
}
void five(){
nothing();
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
//digitalWrite(4,HIGH); disabled
digitalWrite(5,HIGH);
//digitalWrite(6,HIGH); disabled
digitalWrite(7,HIGH);
//digitalWrite(8,HIGH); disabled
digitalWrite(9,HIGH);
delay(refleshT);
}
void six(){
nothing();
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
//digitalWrite(6,HIGH); disabled
digitalWrite(7,HIGH);
//digitalWrite(8,HIGH); disabled
//digitalWrite(9,HIGH); disabled
delay(refleshT);
}
void seven(){
nothing();
digitalWrite(2,HIGH);
//digitalWrite(3,HIGH); disabled
//digitalWrite(4,HIGH); disabled
//digitalWrite(5,HIGH); disabled
//digitalWrite(6,HIGH); disabled
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
delay(refleshT);
}
void eight(){
nothing();
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
//digitalWrite(6,HIGH); disabled
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
delay(refleshT);
}
void nine(){
nothing();
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
//digitalWrite(4,HIGH); disabled
//digitalWrite(5,HIGH); disabled
//digitalWrite(6,HIGH); disabled
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
delay(refleshT);
}
void nothing(){
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
delay(refleshT);
}

//special loop
//reset pins
void reset(){
for (int e=10; e<13; ++e){
pinMode(e,INPUT);
}
}



2010年6月15日火曜日

Make a simple work with Lily Pad Arduino


LilyPad Arduino is a wearable Arduino.

It uses conduct threads in stead of regular metal wires so that it enable to make a wearable art work or interactive wall cloth.

I did a following experiment with Lily pad; however, I do not recommend you to do a same thing with me since I did not planed perfectly and it was the first time trial. 

I made a gloves with LED. If I press or hold something with finger, the color of LED will be changed. 

Requirement

Lily pad Arduino

conduct thread

power supply for Lily pad Arduino

AAA battery  

10K resistor

Force sensor

LED that came with Lily Pad

Sewing Stuffs (needle, thread)

Cloth or material which you want to be sewed 





Warning: this experiment potentially causes unexpected danger to you and Arduino.

Be safe when you do a experiment with Lily Pad.

If you find anything that unexpected result, plug out power charger( USB or battery ).

I actually almost broke down the circuit of the LilyPad because of shorts of the circuit.

First thing that you need to do is to imagine the final form of the circuit.

It must be better to spend a time to figure out how you sew thread to the glove.

I am sure that you will encounter a lot of problems while you are sewing since I also encountered a lot of problems.

Basic idea of circuit









As you see some of the threads nearly touch each other, that really bad.

I should have planned more nicely.



Program


int ledPin=10; // declare variables
int ledPin2=10;
int pressure=0;
int val,val2;
void setup()
{
  pinMode(ledPin, OUTPUT); //setup pin
}
void loop()
{
  val = analogRead(pressure)/4;

//load data and convert it to suitable value for PWM
val2 = 255-val;

//load data and convert it to suitable value for PWM
analogWrite(ledPin, val);
delay(400);
analogWrite(ledPin, val2);
delay(400);
}







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 
}
}

Sensors 01 Piezo

Piezo vibration sensor

explanation of Piezo

http://arduino.cc/en/Tutorial/Knock

 Requirement

10k Ohm Resister(any valued resistor is fine but it is hard to get a signal if you use lower resistor and it is potential risk to break down analog input if you use too high resistor)

piezo

wires

Arduino




This exercise is very simple.

Circuit



I wrongly put a LED in a picture but it does not do anything.



Program

I made a very simple program to check

void setup()
{
  Serial.begin(9600);//setup serial speed
}
void loop()
{
  Serial.println(analogRead(0)); // gets data from analog pin 0 and send to computer
  delay(500); //not to send too much information
}


It actually the resistor is critical for this circuit.

I originally used 100k ohm resistor but the value of analog signal was so tiny.

Also the result is deeply depend on piezo itself. I tried three different piezo but they send back different amount of values.





Exercise and Tutorial 4

 http://www.lulu.com/items/volume_63/1108000/1108699/4/print/ARDUINO_NOTEBOOKv6.pdf

This tutorial is based on the PDF page 35 about servo, and I changed program to check my understanding of the tutorial.

The PDF tutorial has a good information but the program seems complex. I simplified a program and add a little function.

In the following tutorial I am going to explain the way to control servo motor in a different way that explained in a tutorial of the Arduino web page.

In way that is introduced in a Arduino web page is use servo library to control the servo motor. Therefore, only pin9 and pin10 is available for servo.

However, the pin 9 and 10 has a function of pwm and you might want to use them for other purposes.

This tutorial enable you to use any digital pin to control servo motor.

Requirements

Servo motor 

(you may need a pin that has three legs both side to connect servo to the board)

10K resistor

Switch

Wires

Arduino





Before we start we need to understand more about servo motor

From the PDF

 http://www.lulu.com/items/volume_63/1108000/1108699/4/print/ARDUINO_NOTEBOOKv6.pdf

"Hobby servos are a type of self-contained motor that can move in a 180º arc. All that is needed is a pulse sent every 20ms."


From the Arduino web page

http://arduino.cc/en/Tutorial/Knob

"Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be connected to a ground pin on the Arduino board. The signal pin is typically yellow or orange and should be connected to pin 9 on the Arduino board."

I found additional useful information from Wikipedia

http://en.wikipedia.org/wiki/Servo_motor

"A servo pulse of 1.5 ms width will set the servo to its "neutral" position, or 90°. For example a servo pulse of 1.25 ms could set the servo to 0° and a pulse of 1.75 ms could set the servo to 180°. The physical limits and timings of the servo hardware varies between brands and models, but a general servo's angular motion will travel somewhere in the range of 180° - 210° and the neutral position is almost always at 1.5 ms."


Now we got a enough information to program and build up circuit, so that let's try based on these information.

Circuit






Program

/*

This program is enable you to rotate a servo motor without using a Arduino library.

If you hit a  switch the motor will rotate opposite direction.

*/

int ledPin=3;//switch 
int pin=2;//for servo motor control 
int val;
int offCount = 1450;// you can change the rotation of the servo motor 
int onCount = 1550;//same as here 

void setup()
{
pinMode(pin, OUTPUT);//set up pins 
pinMode(ledPin, INPUT);
}
void loop()
{
val= digitalRead(ledPin); // get data from switch 
if (val==false)

//check whether switch is on or off you can use 0 instead of false 
{
digitalWrite(pin, HIGH); //send a pulse 
  delayMicroseconds(offCount);//it is important for servo motor 
digitalWrite(pin, LOW);
delay(20);// also important. If you omit it, the motor do not work properly. 
}
else
{

// when you switch on
digitalWrite(pin, HIGH);
  delayMicroseconds(onCount);
digitalWrite(pin, LOW);
delay(20);
}

}



If you put a value 1500 at offCount or onCount ot both the motor does not work but it does not mean broken but it is balanced.

I do not know how much angle does our servo motor can take, but we can put a value from 1250 to 1750 safely.




Extra

Ardui-Bot (Arduino on the Boe-Bot frame)





2010年6月7日月曜日

Exercise and Tutorial 3

http://www.lulu.com/items/volume_63/1108000/1108699/4/print/ARDUINO_NOTEBOOKv6.pdf

This exercise based on the PDF p32,p34 "pwm output" out put and I modified a program to check my understanding.

The term pwm output is Pulse-width modulation that allow to use digital output like as analog output.

The following circuit and program will adjust the brightness of the  LED by the darkness of the place with photo-sensor and pwm.

Requirements

220Ω resistor

more than 10kΩ resistor (depend on the darkness of a room. I use 21kΩ)

1kΩ resistor(not necessary to use 1kΩ)

LED

Photo-sensor

Wires

Arduino 

Program

/*

Basically, this program works like a bridge between analog input and pwm output.

Get a value from photosensor and do calculation to adjust a value for pwm with arithmetics. 

*/

int ledPin = 9; // PWM pin for the LED
int anaPin=0;
int val;


void setup(){
Serial.begin(9600);
Serial.println("start");
}
void loop()
{
 val = analogRead(anaPin)/4; 

/*

The program get a vale from analog input.

However, the value of analog input takes from 0 to approx. 1000

,but for the pwm we need a value from 0 to 255.

Therefore, the value is divided by 4.

*/
Serial.println(val); // just for checking a value 
val = 255 - val;

/*

Since we want to light the LED when a room became dark,

we need to do kind of flip the value. 

So that we need to subtract a value from 255.

*/
analogWrite(ledPin, val);// send a signal and value to the pin 
delay(100);
}



Hardware setup



Need to adjust the resistance of resisters case by case.

Work movie





Exercise and Tutorial

http://www.lulu.com/items/volume_63/1108000/1108699/4/print/ARDUINO_NOTEBOOKv6.pdf

This exercise is based on PDF page 30 (digital input)

This original exercise is making up circuit and program that turn on Green LED when the switch is pressed. I added a circuit and modified the program so that Red LED blink while the witch is not pressed.

Requirement

Arduino main board

Two different colored LED.

Resisters 10kΩ and around 1kΩ

Push Switch

Wires




Program

/*

This circuit use "if else" instead of "if" in oder to light a Red LED while switch is off.

*/

int ledPin = 13; // output pin for the LED
int inPin = 2; // input pin (for a switch)
int ledPin2 = 7;
int val;
void setup()
{
Serial.begin(9600);
Serial.println("program is started");
pinMode(ledPin, OUTPUT); //set up 13 pin
pinMode(inPin, INPUT); // set up 2 pin
pinMode(inPin, OUTPUT); // set up 7 pin
}
void loop()
{
val = digitalRead(inPin);
if ( val == 1) // check the button
{
digitalWrite(ledPin, HIGH); // turns the LED on
delay(500); // 0.5 second duration
digitalWrite(ledPin, LOW); // turns the LED off
delay(500); // 0.5 second duration
}
else 
{
digitalWrite(ledPin2, HIGH); // turns the LED on
delay(500); // 0.5 second duration
digitalWrite(ledPin2, LOW); // turns the LED off
delay(500); // 0.5 second duration
}
}


Hardware setup

The key of the structure is to put a resistor between a switch and ground to work everything properly.








Exercise and tutorial

http://www.lulu.com/items/volume_63/1108000/1108699/4/print/ARDUINO_NOTEBOOKv6.pdf

This exercise is based on PDF page 29 (digital output)

The exercise in PDF was lighting up LED. I changed a program little bit so that Arduino sends back to the computer additional information.

Requirements

Arduino Kit (Arduino board, LED, resistor, wires)



Program

/*

This program is a basic test of digital output and "Serial.print".

The Arduino board will send back information of the loop counter.

*/
int pin=13; //variables. I use this variable to specify a digital pin
int counter=0; //I use this variable to count a number of loop
int delayTime = 500; //value for delay


void setup()
{
  Serial.begin(9600);  //setup serial connection speed
  pinMode(pin, OUTPUT); //setup digital pin
  Serial.println("start program"); //This message will appear one at the beginning 
}


void loop()
{

// the followings loop forever
  counter++; // Whenever loop, increment will add 1 to the "counter" variable 
  Serial.print("this is"); //It is better not to use Serial.println in hear
  Serial.print(counter); // get a value from variable
  Serial.println("time"); 
  digitalWrite(pin, HIGH); //light LED
  delay(delayTime);           //duration
  digitalWrite(pin,LOW);  //turn of LED
  delay(delayTime*2);    //duration
}



Hardware setup

The LED is connected to the resistor and digital pin 13

The program will control power supply to the LED and resistor control the amount of electrical flow.


Work picture