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

Saturday, April 17, 2010

LED Binary 60 Seconds 2.0 - refined code

I have done some research and have  found a much simpler yet more complex code to out put exactly the same pattern with seven LEDs.

Here is the new code:

const int nbr10SecBits = 3;  //10 seconds' number of pins.
const int first10SecPin = 2;  //First 10 seconds pin.

const int nbr1SecBits = 4;  //1 seconds' number of pins.
const int first1SecPin = 8;  //First 1 seconds pin.

// 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()
{
  Serial.begin(9600);
  for(int i=0; i < nbr10SecBits; i++)
    pinMode(i+first10SecPin, OUTPUT);
  for(int i=0; i < nbr1SecBits; i++)
    pinMode(i+first1SecPin, OUTPUT);   
}

void loop()
{
  unsigned long time = millis() / 1000;
  int tenSeconds = ((numberOfSeconds(time) - (numberOfSeconds(time) % 10))/ 10);
  int oneSeconds = numberOfSeconds(time) % 10 ;

  showBinary(tenSeconds,nbr10SecBits,first10SecPin);
  showBinary(oneSeconds,nbr1SecBits,first1SecPin);
 
  Serial.print(numberOfSeconds(time));
  Serial.print(tenSeconds);
  Serial.print(oneSeconds);
  Serial.println();
  delay(1000);
}

// this function sets the pins starting from firstPin to the binary value of the given number
void showBinary( int number, int nbrPins, int firstPin)
{
  for(int bit=0; bit < nbrPins; bit++)
  {
    boolean isBitSet =  bitRead(number, bit); // isBitSet will be true if given bit is set in this channel
    digitalWrite(bit + firstPin, isBitSet);
  } 
}

Saturday, April 10, 2010

For Loop: Task 17 and 18

This is the code i wrote for Task 17. It makes one LED blink 5 times and then another to blink once.

int del = 500;
int LEDPin2 = 2;
int LEDPin3 = 3;
void setup()
{
pinMode(LEDPin2, OUTPUT);
pinMode(LEDPin3, OUTPUT);
}

void loop()
{
for (int count = 1; count < 6; count++)
{
digitalWrite(LEDPin2, HIGH);
delay(del);
digitalWrite(LEDPin2, LOW);
delay(del);
}
digitalWrite(LEDPin3, HIGH);
delay(del);
digitalWrite(LEDPin3, LOW);
delay(del);
}


This is the code I wrote for task 18. This is like the code from 17 but there is a variable that is used to change the amount of times the first LED blinks.

int del = 500;
int LEDPin2 = 2;
int LEDPin3 = 3;
int countnum = 5; //This variable changes the amout of times the LEDPin2 LED blinks.
void setup()
{
pinMode(LEDPin2, OUTPUT);
pinMode(LEDPin3, OUTPUT);
}

void loop()
{
for (int count = 1; count < (countnum + 1); count++)
//For Loop uses the variable countnum to determine the duration of the loop.
{
digitalWrite(LEDPin2, HIGH);
delay(del);
digitalWrite(LEDPin2, LOW);
delay(del);
}
digitalWrite(LEDPin3, HIGH);
delay(del);
digitalWrite(LEDPin3, LOW);
delay(del);
}

Monday, March 15, 2010

Blink 2: Tasks 11 - 16

This the original Blink 2 program (Task 11):

int ledPin13 = 13;
int ledPin12 = 12;
int del = 500;


void setup() {
pinMode(ledPin13, OUTPUT);
pinMode(ledPin12, OUTPUT);
}

void loop()
{
digitalWrite(ledPin13, HIGH);
digitalWrite(ledPin12, LOW);
delay(del);
digitalWrite(ledPin13, LOW);
digitalWrite(ledPin12, HIGH);
delay(del);
}


This is a variation where one LED blinks when the other one is off (Task 12):

int ledPin13 = 13;
int ledPin12 = 12;
int del = 500;


void setup() {
pinMode(ledPin13, OUTPUT);
pinMode(ledPin12, OUTPUT);
}

void loop()
{
digitalWrite(ledPin12, LOW);
delay(del);
digitalWrite(ledPin13, LOW);
delay(del);
digitalWrite(ledPin13, HIGH);
delay(del);
digitalWrite(ledPin13, LOW);
delay(del);
digitalWrite(ledPin12, LOW);
delay(del);
digitalWrite(ledPin12, HIGH);
delay(del);
}


This is a variation where one LED is mostly on, and the other mostly off (Task 13):

int ledPin13 = 13;
int ledPin12 = 12;
int del = 1000;


void setup() {
pinMode(ledPin13, OUTPUT);
pinMode(ledPin12, OUTPUT);
}

void loop()
{
digitalWrite(ledPin13, HIGH);
digitalWrite(ledPin12, LOW);
delay(del);
digitalWrite(ledPin13, LOW);
digitalWrite(ledPin12, HIGH);
delay(del/10);
}


This variation is like the last, but the LEDs are reversed (Task 14):

int ledPin13 = 13;
int ledPin12 = 12;
int del = 1000;


void setup() {
pinMode(ledPin13, OUTPUT);
pinMode(ledPin12, OUTPUT);
}

void loop()
{
digitalWrite(ledPin13, HIGH);
digitalWrite(ledPin12, LOW);
delay(del/10);
digitalWrite(ledPin13, LOW);
digitalWrite(ledPin12, HIGH);
delay(del);
}


This is a veriation where one LED blinks twise, then the other one blinks once (Task 16):

int ledPin13 = 13;
int ledPin12 = 12;
int del = 500;


void setup() {
pinMode(ledPin13, OUTPUT);
pinMode(ledPin12, OUTPUT);
}

