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/