14 Mart 2015 Cumartesi

Arduino Experiment 3 - RGB Modify

Definition : We change RGB Led's colour by using potentiometer. Changing resistor values gives different colours.

Circuit Diagram



Components

  •         1 x RGB LED
  •            1 x 10kΩ Resistor
  •            Arduino Uno
  •           Wires

Arduino Code
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
 */

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 7;
int led2 = 6;
int led3 = 5;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);  
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(led2, HIGH);
  digitalWrite(led3, HIGH);
}

Video


13 Mart 2015 Cuma

Arduino Experiment 5 - Push Buttons Modify

Circuit Diagram

Definition : In here, we use 2 buttons and 3 function to blink our leds. If left button is pushed, the leds will blink like disco. If right button pushed we have ordered blinking(from left to right) and if both are pushed, three of leds blink at the same time.





Components


  •          5 x 1K resistors
  •          3 x LED
  •          2 x On / Off Buttons
  •          Wires
  •          Arduino Uno


Arduino Code

// First we'll set up constants for the pin numbers.
// This will make it easier to follow the code below.

const int button1Pin = 2;  // pushbutton 1 pin
const int button2Pin = 3;  // pushbutton 2 pin
const int ledPin =  13;    // LED pin
const int ledPin2 = 12;
const int ledPin3 = 11;


void setup()
{
  // Set up the pushbutton pins to be an input:
  pinMode(button1Pin, INPUT);
  pinMode(button2Pin, INPUT);

  // Set up the LED pin to be an output:
  pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin2, OUTPUT);

}


void loop()
{
  int button1State, button2State;  // variables to hold the pushbutton states

  // Since a pushbutton has only two states (pushed or not pushed),
  // we've run them into digital inputs. To read an input, we'll
  // use the digitalRead() function. This function takes one
  // parameter, the pin number, and returns either HIGH (5V)
  // or LOW (GND).

  // Here we'll read the current pushbutton states into
  // two variables:

  button1State = digitalRead(button1Pin);
  button2State = digitalRead(button2Pin);

  if ((button1State == LOW)) {
    for(int i = 2; i>=1; i--) {
    digitalWrite(ledPin, HIGH);  // turn the LED on
    delay(500);
    digitalWrite(ledPin2, HIGH);  // turn the LED
    delay(500);
    digitalWrite(ledPin3, HIGH);  // turn the LED on
    delay(500);
    digitalWrite(ledPin, LOW);  // turn the LED on
    delay(500);
    digitalWrite(ledPin2, LOW);  // turn the LED on
    delay(500);
    digitalWrite(ledPin3, LOW);  // turn the LED on
    delay(500);
       }  
  }    

  if ((button1State == LOW) && (button2State == LOW))  // if we're pushing button 1 OR button 2
        {                                             // AND we're NOT
      // pushing button 1 AND button 2
                                                     // then...


    digitalWrite(ledPin, HIGH);  // turn the LED on
    digitalWrite(ledPin2, HIGH);  // turn the LED on
    digitalWrite(ledPin3, HIGH);  // turn the LED on
    delay(500);
    digitalWrite(ledPin, LOW);  // turn the LED on
    digitalWrite(ledPin2, LOW);  // turn the LED on
    digitalWrite(ledPin3, LOW);  // turn the LED on
    delay(500);
     digitalWrite(ledPin, HIGH);  // turn the LED on
    digitalWrite(ledPin2, HIGH);  // turn the LED on
    digitalWrite(ledPin3, HIGH);  // turn the LED on
    delay(500);
    digitalWrite(ledPin, LOW);  // turn the LED on
    digitalWrite(ledPin2, LOW);  // turn the LED on
    digitalWrite(ledPin3, LOW);  // turn the LED on
    delay(500);
     digitalWrite(ledPin, HIGH);  // turn the LED on
    digitalWrite(ledPin2, HIGH);  // turn the LED on
    digitalWrite(ledPin3, HIGH);  // turn the LED on
    delay(500);
    digitalWrite(ledPin, LOW);  // turn the LED on
    digitalWrite(ledPin2, LOW);  // turn the LED on
    digitalWrite(ledPin3, LOW);  // turn the LED on
  }
 
  if ((button2State == LOW)) {
    for(int i = 0; i<4; i++) {
    digitalWrite(ledPin, HIGH);  // turn the LED on
    digitalWrite(ledPin3, HIGH);  // turn the LED on
    delay(500);
    digitalWrite(ledPin2, HIGH);  // turn the LED on
 
    digitalWrite(ledPin, LOW);  // turn the LED on
    digitalWrite(ledPin3, LOW);  // turn the LED on
    delay(500);
    digitalWrite(ledPin2, LOW);  // turn the LED on
    }}}
  

Video : 

                                           

12 Mart 2015 Perşembe

Arduino Experiment 6 - Photo Resistor Modify

Definition : By using photo resistor, we can change the resistor value and send different amount of voltage to the leds base on our light level ! We arrange lightlevel value and give different values of each led so they react different to light as you see.

Circuit Diagram






























Components

  •          1 x Photo Resistor
  •          3 x Led ( Green, Yellow, Red)
  •          3 x 330 Ω Resistor
  •          Wires
  •          Uno Board


Code

