Archive for October, 2007

Light sensor

Thursday, October 18th, 2007

My next idea was to play around with the light sensor.

The idea of a practical use was following:
Most of the times I carry my mobile phone in my bag – so I have many missed calls, because I can’t hear it ringing (especially when listening to music). So I wanted to make something, that would notify my when the phone is ringing. Nowadays most mobile phones turn on their displays when you ring them – here the light sensor could be used. I’d create a small pocket for my phone in my bag, with the light sensor integrated and facing the display of the mobile phone. All I need then is a program, that would detect the light from the display and then turn the beeper on.

The program:
- monitor block – to see the values coming from the light sensor and thus to set the correct treshold value
- “if” block – to tell the board that if a certain value from the sensor is lower than a treshold (values rise as less ligt shines on sensor/more light means smaller number outputs – 1023 is the top value) to turn the beeper on
- “on” block next to the “if” block – simply to turn on the digital output (beeper in our case)
- “off” block to turn off the digital output when the value is less than the set treshold

Code:
int val= 0;
int compare=0;
int Pin7 = 7;
int Pin2 = 2;
void setup(){
pinMode(Pin2, INPUT);
pinMode(Pin7, OUTPUT);
Serial.begin(9600);

}
void loop(){
int analogValue;
analogValue = analogRead(2);
Serial.println(analogValue);
delay(10);
val = analogRead(Pin2);
compare=900;
if (val > compare){
digitalWrite(Pin7, HIGH);
}
else {
digitalWrite(Pin7, LOW);
}

}

And it works!!!

But:
I ahad several problems while working on this code:

- first of all, from reasons unknown to me the code has to be corrected after you switch from the block to the text view. the else statement in the condition looked originally like this:

else {

}
digitalWrite(Pin7, LOW);

The instruction to turn off the digital pin was out of curly brackets, so I had to move it in.

- I also don’t quite understand the if condition itself – it says, that if the value from the sensor is more that 900 (treshold value) it will turn the digital pin on, but it works the opposite way. I had to change the code itself after I turned it on for the first time and it did not worked as I wanted. I’m playing around with it right now and I see the values coming from the sensor – if they are above 900 the beeper is off and vice versa…strange to me…

What does each Block do?

Tuesday, October 16th, 2007


On

The block switches on the pin you choose in the list

OnFor

The block switches on the port you choose for a certain time.
You need to add a variable on the to say for how long i.e. 1000 for 1 second
Afterwards the pin will be switched of for the same amount of time. Note: a LED would blink.

That is example how to use onFor:
onForConstrcut

Off

The block switches the pin you choose off. NOTE: on and off might be different from what you expect as they also depend on your circuit.

If

The block can be used for everything you want to do after reading a value from a switch/sensor.
Choose where you connected the switch/sensor and choose the treshold. You can try out what values
you get by using the Monitor block before. Drag for example an On Block right to the if block to switch on an LED after pressing a button.

Note: if you do not add a second if statement below with the opposite values the LED will be on forever

Here is an example how to use the if block: First ask i.e. if the sensor value on pin 3 is more then 500 then drag an on block to right. Then ask in another if block if the sensor value on pin 3 is less then 500 and drag on off block next to it. Now you can go on with your programm under the second if block
ifConstuct
waittill

Wait till

Can be used instead of “if”. Waits till a certain event (i.e. Switch is pressed happens).

Sound

If you connect a beeper to port 9,10 or 11 you can play melodies with this block
monitor

Monitor

Can be used to show data of a sensor or switch back on your computer. It is very usefull to find out what kind of values you get. NOTE: to see the values you must click on the “Serial Monitor” after uploading your program.

delay

Delay

Pauses the program for the duration of a variable you have to add.The duration is in Microseconds so use 1000 if you want to stop for a second.

delayConstruct

Flashing/beeping

Monday, October 15th, 2007

Ok. So I started with very simple programs first to familiarize myself with the whole process of creating/compiling and uploading to the board.

One of the simplest that came into my mind was a program for flashing LED or beeping sound (can be later integrated to more difficult and complex programs…)

I have only connected the sound beeper to the board (digital output pin).

Blocks:
- drag an “on for” block and select your digital pin number
- drag a “variable” block next to it and set the variable – that will be the time delay (in miliseconds) between beeps/flashes (I chose 500 – 1/2 of a second)

The code looks like this:

int val= 0;
int compare=0;
int Variable31=500;
int Pin7 = 7;
void setup(){
pinMode(Pin7, OUTPUT);

}
void loop(){
digitalWrite(Pin7, HIGH);
delay(Variable31);
digitalWrite(Pin7, LOW);
delay(Variable31);

}

LilyPad

Monday, October 8th, 2007

Leah Buechley in corperation with SparkFun released the first version of the LilyPad. It seems to be a great work and I can’t wait till I get one.
View the LilyPad guide for more examples.

We will order it for EduWear, but unfortunatly it is already sold out.

So we will stick to the shield for the Arduino Mini that I verified, until there are new LilyPads availible. That is the Layout in Eagle and here is a pic of the layout.