Sunday, 6 December 2015

Arduino Challenge 3: Button Control (Make Your Own Challenge)

Challenge Name: Button Control LEDs

Author: Christina He

Credit: New Innovators.ca Lab 3

Difficulty Level: Level 2

Time to Complete: Appro. 30 minute

Challenge Description: Make two LEDs to blink on and off according to the button. When the button is pressed, one LED will turn on while the other will stay off. When the button is released, the LED that was on will turn off, while the other that was off will turn on for one second and then switch back. The program will repeat.

Answer:

Code 

int button = 2;
int led1 = 8;
int led2 = 9;

void setup()
{
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(button, INPUT);
}

void loop()
{
  if (digitalRead(button) == HIGH)
  {
   digitalWrite(led2, LOW);
   digitalWrite(led1, HIGH);
   delay(1000);
  }
  else
  {
    digitalWrite(led1, LOW);
    digitalWrite(led2, HIGH);
    delay(1000);
  }
}

Visual Answer








Thursday, 3 December 2015

Arduino Challenge 2: Multi-LED (Make Your Own Challenge)

Challenge Name: Multi LED

Author: Christina He

Credit: New Innovators.ca Lab 2

Time to Complete: Appro. 30 min

Difficulty Level: Level 3

Challenge Description: Make 5 LEDs to light up in orders: 1, 2, 3, 4, 5. And then light off in orders:                                         5, 4, 3, 2, 1. Then repeat.

Hint: Use for loop to count up and down.

Answer:

Code:

int ledPins[] = {1,2,3,4,5};
void setup()
{
  for(int x=0; x<6;x++)
  {
  pinMode(ledPins[x],OUTPUT);
  }
}
void loop()
{
  int delaytime = 100;
  for(int x=0; x<6; x++)
  {
    digitalWrite (ledPins [x], HIGH);
    delay(delaytime);
  }
  for(int x=5; x>=0; x--)
  {
    digitalWrite (ledPins [x], LOW);
    delay(delaytime);
  }
}

Visual Answer:





Wednesday, 2 December 2015

Arduino Lab 2 Multi LED: Mandatory Challenge Completed

The following code is what I wrote to complete Arduino Lab 2 mandatory challenge. Visual evidence are also provided.

Code:

int ledPins[] = {1,2,3,4,5,6};
void setup()
{
  for(int x=0; x<7;x++)
  {
  pinMode(ledPins[x],OUTPUT);
  }
}
void loop()
{
  int delaytime = 800;
  for(int x=0; x<=6; x+=2)
  {
    digitalWrite (ledPins [x], HIGH);
    delay(delaytime);
  }
  for(int x=1; x<=5; x+=2)
  {
    digitalWrite (ledPins [x], HIGH);
    delay(delaytime);
  }
  for(int x=6; x>=0; x-=2)
  {
    digitalWrite (ledPins [x], LOW);
    delay(delaytime);
  }
  for(int x=5; x>=1; x-=2)
  {
    digitalWrite (ledPins [x], LOW);
    delay(delaytime);
  }
}

Visual Evidence:





Monday, 30 November 2015

Arduino Challenge 1: LED Blinking (Make Your Own Challenge)

Challenge NameLED Bilnking
AuthorChristina He
Credit-New Innovators: Lab 1
Difficulty Level (1-5)Level 2 
Time To CompleteApproximately 15 minutes
Challenge DescriptionMake one LED to blink on low power for two times, wait for 3 seconds, and blink on high power for one time. The LED will blink continuously.
HintEvery second is 1000 for delay function
Answer
Code:

int ledPin = 13; 

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

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

}

Photos:

























Thursday, 26 November 2015

Arduino Lab 7: Buzzer

Purpose:
This lab will teach you how to make music with piezo element.

Equipment:
-1 piezo element 
-1 wire (any colour) 
-2 wires (black) 
-1 Arduino UNO 
-1 breadboard 
-1 USB cable

Program Details:
-Download Arduino here

Time to Program and Complete:
-Approximately 30 min

Results:
-The pins under the buzzer were not in the correct holes, but after I fixed them the buzzer made music

Photo/Video:



