Monday, June 21, 2010

Task 51 - 59: EEPROM

The Arduino contains a small amount of storage called EEPROM, this storage is available for the program to store and retrieve data.

below is my program to read tempeture and save it to the EEPROM then read it when needed.

#include <math.h>
#include <EEPROM.h>

#define DELAY (2 * 60) //(mins * seconds)

int value = 0;

double Thermister(int RawADC) {
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp - 273.15; // Convert Kelvin to Celcius
return Temp;
}

void delaySeconds(int delaytime = 0) {
for(int i = 0; i <= delaytime; i++){
delay(1000);
}
}

void setup() {
Serial.begin(9600);
Serial.println("Would you like to record temperatures? (y/N)");
do {;} while(Serial.available() <= 0); // Check for iput from serial
if((char)Serial.read() == (char)'y')
{
for(int i = 0; i < 512; i++) {
Serial.print("Reading temperatures, please wait : #");
Serial.println(i);
EEPROM.write(i, int(Thermister(analogRead(0))));
delaySeconds(DELAY);
}
}
for(int i = 0; i < 512; i++) {
value = EEPROM.read(i);

Serial.print(i);
Serial.print("\t");
Serial.print(value);
Serial.println();
}
}

void loop() {
}

Monday, May 3, 2010

Task 46: Sending from one arduino to another

Simple answer, using IR as a means with the RX/TX (Serial) we can send data like a tv remote.

Task 41: Register on Arduino forums



Getting ready to annoy some people :)

Task 40: News Feed



A cheaper version of the Wi-Fi sheild, i'm keen to learn more about wireless communication and the arduino.

Task 34: 100 Random Numbers

int min = 1;
int max = 100;
int randNumber = 0;

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

void loop() {
for(int i = 0; i >= 100; i++) {
randNumber = random(300);
Serial.println(randNumber);
}
}

Task 30: Push Button

/*
Button

Turns on and off a light emitting diode(LED) connected to digital
pin 13, when pressing a pushbutton attached to pin 7.


The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground

* Note: on most Arduinos there is already an LED on the board
attached to pin 13.


created 2005
by DojoDave
modified 17 Jun 2009
by Tom Igoe

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/Button
*/

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}

Task 29: Arduino resources.

One great website i have found so far is http://freeduino.org, it has a LRAGE list of things being done on and with the arduino from simple LEDs to SMS with cellphones, take a look...

Task 26: Photocell Program

/* Photocell simple testing sketch.

Connect one end of the photocell to 5V, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground
Connect LED from pin 11 through a resistor to ground
For more information see www.ladyada.net/learn/sensors/cds.html */

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

This program reads the amount of light shining on the LDR/Photocell and sends it to the serial port so the human can read it

Task 23: How many Arduino's are there?

check out wikieducator.org page with just some of the few arduino types listed

Task 21: Blink with Serial output

int ledPin = 13; // LED pin
int del = 200; // Starting Delay

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
Serial.begin(9600); // Start serial connection
Serial.println('Ready'); // let the human know the machine is ready
}

void loop() {
Serial.println('Blink'); write to the serial port
digitalWrite(ledPin, HIGH); // set the LED on
delay(del);
digitalWrite(ledPin, LOW); // set the LED off
delay(del);
}

Task 20: from 10ms to 1 sec then back down again

int ledPin = 13; // LED pin
int del = 10; // Starting Delay
bool dirUp = false; // are we increasing or decreasing

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
}

void loop() {
digitalWrite(ledPin, HIGH); // set the LED on
delay(del); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(del); // wait for a second
if( dirUp ) {
if((del++) == 1001) {
del = 1000;
dirUp = false;
}
} else {
if((del--) == 9) {
del = 10;
dirUp = true;
}
}
}

Task 19: blinking from 100ms to 1sec.

int ledPin = 13; // LED pin
int del = 100; // Starting Delay

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
}

