27 May, 2010

Tasks 19-30

Tasks 19 to 30

19) Write a program to get one led to increase its rate of blinking from 100ms to1 sec.

int t = 100; //set the inital value of t as 100ms.
int led = 13;

void setup(){
pinMode(led, OUTPUT);
}

void loop() {
digitalWrite(led, HIGH);
delay(t);
digitalWrite(led, LOW);
delay(t);
t = t + 100; //increment t by 100 each time that the code is run.
}

20) Same as 19 but this time ramp up the rate from 10ms to 1 sec then back down again.

int led = 13;

void setup(){
pinMode(led, OUTPUT);
}

void loop(){
for(int t = 10; t <1000; t+100){
digitalWrite(led, HIGH);
delay(t);
digitalWrite(led, LOW);
delay(t);
}

for( t= 1000; t >100; t-100){
digitalWrite(led, HIGH);
delay(t);
digitalWrite(led, LOW);
delay(t);
}
}

21) Write a program to output one led blinking at rate of 200ms that outputs the word "blink" to the screen each time it comes on.

int led = 13;
void setup() {
pinMode(led, OUTPUT);
Serial.begin(9600); //set the baud rate to 9600 bits per sec
}
void setup() {
digitalWrite(led, HIGH);
Serial.println("BLINK");
delay(200);
digitalWrite(led, LOW);
delay(200);
}

22) Same as 21 but this time use two leds of different colours and output the colour of the led to the screen each time it goes on. So you should see eg. "red yellow red yellow ..."

int ledO = 13; //orange
itn ledG = 12; //green led
void setup() {
pinMode(ledO, OUTPUT);
pinMode(ledG, OUTPUT);
Serial.begin(9600); //set the baud rate to 9600 bits per sec
}
void setup() {
digitalWrite(ledO, HIGH);
Serial.println("Orange ON");
delay(200);
digitalWrite(ledO, LOW);
delay(200);
digitalWrite(ledG, HIGH);
Serial.print("Green ON);
delay(200);
digitalWrite(ledG, LOW);
delay(200;

}

23) Look at http://wwww.wikieducator.org/User:Peterb/HowManyArduinos0

In my school this website was blocked.
 But there is a kind of arduino i saw off MindKits called the Arduino MEGA which has 54 digital I/O pins.  It uses a larger version of the ATMega Microprocessor.

24) LRD photo resistors
when the light changes in a room the LDR's resistance changes.  This can be monitored using the Arduino with the analogRead() function.

25, 26 and 28)  Making the light sensor work.

To get the arduino to read the light sensor accuratly I use a 1k ohm resistor in the circut.


Here is the code that I used:

//LDRMon by Tim Sullivan

//set varyables for stuff
int ldr = 0; //inital value of the ldr
int led = 13; //use the default led on the arduino
int ldrPin = 0; //the LDR is connected to analouge pin 0

void setup() {
  pinMode(led, OUTPUT); //because LEDs usally output light...
  Serial.begin(9600); // connect to the arduino to monitor things such as 'ldr'
  //above line was just used just for debugging
}

void loop() {
ldr = analogRead(ldrPin); //read the analog pin.
// Serial.println(ldr); //tell us what the ldr is.
if(ldr > 20){
  digitalWrite(led, HIGH);
  }
 digitalWrite(led, LOW);

}

29) Random numbers on arduino

My code

int num = 0;
void setup(){
  Serial.begin(9600);
}
void loop(){
  num = random(101); //generate random numbers 0 to 100
 Serial.print(num);
}

Screenshot (my arduino was home at the [imagine random numbers in here] )


Task 30) Random dice program

/*The DICE program
by Tim Sullivan

It hasn't actually been tested with an arduino but think
it will range the correct numbers.

*/

int num = 1;
void setup(){
  Serial.begin(9600);
}
void loop(){
  num = random(1,6); //generate random numbers 1 to 6
  //i hope thats right
 Serial.print(num);
}

25 May, 2010

PWM - Pulse Width Modulation - Arduino

Today i discovered what the digtal I/O pins labeled with a "PWM" were for.  They can be use to make a digital signal pulse instead of be on or off.  This means that you can make an LED fade on and off without using 1000's of on's and off's.

The IDE function used to do this is called analogWrite()

12 May, 2010

Tasks second set 13 - 18

Tasks - Second set

13)  mostly on than off.
[...]
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
delay(1000);
digitalWrite(led2, HIGH);
delay(500);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
[...]
----------------------------------------------------------------
14)  now the opposite