void loop()
{
digitalWrite(ledPin12, LOW);
digitalWrite(ledPin13, LOW);
delay(del);
digitalWrite(ledPin13, HIGH);
delay(del);
digitalWrite(ledPin13, LOW);
delay(del);
digitalWrite(ledPin13, HIGH);
delay(del);
digitalWrite(ledPin13, LOW);
digitalWrite(ledPin12, LOW);
delay(del);
digitalWrite(ledPin12, HIGH);
delay(del);
}

Sunday, March 7, 2010

LED Binary 60 Seconds Project

For my LED project, i intend to create a binary representation of the seconds of a clock. This will be done by using seven LEDs, set up in two parallel lines -- one line of three, and one line of four. The first line of three LEDs represent the first digit, and the second line of four LEDs represent the second digit. Each LED represents a binary value; starting at the bottom the values are 1, 2, 4 & 8.

Layout:

This is the program i wrote for the project, which shows the sequence of the LEDs turning on:

int ledPin2 = 2;
int ledPin3 = 3;
int ledPin4 = 4;
int ledPin5 = 5;
int ledPin6 = 6;
int ledPin7 = 7;
int ledPin8 = 8;
int del = 970;

void setup() {
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin7, OUTPUT);
pinMode(ledPin8, OUTPUT);
}

void loop()
{

digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
digitalWrite(ledPin6, LOW);
digitalWrite(ledPin7, LOW);
digitalWrite(ledPin8, LOW);
delay(del);

digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, HIGH);
digitalWrite(ledPin6, LOW);
digitalWrite(ledPin7, LOW);
digitalWrite(ledPin8, LOW);
delay(del);

digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, HIGH);
digitalWrite(ledPin5, LOW);
digitalWrite(ledPin6, LOW);
digitalWrite(ledPin7, LOW);
digitalWrite(ledPin8, LOW);
delay(del);

digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, HIGH);
digitalWrite(ledPin5, HIGH);
digitalWrite(ledPin6, LOW);
digitalWrite(ledPin7, LOW);
digitalWrite(ledPin8, LOW);
delay(del);

digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
digitalWrite(ledPin6, LOW);
digitalWrite(ledPin7, LOW);
digitalWrite(ledPin8, LOW);
delay(del);

digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, HIGH);
digitalWrite(ledPin6, LOW);
digitalWrite(ledPin7, LOW);
digitalWrite(ledPin8, LOW);
delay(del);

digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
digitalWrite(ledPin5, LOW);
digitalWrite(ledPin6, LOW);
digitalWrite(ledPin7, LOW);
digitalWrite(ledPin8, LOW);
delay(del);

digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
digitalWrite(ledPin5, HIGH);
digitalWrite(ledPin6, LOW);
digitalWrite(ledPin7, LOW);
digitalWrite(ledPin8, LOW);
delay(del);

digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
digitalWrite(ledPin6, LOW);
digitalWrite(ledPin7, LOW);
digitalWrite(ledPin8, LOW);
delay(del);

digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, HIGH);
digitalWrite(ledPin6, LOW);
digitalWrite(ledPin7, LOW);
digitalWrite(ledPin8, LOW);
delay(del);

digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
digitalWrite(ledPin6, LOW);
digitalWrite(ledPin7, LOW);
digitalWrite(ledPin8, HIGH);
delay(del);

...

}

Videos:






Blink: Tasks 7 - 10

This is the original Blink Program.

int ledPin = 13;

void setup() {

pinMode(ledPin, OUTPUT);
}

void loop()
{
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
} This is a modified version which has the LED is mostly off, only blinking on briefly.

int ledPin = 13;

void setup() {

pinMode(ledPin, OUTPUT);
}

void loop()
{
digitalWrite(ledPin, HIGH);
delay(125);
digitalWrite(ledPin, LOW);
delay(1000);
}


This is a modified version which has the LED mostly on, only turning off briefly.

int ledPin = 13;

void setup() {

pinMode(ledPin, OUTPUT);
}

void loop()
{
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(125);
}


This is a modified version which has the LED blinking at 10ms.

int ledPin = 13;

void setup() {

pinMode(ledPin, OUTPUT);
}

void loop()
{
digitalWrite(ledPin, HIGH);
delay(10);
digitalWrite(ledPin, LOW);
delay(10);
}

(A slight flicker can be seen, but almost unaparent.)

Saturday, March 6, 2010

Saturday, February 27, 2010

Software

Arduino Environment:
This is the software that you use to write the programs for the Arduino. it is also used to upload the programs into the Arduino.

Processing Environment:
This is an open source programming language and environment, used to program images, animation and interactions.

GNU gcc
This is the GNU Compiler Collection, which includes front ends for C, C++, Objective-C, Fortran, Java and Ada.

Wikieducator
This is the website that is run by a global comunity; it is a means to distribute free educational content.

Moodle
This is the platform that the Otago Polytechnic is using instead of Blackboard.

Chip8
This is an emulator created to run old aplications written in the Chip8 programming language.

Fritzing
This is a free application, which can be used to create virtual representations of an arduino circuit layout.

Open Office
This is a free open source suite, which offers a word processor, spreadsheet editor and Presentation creator. It is a lot like Microsoft office, only its free.

PeerWise
This is a website dedicated to enabling students to help themselves and their fellow classmates. PeerWise lets students write their own multi-choice questions and stores them for other students in the same course to use as revision.

Thursday, February 18, 2010

Welcome to Tim Gosling's Embedded Systems Blog

Hello and welcome to my Embedded Systems Blog.


My name is Tim Gosling and i am a BIT student at the Otago Polytechnic.


I am an ExCITSS student, and was awarded Best in CITSS in 2009 from Prosouth.