Sunday, June 20, 2010

Major Project

My major project is an extended version of my minor project, The Binary Coded Decimal Light Emitting Diode Chronological Gauging Mechanism (BCDLEDCGM). I have added some extra features to the BCDLEDCGM including, the ability to set the hours and minutes, the ability to set it to 12 or 24 hour time and the ability to set an alarm to go off at a specific hour and minute.

Here is an image and some video footage of the BCDLEDCGM:


































Here is the code:


////Pin connected to DS of 74HC595
const int dataPin = 11;

//Pin connected to SH_CP of 74HC595
const int clockPin = 12;

//Pin connected to ST_CP of 74HC595
const int latchPin = 13;

const int switchModeButton = 2;
const int actionButton = 6;
const int hourButton = 4;
const int minuteButton = 5;
const int buzzer = 10;

int minuteSetNum;
int hourSetNum;
int setMinutes;
int setHours;
int shiftAlarmSeconds;
int shiftAlarmMinutes;
int shiftAlarmHours;
int alarmMinutes;
int alarmHours;
int alarmSet;
int hourMode = 0;
int clockMode = 1;




#define SECS_PER_MIN (60UL)

#define numberOfSeconds(_time_) (_time_ % SECS_PER_MIN)


void setup()
{
Serial.begin(9600);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(switchModeButton, INPUT);
pinMode(actionButton,INPUT);
pinMode(hourButton, INPUT);
pinMode(minuteButton, INPUT);
}
void loop()
{
if (clockMode == 1)
{
int modeButtonState = digitalRead(switchModeButton);
if (modeButtonState == 1)
clockMode = 0;
int actionButtonState = digitalRead(actionButton);
if (actionButtonState == 1)
if (hourMode == 1)
hourMode = 0;
else
hourMode = 1;
int seconds = shiftSeconds();
int minutes = shiftMinutes(seconds);
int hours = shiftHours(seconds, minutes, hourMode);
if (alarmSet == 1)
if((minutes == shiftAlarmMinutes) && (hours == shiftAlarmHours))
tone(buzzer, 880, 500);
showTime(hours, minutes, seconds);
}
else
{
int modeButtonState = digitalRead(switchModeButton);
if (modeButtonState == 1)
clockMode = 1;
int actionButtonState = digitalRead(actionButton);
if (actionButtonState == 1)
if (alarmSet == 1)
alarmSet = 0;
else
alarmSet = 1;
int seconds = shiftSeconds();
shiftAlarmSeconds = alarmShiftSeconds();
shiftAlarmMinutes = alarmShiftMinutes(seconds);
shiftAlarmHours = alarmShiftHours(seconds, hourMode);
showTime(shiftAlarmHours, shiftAlarmMinutes, shiftAlarmSeconds);
}
delay(500);
}


int shiftSeconds()
{
unsigned long time = millis() / 1000;
int tenSeconds = ((numberOfSeconds(time) - (numberOfSeconds(time) % 10))/ 10);
int oneSeconds = numberOfSeconds(time) % 10 ;
return ((tenSeconds<<4) + oneSeconds);
}


int shiftMinutes(int seconds)
{
int buttonState = digitalRead(minuteButton);
if (buttonState == 1)
minuteSetNum = (minuteSetNum + 1) % 60;
if (seconds == 0)
{
setMinutes = (setMinutes + 1) % 60;
delay(750);
}
int minutes = (setMinutes + minuteSetNum) % 60;
int tenMinutes = ((minutes - (minutes % 10))/ 10);
int oneMinutes = minutes % 10 ;
return ((tenMinutes<<4) + oneMinutes);
}


int shiftHours(int seconds, int minutes, int mode)
{
int buttonState = digitalRead(hourButton);
if (buttonState == 1)
hourSetNum = (hourSetNum + 1) % 24;
if ((seconds == 0) && (minutes == 0))
{
setHours = (setHours + 1) % 24;
delay(750);
}
int hours = (setHours + hourSetNum) % 24;
if (mode == 0)
hours = (hours % 12) + 1;
int tenHours = ((hours - (hours % 10))/ 10);
int oneHours = hours % 10 ;
return ((tenHours<<4) + oneHours);
}


int alarmShiftSeconds()
{
if (alarmSet == 1)
return 255;
else
return 0;
}