const int sensorPin = 0;
const int ledPin = 9;
int ledPin2 = 10;
int ledPin3 = 11;

// We'll also set up some global variables for the light level:

int lightLevel, high = 0, low = 1023;


void setup()
{
  // We'll set up the LED pin to be an output.
  // (We don't need to do anything special to use the analog input.)

  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
}

void loop()
{
  lightLevel = analogRead(sensorPin);

  manualTune();  // manually change the range from light to dark

  analogWrite(ledPin, lightLevel);
  analogWrite(ledPin2, lightLevel+1);
  analogWrite(ledPin3, lightLevel+100);
}

void manualTune()
{
 
  lightLevel = map(lightLevel, 0, 10, 0, 255);
  lightLevel = constrain(lightLevel, 0, 255);
}
void autoTune()
{
  if (lightLevel < low)
  {
    low = lightLevel;
  }


  if (lightLevel > high)
  {
    high = lightLevel;
  }
  lightLevel = map(lightLevel, low+30, high-30, 0, 255);
  lightLevel = constrain(lightLevel, 0, 255);

 
}


Video


11 Mart 2015 Çarşamba

Arduino Experiment 7 – Reading Temperature Sensor Modify


Definition : We use temperature sensor to construct a circuit to determine temperature value by leds. If our sensor reads a value that is smaller than 23 degree, our light will be green, if it is equal to 22, we have yellow and if it is greater than 22, we have red light.


Circuit Diagram



Components:

  •          1 x Temperature Sensor
  •          3 x LED ( Green, Yellow, Red)
  •          3 x 330 Ω Resistor
  •          Uno board
  •          Wires
Code :
const int temperaturePin = 0;
int green = 9;
int yellow = 10;
int red = 11;


void setup()
{
 
  pinMode(green,OUTPUT);
    pinMode(yellow,OUTPUT);
      pinMode(red,OUTPUT);

  Serial.begin(9600);
}
void loop()
{
 
  float voltage, degreesC, degreesF;
  voltage = getVoltage(temperaturePin);
  degreesC = (voltage - 0.5) * 100.0;


  degreesF = degreesC * (9.0/5.0) + 32.0;

if(degreesC<22) {
  digitalWrite(green,HIGH);
  digitalWrite(yellow,LOW);
  digitalWrite(red,LOW);
 
  }
  else if (degreesC<23) {
     digitalWrite(green,LOW);
  digitalWrite(yellow,HIGH);
  digitalWrite(red,LOW);
  }
  if(degreesC>23) {
     digitalWrite(green,LOW);
  digitalWrite(yellow,LOW);
  digitalWrite(red,HIGH);
  }
  Serial.print("voltage: ");
  Serial.print(voltage);
  Serial.print("  deg C: ");
  Serial.print(degreesC);
  Serial.print("  deg F: ");
  Serial.println(degreesF);
  delay(1000); // repeat once per second (change as you wish!)
}
float getVoltage(int pin)
{
  return (analogRead(pin) * 0.004882814);

}

Video



10 Mart 2015 Salı

Arduino Experiment 8 - Driving a Servo Motor Modify


Definition : Driving servo with 2 buttons. If left button is pushed, servo turns to the left and if right button is pushed, servo will turn to the right.

Circuit Diagram





Components

  •          2 x Button
  •          2 x 10 KΩ Resistor
  •          1 x Servo Motor
  •          Arduino Uno
  •          Bread Board


Code

#include <Servo.h>  // servo library
Servo servo1;  // servo control object
int ledred = 13;
int ledyellow = 12;
int ledgreen = 11;
int button1 = 2;
int button2 = 3;
int pos = 0;
boolean check = false;

void setup()
{
  pinMode(13,OUTPUT);
  pinMode(12,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(button1,INPUT);
  pinMode(button2,INPUT);

  servo1.attach(9);
}


void loop()
{
  int button1State, button2State;
  button1State = digitalRead(button1);
  button2State = digitalRead(button2);
 if(button1State == LOW && button2State == HIGH) {
   if(pos <170){
   pos = pos+100;
  check = true;
}
   }
  
   if(button2State == LOW && button1State == HIGH ) {
     if(pos > 10){
   pos = pos-100;
  check = true;
    }
   }
  if(check){
  servo1.write(pos);
  check = false;
  }
delay(200);


}

 Video






9 Mart 2015 Pazartesi

Arduino Experiment 9 - Using a Flex Sensor Modify



Circuit Diagram





Components


  •       1x Breadboard
  •       1x RedBoard or Arduino Uno
  •       1x Flex Sensor
  •       1x RGB Led
  •       1x 10k resistor
  •       3 x 330Ω resistor
  •       Wires

Code

const int RED_PIN = 9;
const int GREEN_PIN = 10;
const int BLUE_PIN = 11;
const int flexpin = 0;

void setup()
{
Serial.begin(9600);

pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
}

void loop()
{
 
int flexposition;    // Input value from the analog pin.

 flexposition = analogRead(flexpin);

Serial.print("sensor: ");
  Serial.print(flexposition);
 
 
 
digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, LOW);

if(flexposition>800) {
digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, HIGH);
}

else if(flexposition>720) {
  digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, LOW);
}

if(flexposition<700) {
digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, HIGH);
}
else if(flexposition<720) {
  digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, HIGH);
}

}

Video