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

Arduino Lab 6: Light Sensor

Purpose:
This lab will teach you how to change one LED's brightness according the level of light that is hitting the light sensor.

Equipment:
-1 light sensor
-1 10k ohm resistor
-1 LED (any colour)
-330 ohm resistor
-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 25 min

Results:
-There were no issues and it worked completely fine

Photo/Video:




Program:
int lightPin = 0;
int ledPin = 9;
void setup()
{
  pinMode (ledPin, OUTPUT);
}
void loop()
{
  int lightLevel = analogRead(lightPin);
  lightLevel = map(lightLevel, 0, 900, 0, 255);
  lightLevel = constrain(lightLevel, 0, 255);
  analogWrite(ledPin, lightLevel);
}

Program Modifications:
-There were none

Helpful Tips:
-Check spelling/spacing

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

Sunday 22 November 2015

Arduino Lab 3: Button Control

Purpose:
This lab will teach you how to control LED lights using buttons.

Equipment:
-2 push buttons
-1 330 ohm resistor
-2 10k ohm resistors
-1 LED
-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 issues with spacing but after I fixed them it worked completely fine.

Photo/Video:
                       

Program:
const int buttonPin = 2;
const int ledPin = 9;

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

Program Modifications:
-There were none; I followed all the instructions

Helpful Tips:
-Check spacing
-Check all the parts on the breadboard

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