int alarmShiftMinutes(int seconds)
{
int buttonState = digitalRead(minuteButton);
if (buttonState == 1)
alarmMinutes = (alarmMinutes + 1) % 60;
if (seconds == 0)
{
setMinutes = (setMinutes + 1) % 60;
delay(750);
}
int minutes = alarmMinutes % 60;
int tenMinutes = ((minutes - (minutes % 10))/ 10);
int oneMinutes = minutes % 10 ;
return ((tenMinutes<<4) + oneMinutes);
}


int alarmShiftHours(int seconds, int mode)
{
int buttonState = digitalRead(hourButton);
if (buttonState == 1)
alarmHours = (alarmHours + 1) % 24;
if ((seconds == 0) && ((setMinutes + minuteSetNum) == 0))
{
setHours = (setHours + 1) % 24;
delay(750);
}
int hours = alarmHours % 24;
if (mode == 0)
hours = (hours % 12) + 1;
int tenHours = ((hours - (hours % 10))/ 10);
int oneHours = hours % 10 ;
return ((tenHours<<4) + oneHours);
}


void showTime(int hours, int minutes, int seconds)
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST,hours);
shiftOut(dataPin, clockPin, LSBFIRST,minutes);
shiftOut(dataPin, clockPin, LSBFIRST,seconds);
digitalWrite(latchPin, HIGH);
}

Wednesday, June 16, 2010

Tasks 54 to 59: Data Logging

Task 54:

int photocellPin = 0;
int photocellReading;

void setup() {
Serial.begin(9600);

for (int i = 0; i <10; i++)
{
photocellReading = analogRead(photocellPin);
Serial.println(photocellReading);
delay(1000);
}
}

void loop()
{
}


Task 55:


int photocellPin = 0;
int photocellReading;
int mySamples[10];


void setup()
{
Serial.begin(9600);

for (int i = 0; i <10; i++)
{
photocellReading = analogRead(photocellPin);
mySamples[i] = photocellReading;
delay(1000);
}
}

void loop()
{
}


Task 56:


#include

int photocellPin = 0;
int photocellReading;
int EEPROMVal;

void setup() {
Serial.begin(9600);

for (int i = 1; i <=10; i++)
{
photocellReading = analogRead(photocellPin);
EEPROM.write(i, photocellReading);
delay(1000);
}
delay(5000);
for (int i = 1; i <=10; i++)
{
EEPROMVal = EEPROM.read(i);
Serial.println(EEPROMVal);
}
}

void loop()
{
}


Task 57:


#include

int photocellPin = 0;
int photocellReading;
int EEPROMVal;


void setup() {
Serial.begin(9600);
for (int i = 1; i <=10; i++)
{
photocellReading = analogRead(photocellPin);
EEPROM.write(i, photocellReading);
delay(1000);
}
delay(5000);
for (int i = 1; i <=10; i++)
{
EEPROMVal = EEPROM.read(i);
Serial.println(EEPROMVal);
}
smallest();
}


void smallest()
{
int smallestVal = 255;
for (int i = 1; i <=10; i++)
{
EEPROMVal = EEPROM.read(i);
if (EEPROMVal < smallestVal)
smallestVal = EEPROMVal;
}
Serial.println();
Serial.print(smallestVal);
Serial.println(" is the smallest value.");
}


void loop()
{
}


Task 58:


#include

int photocellPin = 0;
int photocellReading;
int EEPROMVal;


void setup() {
Serial.begin(9600);
for (int i = 1; i <=10; i++)
{
photocellReading = analogRead(photocellPin);
EEPROM.write(i, photocellReading);
delay(1000);
}
delay(5000);
for (int i = 1; i <=10; i++)
{
EEPROMVal = EEPROM.read(i);
Serial.println(EEPROMVal);
}
smallest();
biggest();
average();
}


void smallest()
{
int smallestVal = 255;
for (int i = 1; i <=10; i++)
{
EEPROMVal = EEPROM.read(i);
if (EEPROMVal < smallestVal)
smallestVal = EEPROMVal;
}
Serial.println();
Serial.print(smallestVal);
Serial.println(" is the smallest value.");
}