Program:
int speakerPin = 9;
int length = 15; 
char notes[] = "ccggaagffeeddc ";
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;
void playTone(int tone, int duration) 
{
  for (long i = 0; i < duration * 1000L; i += tone * 2)
  {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
  }
}
void playNote(char note, int duration)
{
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
  for (int i = 0; i < 8; i++)
  {
     if (names[i] == note) 
    {
      playTone(tones[i], duration);
    }
  }
}
void setup()
{
  pinMode(speakerPin, OUTPUT);
}
void loop()
{
  for (int i = 0; i < length; i++)
  {
    if (notes[i] == ' ') 
    {
      delay(beats[i] * tempo);
    }
    else
    {
      playNote(notes[i], beats[i] * tempo);
     }
    delay(tempo / 2);
  }
}

Program Modifications:
-There were none

Helpful Tips:
-Check all the parts inserted

References:
-Arduino website: arduino.cc
-New Innovators: Lab 7

Wednesday, 25 November 2015

Arduino Lab 4: Potentiometer (Twist Pot)

Purpose:
This lab will teach you how to make one LED blink faster or slower when you turn the potentiometer.
Modified: The modified version will make the LED fade when you turn the potentiometer.

Equipment:
-1 potentiometer (10k ohms)
-1 330 ohm resistor
-1 LED (any colour)
-1 wire (red)
-1 wire (black)
-4 wires (any colour) 
-1 USB cable 
-1 breadboard 
-1 Arduino UNO

Program Details:
-Download Arduino here

Time to Program and Complete:
-Approximately 35 min (for 2 parts)

Results:
-There were some spelling mistakes in the code, but after I fixed them it worked completely fine.

Photo/Video:




Modified Program






Program:
int sensorPin = A0;
int ledPin = 13;
int sensorValue = 0;
void setup()
{
  pinMode (ledPin , OUTPUT);
}
void loop()
{
  sensorValue = analogRead(sensorPin);
  digitalWrite(ledPin , HIGH);
  delay(sensorValue);
  digitalWrite(ledPin, LOW);
  delay(sensorValue);
}

Program Modifications:
--Modified version-- To make the LED fade when we turn the potentiometer.

int sensorPin = A0;
int ledPin = 9;
int senorValue = 0;
void setup()
{
  pinMode(ledPin, OUTPUT);
}
void loop()
{
  int value = analogRead(sensorPin) / 4;
  analogWrite (ledPin, value);
}

Helpful Tips:
-Check spelling

References:
-Arduino website: arduino.cc 
-New Innovator: Lab 4

Arduino Lab 5: RGB LED

Purpose:
This lab will teach you how to make one RBG LED to change colours.

Equipment:
-1 RGB LED (common anode) 
-3 330 ohm resistors 
-1 wire (red) 
-1 wire (black) 
-4 wires (any colour) 
-1 Arduino UNO 
-1 breadboard 
-1 USB cable

Program Details:
-Download Arduino here

Time to Program and Complete:
-Approximately 30 min

Results:
-There were some spelling and spacing errors, but after they were fixed the Arduino worked completely fine

Photo/Video:





Program:
const int RED_LED_PIN = 9;
const int GREEN_LED_PIN = 10;
const int BLUE_LED_PIN = 11;

int redIntensity = 0;
int greenIntensity = 0;
int blueIntensity = 0;

const int DISPLAY_TIME = 100;

void setup()
{
}

void loop()
{
  for (greenIntensity = 0; greenIntensity <= 255; greenIntensity +=5)
  {
        redIntensity = 255-greenIntensity;
        analogWrite(GREEN_LED_PIN, greenIntensity);
        analogWrite(RED_LED_PIN, redIntensity);
        delay(DISPLAY_TIME);
  }
  for (blueIntensity = 0; blueIntensity <= 255; blueIntensity +=5)
  {
        greenIntensity = 255-blueIntensity;
        analogWrite(BLUE_LED_PIN, blueIntensity);
        analogWrite(GREEN_LED_PIN, greenIntensity);
        delay(DISPLAY_TIME);
  } 
  for(redIntensity = 0; redIntensity <= 255; redIntensity +=5) 
  { 
        blueIntensity = 255-redIntensity;
        analogWrite (RED_LED_PIN, redIntensity);
        analogWrite (BLUE_LED_PIN, blueIntensity);
        delay(DISPLAY_TIME);
  }
}

Program Modifications:
-There were none

Helpful Tips:
-Check spacing/spelling

References:
-Arduino website: arduino.cc
-New Innovators: Lab 5