[...]
digitalWrite(led2, HIGH);
digitalWrite(led1, LOW);
delay(1000);
digitalWrite(led1, HIGH);
delay(500);
digitalWrite(led2, LOW);
digitalWrite(led1, LOW);
[...]
----------------------------------------------------------------
15)  will send email
----------------------------------------------------------------
16) get one led to blink once then repeat the other infinitely 

//start of program
int powerOnLed = 13;
int blinkStatus = 12;
int num = 0;

void setup() {
  pinMode(powerOnLed, OUTPUT);
  pinMode(blinkStatus, OUTPUT);
  }

void loop() {
while(num = 0) {
  digitalWrite(powerOnLed, HIGH);
  delay(1000);
  digitalWrite(powerOnLed, LOW);
  num = num + 1;
  }
digitalWrite(blinkStatus, HIGH);
delay(1000);
digitalWrite(blinkStatus, LOW);
delay(1000);

}

--------------------------------------------------------------------
17) using the for loop SUCCESS!!

int ledPin1 = 13;
int ledPin2 = 12;
int t = 300;


void setup() {
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
}


void loop() {
int i = 0;
for(i=0;i<5;i++){
digitalWrite(ledPin1, HIGH);
delay(t);
digitalWrite(ledPin1,LOW);
delay(t);
}


digitalWrite(ledPin2, HIGH);
delay(t);
digitalWrite(ledPin2, LOW);
delay(t);
}








-----------------------------------------------------------------------------
18) same as above but different value

int ledPin1 = 13;
int ledPin2 = 12;
int t = 300;


void setup() {
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
}


void loop() {
int i = 0;
for(i=0;i<10;i++){
digitalWrite(ledPin1, HIGH);
delay(t);
digitalWrite(ledPin1,LOW);
delay(t);
}


digitalWrite(ledPin2, HIGH);
delay(t);
digitalWrite(ledPin2, LOW);
delay(t);
}




Tasks first set 1-12

Tasks


5) Make the blink twice as slow:
[...]
//make led blink on for 2s and off for 2s
digitalWrite(led, HIGH);
delay(2000);
digitalWrite(led, LOW);
delay(2000);
[...]
-----------------------------------------------------------

6) Make the LED blink fast
[...]
//make the led turn on for (50ms) and off (50ms)

digitalWrite(led, HIGH);
delay(50); //this is quite fast but still visible.
digitalWrite(led, LOW);
delay(50);

/*if the program was delayed for 9 milli seconds it would look like the led is solid on. */
[...]
-------------------------------------------------------------

7) Get led to stay on mostly then flash off.
[...]
digitalWrite(led, HIGH);
delay(10000); //stay on for 10 seconds
digitalWrite(led, LOW);
delay(100); //flash off for 100ms
[...]
-------------------------------------------------------------
8) Now the other way around from '7'
[...]
digitalWrite(led, HIGH);
delay(100); // illuminate for 100ms
digitalWrite(led, LOW);
delay(10000); //stay off for 10 sec
[...]
-------------------------------------------------------------
9) What has LEDs
iPods, computers (eg HDD activity), the arduino, network hubs/switches, tv.

Some cordless phones detect whether there is a message and makes a LED light up for 500ms every 4 seconds.
-------------------------------------------------------------
10) I have downloaded Fritzing
-------------------------------------------------------------
11) I have made a Fritzing diagram for the 7-Segment LED display
-------------------------------------------------------------
12) Fritzing project
A RGB colour mixer looks interesting by getting different colours to change by using a potentiometer. 

06 May, 2010

Another cool idea

http://www.youtube.com/watch?v=ATnnMFO60y8&NR=1&feature=fvwp

LDR Robot

Here is a video of something I would like to make using a Light Dependent Resistor: http://www.youtube.com/watch?v=wLAjnOWO8mU

Getting 2 reds and 1 green flashing!

15 minutes after the video conference on Thursday me and Nich got 2 LEDs that were red and 1 green to oscillate.

Here is the code


int green = 12;
int red1 = 11;
int red2 = 10;
int t = 1000;

void setup() {
pinMode(green, OUTPUT);
pinMode(red1, OUTPUT);
pinMode(red2, OUTPUT);
}

void loop() {
digitalWrite(red1, HIGH);
digitalWrite(red2, HIGH);
digitalWrite(green, LOW);
delay(t);

digitalWrite(red1, LOW);
digitalWrite(red2, LOW);
digitalWrite(green, HIGH);
delay(t);
}