void biggest()
{
int biggestVal = 0;
for (int i = 1; i <=10; i++)
{
EEPROMVal = EEPROM.read(i);
if (EEPROMVal > biggestVal)
biggestVal = EEPROMVal;
}
Serial.println();
Serial.print(biggestVal);
Serial.println(" is the biggest value.");
}


void average()
{
float averageVal;
int totalVal = 0;
for (int i = 1; i <=10; i++)
{
EEPROMVal = EEPROM.read(i);
totalVal += EEPROMVal;
}
averageVal = totalVal / 10;
Serial.println();
Serial.print(averageVal);
Serial.println(" is the average.");
}


void loop()
{
}


Task 59:


Logging code:

#include

int photocellPin = 0;
int photocellReading;

void setup()
{
Serial.begin(9600);
for (int i = 1; i <=144; i++)
{
photocellReading = analogRead(photocellPin);
EEPROM.write(i, photocellReading);
Serial.println(photocellReading);
delay(600000);
}
}
void loop()
{
}


Recalling code:


#include

int EEPROMVal;

void setup()
{
Serial.begin(9600);
for (int i = 1; i <=144; i++)
{
EEPROMVal = EEPROM.read(i);
Serial.println(EEPROMVal);
}
}
void loop()
{
}


Data recorded in Bar Graph form:

Monday, June 14, 2010

Tasks 51 to 53: EEPROM

Task 51:











#include


int a = 0;
int value;

void setup()
{
Serial.begin(9600);
}

void loop()
{
value = EEPROM.read(a);

Serial.print(a);
Serial.print("\t");
Serial.print(value);
Serial.println();

a = a + 1;

if (a == 1023)
a = 0;

delay(500);
}



Task 52:











#include

int a = 0;
int value;

void setup()
{
Serial.begin(9600);
EEPROM.write(01, 35);
EEPROM.write(02, 42);
for (int i = 0; i <= 20; i++)
{
value = EEPROM.read(i);
Serial.print(i);
Serial.print("\t");
Serial.print(value);
Serial.println();
}
}

void loop()
{

}



Task 53:











#include

int a = 0;
int value;

void setup()
{
Serial.begin(9600);
for (int i = 1; i <= 1023; i++)
{
EEPROM.write(i, 171);
}
for (int i = 0; i <= 1023; i++)
{
value = EEPROM.read(i);
Serial.print(i);
Serial.print("\t");
Serial.print(value);
Serial.println();
delay(100);
}
}

void loop()
{

}

Friday, May 21, 2010

Minor Project - Complete

I have finally got the wiring sorted out so it is now working correctly.

My Minor Project is a Binary-Coded Decimal (BCD) Light Emmiting Diode (LED) Chronological Gauging Mechanisum(CGM).

The BCDLEDCGM is laid out like this:

Hours

*
8
*
4
* *
2 2
* *
1 1

Minutes

*
8
* *
4 4
* *
2 2
* *
1 1

Seconds
*
8
* *
4 4
* *
2 2
* *
1 1


Here are some pictures of it working:











This picture shows the clock at 12:07am in 24hr time.











This picture shows the clock at 2:22am in 24hr time.






This is the sketch that the Arduino is running:


//Pin connected to DS of 74HC595
const int hourDataPin = 5;
const int minDataPin = 8;
const int secDataPin = 11;

//Pin connected to SH_CP of 74HC595
const int hourClockPin = 6;
const int minClockPin = 9;
const int secClockPin = 12;

//Pin connected to ST_CP of 74HC595
const int hourLatchPin = 7;
const int minLatchPin = 10;
const int secLatchPin = 13;


// macros from DateTime.h
/* Useful Constants */
#define SECS_PER_MIN (60UL)
#define SECS_PER_HOUR (3600UL)
#define SECS_PER_DAY (SECS_PER_HOUR * 24L)

/* Useful Macros for getting elapsed time */
#define numberOfSeconds(_time_) (_time_ % SECS_PER_MIN)
#define numberOfMinutes(_time_) ((_time_ / SECS_PER_MIN) % SECS_PER_MIN)
#define numberOfHours(_time_) (( _time_% SECS_PER_DAY) / SECS_PER_HOUR)
#define elapsedDays(_time_) ( _time_ / SECS_PER_DAY)