void loop() {
digitalWrite(ledPin, HIGH); // set the LED on
delay(del); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(del); // wait for a second
if((del++) == 1001) { del = 100; }
}

Task 17: for-loop and 5 blinks then 1

int ledPin[2] = {13, 12}; // array of LEDs
int del = 500; // Delay
int led = 0; // which LED is to be turned on

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin[0], OUTPUT);
pinMode(ledPin[1], OUTPUT);
}

void loop()
{
for(int i = 0; i >= 5; i++) {
digitalWrite(ledPin[1], HIGH); // set the LED on
delay(del); // wait for a second
digitalWrite(ledPin[1], LOW); // set the LED off
delay(del); // wait for a second
}
digitalWrite(ledPin[0], HIGH); // set the LED on
delay(del); // wait for a second
digitalWrite(ledPin[0], LOW); // set the LED off
delay(del); // wait for a second
}

Tuesday, March 16, 2010

Arduino Keywords

setup()
This is the function that tells the arduino how to set its self up.

loop()
This is what the arduino is to do while it is running.

analogRead(pinnumber)
read an analog value (0 -> 1023) from the pinnumber given

Serial.print()
print ASCII to the serial

Serial.println()
Print ASCII to the serial port but also add a line break after

pinMode(pinnumber, mode)
pinnumber = the number of the digital pin on the arduino board.
mode = Can be ether 'INPUT' for receving data or 'OUTPUT' for sending data.

digitalRead(pinnumber)
pinnumber = the number of the digital pin on the arduino board.

Task 11 & 12 - Blink2 (Controlling 2 blinking LEDs)

/*
Blink2
Turns on a LED on for half a second, then off for half a second, repeatedly. It also does the same to an off-board LED connected to pin 12 so that when one LED is on the other is off.
The circuit:
* LED connected from digital pin 13 to ground via resistor.
* second LED connected from digital pin 12 to ground via resistor. I used 330 ohms.
* Note: On most Arduino boards, there is already an LED on the board
connected to pin 13.
Created 1 June 2005
By David Cuartielles. Adapted by Peter Brook

based on an orginal by H. Barragan for the Wiring i/o board
*/

int ledPin = 13; // LED connected to digital pin 13
int redLedPin = 12; // LED connected to digital pin 13
int del =500;

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
digitalWrite(redLedPin, LOW); // set the LED on
delay(del); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
digitalWrite(redLedPin, HIGH); // set the LED off
delay(del); // wait for a second
}

Task 10 - Blink at 10ms

/*
Blink

Turns on an LED on for half a second, then off for one second, repeatedly.

http://arduino.cc/en/Tutorial/Blink

based on an orginal by H. Barragan for the Wiring i/o board and Blink by David Cuartielles

*/

int ledPin = 13; // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(10);
digitalWrite(ledPin, LOW); // set the LED off
delay(10);
}

Task 9 - Blink while LED is off longer then it is on

/*
Blink

Turns on an LED on for half a second, then off for one second, repeatedly.

http://arduino.cc/en/Tutorial/Blink

based on an orginal by H. Barragan for the Wiring i/o board and Blink by David Cuartielles

*/

int ledPin = 13; // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(500); // wait half a second
digitalWrite(ledPin, LOW); // set the LED off
delay(1000); // wait for a second
}

Task 8 - Blink while LED is on longer then the off time

/*
Blink

Turns on an LED on for one second, then off for half a second, repeatedly.

http://arduino.cc/en/Tutorial/Blink

based on an orginal by H. Barragan for the Wiring i/o board and Blink by David Cuartielles

*/

int ledPin = 13; // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(500); // wait half a second
}

Tuesday, March 9, 2010

LED Mono Color Matrix Completed





















This is my home made board for my LED Matrix, its a 5x5 grid of Green LEDs, now i can move on and start the programming.

LED Assignment

My LED assignment is a martix, using a 5x5 grid of Green LEDs i will make a simple pattern turning LEDs on and off using the arduino