Tuesday 8 December 2015

Arduino Challenge 7: Buzzer (Make Your Own Challenge)

Challenge Name: Buzzer & Light Sensor

Author: Christina He

Credit: New Innovators.com Lab 7

Time to Complete: Approximately 10 min

Difficulty Level: Level 1

Challenge Description: Make a program that the buzzer will sing "Ode To Joy".

Answer:

Code

int speakerPin = 9;
int length = 15;
char notes[] = "eefggfedccdeeddeefggfedccdedcc ";
int beats[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1 , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1 ,1 };
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);
      delay(2000);
    }
  }
}
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);
  }

}

Visual Answer




Arduino Challenge 6: Light Sensor (Make Your Own Challenge)

Challenge Name: Light Sensor & RGB LED

Author: Christina He

Credit: New Innovators: Lab 6

Difficulty Level: Level 5

Time to Complete: Approximately 35 minute

Challenge Description: Make the RGB LED change colours using the light sensor. When the light sensor is covered, the RGB will switch to red (pink) and green from blue. When the light sensor is released, the RGB will switch back and stay at blue.

Answer:

Code

int lightPin = 0;
int redrgb = 11;
int greenrgb = 10;
int bluergb = 9;

void setup()
{
  pinMode (redrgb, OUTPUT);
  pinMode(greenrgb, OUTPUT);
  pinMode(bluergb, OUTPUT);
}
void loop()
{
  int lightLevel = analogRead(lightPin);
  lightLevel = map(lightLevel, 0, 900, 0, 255);
  lightLevel = constrain(lightLevel, 0, 255);
  analogWrite(redrgb, lightLevel);
  delay(100);
  analogWrite(greenrgb,lightLevel);
  delay(100);
  analogWrite(bluergb, lightLevel);
  delay(100);
}

Visual Answer



(colours not showing up properly, but the order is: blue, red(pink), green, and back to blue)

Arduino Challenge 5: RGB LED (Make Your Own Challenge)

Challenge Name: RGB LED & Potentiometer

Author: Christina He

Credit: New Innovatos: Lab 5

Difficulty: Level 3

Time to Complete: Approximately 40 min

Challenge Description: Make the RGB LED to change colours when twisting the potentiometer.

Answer:

Code

const int red= 9;
const int green= 10;
const int blue= 11;
const int pot= A0;

const int distime= 100;

void setup()
{
  pinMode(pot, INPUT);
}

void loop()
{
  int a=analogRead(pot)/63.75;
  if (a==4)
  {
    analogWrite(green,255);
    delay(distime);
    analogWrite(green,0);
  }
  else if (a==3)
  {
    analogWrite(blue, 255);
    delay(distime);
    analogWrite(blue,0);
  }
  else
  {
    analogWrite (red,255);
    delay(distime);
    analogWrite(red,0);
  }

}

Visual Answer







Arduino Lab 4 Potentiometer (Twist Plot): Mandatory Challenge Completed

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

Code:

int sensorPin = A0;
int ledPins[] = {6,9,10,11};

void setup()
{
  pinMode(sensorPin,INPUT);
  pinMode(ledPins[1,2,3,4], OUTPUT);
}
void loop()
{
  int a = analogRead(sensorPin)/63.75;
  if (a == 4)
  {
    for (int i = 0; i<5; i+=1)
    {
      analogWrite(ledPins[i], HIGH);
      delay(100);
    }
  }
  else if (a == 3)
  {
    for (int t = 0; t<4; t+=1)
    {
      analogWrite(ledPins[t], HIGH);
      delay(100);
    }
  }
  else if (a == 2)
  {
    for (int x=0; x<3; x+=1)
    {
      analogWrite(ledPins[x], HIGH);
      delay(100);
    }
  }
  else if (a ==1)
  {
    for (int y=0; y<2; y+=1)
    {
      analogWrite(ledPins[y],HIGH);
      delay(100);
    }
  }
  else
  {
    for (int g=0; g<5; g+=1)
    {
      digitalWrite(ledPins[g], LOW);
    }
  }
}

Visual Evidence:







Arduino Challenge 4: Potentiometer (Make Your Own Challenge)

Challenge Name: Poteniometer & LED Brightness

Author: Christina He

Credit: New Innovators.ca Lab 4

Difficulty Level: Level 2

Time to Complete: Approximately 30 min

Challenge Description: Make one LED to blink with different levels of brightness by twisting the potentiometer.

Answer:

Code

int ledPin = 13;
int value = 0;
void setup()
{
  pinMode (ledPin , OUTPUT);
  pinMode(sensorPin, INPUT);
}
void loop()
{
  value = analogRead(sensorPin);
  analogWrite(ledPin , value);
  delay(100);

}

Visual Answer




Arduino Lab 3 Button Control: Mandatory Challenge Completed (part 1&2)

The following code is what I wrote for Arduino Lab 3 mandatory challenge. Visual evidence are also provided.

Code:

(part 1)
int led1 = 0;
int led2 = 1;
int led3 = 2;
int led4 = 3;

int button1 = 8;
int button2 = 9;

void setup()
{
  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
  pinMode(led3,OUTPUT);
  pinMode(led4,OUTPUT);
  pinMode(button2,INPUT);
  pinMode(button1,INPUT);
}

void loop()
{
  int delaytime = 500;
  if (digitalRead(button1) == HIGH)
  {
    digitalWrite(led2,HIGH);
    digitalWrite(led4,HIGH);
    delay(delaytime);
    digitalWrite(led2,LOW);
    digitalWrite(led4,LOW);
 
  }
  else if (digitalRead(button2) == HIGH)
  {
    digitalWrite(led1,HIGH);
    digitalWrite(led3,HIGH);
    delay(delaytime);
    digitalWrite(led1,LOW);
    digitalWrite(led3,LOW);
  }
  else if (digitalRead(button1) == LOW)
  {
    digitalWrite(led2, LOW);
    digitalWrite(led4, LOW);
  }
  else if (digitalRead(button2)==LOW)
  {
    digitalWrite(led1,LOW);
    digitalWrite(led3,LOW);
  }
  else
  {
    digitalWrite(led1,LOW);
    digitalWrite(led2,LOW);
    digitalWrite(led3,LOW);
    digitalWrite(led4,LOW);
  }
}


(part 2)

int leds[] = {0,1,2,3};
int counter = 0;
int buttons[] = {8,9};

void setup()
{
  for (int a=0; a<5; a+=1)
  {
    pinMode(leds[a],OUTPUT);
  }
  pinMode(8,INPUT);
  pinMode(9,INPUT);
}

void loop()
{
  digitalWrite(0,LOW);
  digitalWrite(1,LOW);
  digitalWrite(2,LOW);
  digitalWrite(3,LOW);
  if (digitalRead(8) == HIGH)
  {
    int counter = counter + 1;
    digitalWrite(0, HIGH);
    digitalWrite(1, HIGH);
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    delay(4000);
    digitalWrite(0,LOW);
    digitalWrite(1,LOW);
    digitalWrite(2,LOW);
    digitalWrite(3,LOW);
  }
  if (digitalRead(9) == HIGH)
  {
    digitalWrite(leds[counter],HIGH);
  }
}

Visual Evidence:

(part1)





(part 2)






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