void setup()
{
pinMode(hourLatchPin, OUTPUT);
pinMode(minLatchPin, OUTPUT);
pinMode(secLatchPin, OUTPUT);
pinMode(hourClockPin, OUTPUT);
pinMode(minClockPin, OUTPUT);
pinMode(secClockPin, OUTPUT);
pinMode(hourDataPin, OUTPUT);
pinMode(minDataPin, OUTPUT);
pinMode(secDataPin, OUTPUT);

void loop()
{
unsigned long time = millis() / 1000;

int tenHours = ((numberOfHours(time) - (numberOfHours(time) % 10))/ 10);
int oneHours = numberOfHours(time) % 10 ;
int tenMinutes = ((numberOfMinutes(time) - (numberOfMinutes(time) % 10))/ 10);
int oneMinutes = numberOfMinutes(time) % 10 ;
int tenSeconds = ((numberOfSeconds(time) - (numberOfSeconds(time) % 10))/ 10);
int oneSeconds = numberOfSeconds(time) % 10 ;

int shiftHours = ((tenHours<<4) + oneHours);
int shiftMinutes = ((tenMinutes<<4) + oneMinutes);
int shiftSeconds = ((tenSeconds<<4) + oneSeconds);

digitalWrite(hourLatchPin, LOW);
digitalWrite(minLatchPin, LOW);
digitalWrite(secLatchPin, LOW);
// shift out the bits:
shiftOut(hourDataPin, hourClockPin, LSBFIRST,shiftHours);
shiftOut(minDataPin, minClockPin, LSBFIRST,shiftMinutes);
shiftOut(secDataPin, secClockPin, LSBFIRST,shiftSeconds);
//take the latch pin high so the LEDs will light up:
digitalWrite(hourLatchPin, HIGH);
digitalWrite(minLatchPin, HIGH);
digitalWrite(secLatchPin, HIGH);

delay(1000);
}

Thursday, May 13, 2010

Task 46, 47, 48, 49 and 50

Task 46:

Here is the senders code:

const int dataSend = 13;

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

void loop()
{
digitalWrite(dataSend, HIGH);
delay(8000);
digitalWrite(dataSend, LOW);
delay(2000);
}


Here is the receivers code:


Here is the senders code:

const int dataRec = 2;

int recData;

void setup()
{
Serial.begin(9600);
pinMode(dataRec, INPUT);
}

void loop()
{
recData = digitalRead(dataRec);
if (recData == HIGH)
{
Serial.print(recData);
}
else
{
Serial.println(recData);
}
delay(500);
}





Task 47:

The Roles were switched on each Arduino.




Task 48:

The sender's code:

const int dataSend = 13;
const int dataRec = 2;

int recData;
int dataState;


void setup()
{
Serial.begin(9600);
pinMode(dataSend, OUTPUT);
pinMode(dataRec, INPUT);
}

void loop()
{
dataState++ % 2;
digitalWrite(dataSend, dataState);
for (int count = 1; count <= 20; count++)
{
recData = digitalRead(dataRec);
if (recData == HIGH)
{
Serial.print(recData);
}
else
{
Serial.println(recData);
}
delay(50);
}
}


The receiver's code:


const int dataSend = 13;
const int dataRec = 2;

int recData;
int dataState;


void setup()
{
Serial.begin(9600);
pinMode(dataSend, OUTPUT);
pinMode(dataRec, INPUT);
}

void loop()
{
for (int count = 1; count <= 20; count++)
{
recData = digitalRead(dataRec);
if (recData == HIGH)
{
digitalWrite(dataSend, dataRec);
Serial.print(recData);
}
else
{
digitalWrite(dataSend, dataRec);
Serial.println(recData);
}
delay(50);
}
}



Task 49:

Sender's code:

const int dataSend = 13;

int state;

void setup()
{
pinMode(dataSend, OUTPUT);
for (int i = 1; i <= 200; i++)
{
state = i % 2;
digitalWrite(dataSend, state);
delay(1);
}

}

void loop()
{
}



Recievers code:


const int dataRec = 2;

int recData;
int pulseCount = 0;

void setup()
{
Serial.begin(9600);
pinMode(dataRec, INPUT);
}

void loop()
{
recData = digitalRead(dataRec);
if (recData == HIGH)
{
pulseCount++;
Serial.print(pulseCount);
delayMicroseconds(1500);
}
}


Task 50:

Did not have two Arduinos to test speeds.

Task 45

Task 45:


Here is the code that i am using for the IR sender and receiver on the same Arduino.

const int infraSender = 13;
const int infraReceiver = 2;

int infra;

void setup(){
  pinMode(infraReceiver,INPUT);
  pinMode(infraSender,OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  for (int i = 1; i < 21; i ++)
  {
  digitalWrite(infraSender,HIGH);
  infra = digitalRead(infraReceiver);
  delay(1000);
 
    if (infra == HIGH)
    {
      Serial.println(i);
  }
  else{
    Serial.print(i);
   
    Serial.println(" Blocked");
  }
Serial.println(infra);
}
Serial.println("Finished");
delay(10000);
}

Task 44

Task 44:

I was in the group that investigated the Passive Infrared (PIR) Sensor.

Sunday, May 9, 2010

Task 43

Task 43:

Here are some project sites:

http://www.arduino.cc/playground/Projects/ArduinoUsers

This project site is on the official Arduino website.

http://hacknmod.com/hack/top-40-arduino-projects-of-the-web/

This project site gives a list of 40 top arduino projects.

http://www.practicalarduino.com/projects

This project site has a few interesting projects.

http://www.arduinoprojects.com/

This project site is an open venue for you to put your own projects and get comments from other Arduino users.

Task 42

Task 42:


Here are some Bulletin Board rules:

  •  You may not use this Bulletin Board to post any material which is knowingly false, abusive, hateful, harassing, obscene, threatening, invasive of a person's privacy, or otherwise violating any law.
  • You may not post any copyrighted material, unless the copyright is owned by you or with permission of the copyright owner.
  • Posts that are solely aimed at instigating fights, insulting or discriminating will be removed and will lead to a ban.
  • Do not start a new thread when there is already a thread on the same topic.

Task 41

Task 41:

Here is a screenshot of the registration process for the YaBB:



Saturday, May 8, 2010

Tasks 38 and 39

Task 38:

const int photocellPin = 0;
const int buttonPin = 2;

int photocellReading;
int buttonState;

void setup()
{
  Serial.begin(9600);
  pinMode(buttonPin,INPUT);
}

void loop()
{
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH)
  {
    photocellReading = analogRead(photocellPin);
    Serial.println(photocellReading);
    delay(1000);
  }
delay(250);
}


Task 39:

const int photocellPin = 0;
const int buttonPin = 2;

int photocellReading;
int buttonState;
int readCount = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(buttonPin,INPUT);
}

void loop()
{
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH)
  {
    photocellReading = analogRead(photocellPin);
    readCount++;
    Serial.print("Reading number ");
    Serial.print(readCount);
    Serial.print(" is ");
    Serial.println(photocellReading);
    delay(1000);
  }
delay(250);
}

Thursday, May 6, 2010

Tasks 34, 35, 36 and 37

Task 34:

int ranNum;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  for (int count = 1; count <101; count++)
  {
  ranNum = random(10);
  Serial.println(ranNum);
  delay(500);
  }
  delay(5000);
}


Task 35:

int ranNum;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  for (int count = 1; count <101; count++)
  {
  ranNum = random(10);
  Serial.print(count);
  Serial.print(".");
  Serial.print(ranNum);
  Serial.println();
  delay(500);
  }
  delay(5000);
}


Task 36:

int ranNum;
int total;
int average;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  total = 0;
  for (int count = 1; count <101; count++)
  {
  ranNum = random(10);
  Serial.print(count);
  Serial.print(".");
  Serial.print(ranNum);
  Serial.println();
  total = (total + ranNum);
  delay(500);
  }
  average = (total / 100);
  Serial.print("The average of these random numbers is ");
  Serial.print(average);
  Serial.println();
  delay(5000);
}


Task 37:

After playing around with the baud rate: I found that, when I set it to 300, i could see each character printed on the serial monitor seperately. When i set it to the maximum of 115200 it was incredibly fast, but i didnt even see any data flow errors.

Monday, May 3, 2010

Tasks 30, 31 and 32

Task 30:

const int buttonPin = 2;
const int LEDPin = 13;

int buttonState = 0;

void setup ()
{
  pinMode (LEDPin, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop ()
{
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH)
  {
  digitalWrite(LEDPin, HIGH);

  }

  else
  {
  digitalWrite(LEDPin, LOW);
  }
}


Task 31:

const int buttonPin = 2;
const int LEDPin = 13;

int buttonState = 0;

void setup ()
{
  pinMode (LEDPin, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop ()
{
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH)
  {
  digitalWrite(LEDPin, LOW);
  }

  else
  {
  digitalWrite(LEDPin, HIGH);
  }
}


Task 32:


const int buttonPin = 2;
const int LEDPin = 13;

int buttonState = 0;

void setup ()
{
  Serial.begin(9600);
  pinMode (LEDPin, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop ()
{
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH)
  {
  digitalWrite(LEDPin, HIGH);
  Serial.println("Button Pressed - LED On");
  }

  else
  {
  digitalWrite(LEDPin, LOW);
  Serial.println("Button Not Pressed - LED Off");
  }
}

Sunday, May 2, 2010

Task 28

Task 28:

int photocellPin = 0;     // the cell and 10K pulldown are connected to a0
int photocellReading;     // the analog reading from the sensor divider
int LEDpin = 11;          // connect Red LED to pin 11 (PWM pin)
int LEDbrightness;        //
void setup(void) {
  // We'll send debugging information via the Serial monitor
  Serial.begin(9600);  
}

void loop(void) {
  photocellReading = analogRead(photocellPin); 
 
  Serial.print("Analog reading = ");
  Serial.println(photocellReading);     // the raw analog reading
 
  // LED gets brighter the darker it is at the sensor
  // that means we have to -invert- the reading from 0-1023 back to 1023-0
  photocellReading = 1023 - photocellReading;
  //now we have to map 0-1023 to 0-255 since thats the range analogWrite uses
  LEDbrightness = map(photocellReading, 0, 1023, 0, 255);
  analogWrite(LEDpin, LEDbrightness);
 
  delay(100);
}

Tasks 26 and 27

Task 26:

int photocellPin = 0;     // the cell and 10K pulldown are connected to a0
int photocellReading;     // the analog reading from the analog resistor divider

void setup(void) {
  // We'll send debugging information via the Serial monitor
  Serial.begin(9600);  
}

void loop(void) {
  photocellReading = analogRead(photocellPin); 
 
  Serial.print("Analog reading = ");
  Serial.print(photocellReading);     // the raw analog reading
 
  // We'll have a few threshholds, qualitatively determined
  if (photocellReading < 10) {
    Serial.println(" - Dark");
  } else if (photocellReading < 200) {
    Serial.println(" - Dim");
  } else if (photocellReading < 500) {
    Serial.println(" - Light");
  } else if (photocellReading < 800) {
    Serial.println(" - Bright");
  } else {
    Serial.println(" - Very bright");
  }
  delay(1000);
}


Task 27:

int photocellPin = 0;     // the cell and 10K pulldown are connected to a0
int photocellReading;     // the analog reading from the analog resistor divider
int ledPin13 = 13;
int ledPin12 = 12;
int ledPin11 = 11;
int ledPin10 = 10;
int counter;

void setup(void) {
  // We'll send debugging information via the Serial monitor
  Serial.begin(9600);
  pinMode(ledPin13, OUTPUT);
  pinMode(ledPin12, OUTPUT);
  pinMode(ledPin11, OUTPUT); 
  pinMode(ledPin10, OUTPUT);
}

void loop(void) {
  photocellReading = analogRead(photocellPin); 
 
  Serial.print("Analog reading = ");
  Serial.print(photocellReading);     // the raw analog reading
 
  // We'll have a few threshholds, qualitatively determined
  if (photocellReading < 10) {
    Serial.println(" - Dark");
  } else if (photocellReading < 200) {
    //Serial.println(" - Dim");
    digitalWrite(ledPin13, HIGH);
    //delay(1000);
    digitalWrite(ledPin12, LOW);
    digitalWrite(ledPin11, LOW);
   for(counter = 1; counter < 50; counter++) {
    digitalWrite(ledPin13, HIGH);
    digitalWrite(ledPin10, HIGH);
    digitalWrite(ledPin13, LOW);
    digitalWrite(ledPin13, LOW);}
  } else if (photocellReading < 500) {
    //Serial.println(" - Light");
    digitalWrite(ledPin12, HIGH);
    //delay(1000);
    digitalWrite(ledPin11, LOW);
    digitalWrite(ledPin13, LOW);
  } else if (photocellReading < 800) {
    //Serial.println(" - Bright");
    digitalWrite(ledPin11, HIGH);
    //delay(1000);
    digitalWrite(ledPin12, LOW);
    digitalWrite(ledPin13, LOW);
  } else {
    //Serial.println(" - Very bright");
  }
  delay(0);
}

Saturday, May 1, 2010

Arduino - Key Words

Here are some key words used in the arduino environment:

analogRead() - Reads the value from the specified analog pin.

digital Read() - Reads the value from a specified digital pin, either HIGH or LOW.

loop() - Does precisely what its name suggests, and loops consecutively.

pinMode() - Configures the specified pin to behave either as an input or an output.

Serial.print() - Prints data to the serial port as human-readable ASCII text.

Serial.println() - Prints data to the serial port as human-readable ASCII text followed by a carriage return character (ASCII 13, or '\r') and a newline character (ASCII 10, or '\n').

setup() - initializes variables, pin modes, starts using libraries, etc.

Task 24 - Ladyada

Ladyada is a great site to go to, to learn how to use some of the components available for the Arduino.

http://www.ladyada.net/

Friday, April 30, 2010

Minor Project - LED Binary Clock Intentions

For my Minor Project, I intend to build the rest of the LED Binary Clock. This will mean using three shift registers to control 20 LEDs seperately. Also, if i can, i will try to program it so that i will be able to set the time on the clock using three push buttons.

Thursday, April 29, 2010

Tasks 21, 22 and 23

Task 21:

int del = 200;
int LEDPin = 13;
void setup()
{
  Serial.begin(9600);
  pinMode(LEDPin, OUTPUT);
}

void loop()
{
  digitalWrite(LEDPin, HIGH);
  Serial.println("Blink");
  delay(del);
  digitalWrite(LEDPin, LOW);
  delay(del);
}


Task: 22

int del = 200;
int LEDPin2 = 2;
int LEDPin3 = 3;
void setup()
{
  Serial.begin(9600);
  pinMode(LEDPin2, OUTPUT);     
  pinMode(LEDPin3, OUTPUT);
}

void loop()
{
  digitalWrite(LEDPin2, HIGH);  
  Serial.write("Red ");
  delay(del);                 
  digitalWrite(LEDPin2, LOW);
  delay(del);

  digitalWrite(LEDPin3, HIGH);
  Serial.print("Yellow");
  delay(del);
  digitalWrite(LEDPin3, LOW);
  delay(del);
  Serial.println();
}


Task 23:

I was unable to edit the Wikieducator page so i shall just show my version of the Arduino here.


    Arduino Nano:

 










For more information see http://www.arduino.cc/en/Main/ArduinoBoardNano.

Tasks 19 and 20

Task 19:

int LEDPin = 13;
int delvar; //This variable changes the speed of the LEDPin2 LED.
void setup()
{
  pinMode(LEDPin, OUTPUT);     
}

void loop()
{
  for (int count = 1; count < 11; count++)
  {
    delvar = (count * 100);
    digitalWrite(LEDPin, HIGH);  
    delay(delvar);                 
    digitalWrite(LEDPin, LOW);
    delay(delvar);
  } 
}


Task 20:

int LEDPin = 13;
int delvar; //This variable changes the speed of the LEDPin2 LED.
void setup()
{
  pinMode(LEDPin, OUTPUT);     
}

void loop()
{
  for (int count = 1; count < 101; count++)
  {
    delvar = (count * 10);
    digitalWrite(LEDPin, HIGH);  
    delay(delvar);                 
    digitalWrite(LEDPin, LOW);
    delay(delvar);
  } 
  for (int count = 100; count > 0; count--)
  {
    delvar = (count * 10);
    digitalWrite(LEDPin, HIGH);  
    delay(delvar);                 
    digitalWrite(LEDPin, LOW);
    delay(delvar);
  }
}