Label:

Tutorial Arduino Untuk Pemula : Kondisi perulangan while pada arduino

0 komentar

Pada kesempatan kali ini saya akan membahas tentang cara menggunakan perulangan while pada arduino. adapun while do merupakan sebuah perulagan yang dapat dimanfaatkan untuk melakukan perulangan yang sudah diketahui kondisi dimana harus berulang.

adapun contoh syntax arduinonya adalah :

/*
  Conditionals - while statement

 This example demonstrates the use of  while() statements.

 While the pushbutton is pressed, the sketch runs the calibration routine.
 The  sensor readings during the while loop define the minimum and maximum
 of expected values from the photo resistor.

 This is a variation on the calibrate example.

 The circuit:
 * photo resistor connected from +5V to analog in pin 0
 * 10K resistor connected from ground to analog in pin 0
 * LED connected from digital pin 9 to ground through 220 ohm resistor
 * pushbutton attached from pin 2 to +5V
 * 10K resistor attached from pin 2 to ground

 created 17 Jan 2009
 modified 30 Aug 2011
 by Tom Igoe

 This example code is in the public domain.

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

 */


// These constants won't change:
const int sensorPin = A2;       // pin that the sensor is attached to
const int ledPin = 9;           // pin that the LED is attached to
const int indicatorLedPin = 13; // pin that the built-in LED is attached to
const int buttonPin = 2;        // pin that the button is attached to


// These variables will change:
int sensorMin = 1023;  // minimum sensor value
int sensorMax = 0;     // maximum sensor value
int sensorValue = 0;         // the sensor value


void setup() {
  // set the LED pins as outputs and the switch pin as input:
  pinMode(indicatorLedPin, OUTPUT);
  pinMode (ledPin, OUTPUT);
  pinMode (buttonPin, INPUT);
}

void loop() {
  // while the button is pressed, take calibration readings:
  while (digitalRead(buttonPin) == HIGH) {
    calibrate();
  }
  // signal the end of the calibration period
  digitalWrite(indicatorLedPin, LOW);

  // read the sensor:
  sensorValue = analogRead(sensorPin);

  // apply the calibration to the sensor reading
  sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);

  // in case the sensor value is outside the range seen during calibration
  sensorValue = constrain(sensorValue, 0, 255);

  // fade the LED using the calibrated value:
  analogWrite(ledPin, sensorValue);
}

void calibrate() {
  // turn on the indicator LED to indicate that calibration is happening:
  digitalWrite(indicatorLedPin, HIGH);
  // read the sensor:
  sensorValue = analogRead(sensorPin);

  // record the maximum sensor value
  if (sensorValue > sensorMax) {
    sensorMax = sensorValue;
  }

  // record the minimum sensor value
  if (sensorValue < sensorMin) {
    sensorMin = sensorValue;
  }
}

Sekian pembahasan dari saya Terima kasih.

Sumber : http://arduino.cc/en/Tutorial/WhileLoop

Label:

Tutorial arduino untuk pemula : Kondisi perulangan for loop pada arduino

0 komentar

Pada kesempatan kali ini saya akan membahas tentang perulangan for loop pada arduino. perulangan for loop pada arduino berfungsi untuk melakukan counter. dibawah akan diberikan contoh penggunaan for loop pada arduino.

adapun syntax arduinonya adalah :
/*
  For Loop Iteration

 Demonstrates the use of a for() loop.
 Lights multiple LEDs in sequence, then in reverse.

 The circuit:
 * LEDs from pins 2 through 7 to ground

 created 2006
 by David A. Mellis
 modified 30 Aug 2011
 by Tom Igoe

This example code is in the public domain.

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

int timer = 100;           // The higher the number, the slower the timing.

void setup() {
  // use a for loop to initialize each pin as an output:
  for (int thisPin = 2; thisPin < 8; thisPin++)  {
    pinMode(thisPin, OUTPUT);    
  }
}

void loop() {
  // loop from the lowest pin to the highest:
  for (int thisPin = 2; thisPin < 8; thisPin++) {
    // turn the pin on:
    digitalWrite(thisPin, HIGH);  
    delay(timer);                
    // turn the pin off:
    digitalWrite(thisPin, LOW);  
  }

  // loop from the highest pin to the lowest:
  for (int thisPin = 7; thisPin >= 2; thisPin--) {
    // turn the pin on:
    digitalWrite(thisPin, HIGH);
    delay(timer);
    // turn the pin off:
    digitalWrite(thisPin, LOW);
  }
}

sekian pembahasan dari saya terima kasih.

Sumber : http://www.arduino.cc/en/Tutorial/ForLoop

Label:

Tutorial Arduino untuk pemula : Kondisi IF pada arduino

0 komentar

Pada kesempatan kali ini saya akan membahas tentang penggunaan IF pada arduino. adapun untuk lebeih jelasnya dapat dilihat pada perintah program yang akan dijelaskan dibawah ini.

Adapun syntax arduinonya adalah :

/*
  Conditionals - If statement

 This example demonstrates the use of if() statements.
 It reads the state of a potentiometer (an analog input) and turns on an LED
 only if the LED goes above a certain threshold level. It prints the analog value
 regardless of the level.

 The circuit:
 * potentiometer connected to analog pin 0.
 Center pin of the potentiometer goes to the analog pin.
 side pins of the potentiometer go to +5V and ground
 * LED connected from digital pin 13 to ground

 * Note: On most Arduino boards, there is already an LED on the board
 connected to pin 13, so you don't need any extra components for this example.

 created 17 Jan 2009
 modified 9 Apr 2012
 by Tom Igoe

This example code is in the public domain.

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

 */

// These constants won't change:
const int analogPin = A0;    // pin that the sensor is attached to
const int ledPin = 13;       // pin that the LED is attached to
const int threshold = 400;   // an arbitrary threshold level that's in the range of the analog input

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communications:
  Serial.begin(9600);
}

void loop() {
  // read the value of the potentiometer:
  int analogValue = analogRead(analogPin);

  // if the analog value is high enough, turn on the LED:
  if (analogValue > threshold) {
    digitalWrite(ledPin, HIGH);
  }
  else {
    digitalWrite(ledPin,LOW);
  }

  // print the analog value:
  Serial.println(analogValue);
  delay(1);        // delay in between reads for stability
}

Sekian pembahasan dari saya terima kasih.

Label:

Tutorial Arduino Untuk Pemula : Cara Menggunaka Liquid Crystal Display pada arduino

0 komentar

Pada kesempatan kali ini saya akan membahas mengenai cara menggunaka LCD pada arduino. adapun komponen yang diperlukan adalah sebuah module LCD dan Arduino uno. untuk pemasangan portnya dapat melihat pada syntax dibawah.

adapun syntax yang dapat digunakan adalah :

Label:

Tutorial Arduino Untuk Pemula : IR Receive pada arduino

0 komentar

Pada pembahasan kali ini saya akan membahas tentang cara menrima kode hexa dari sebuah perangkat yang mengirimkan data hexa menggunakan inframerah. adapun perangkat yang diperlukan adalah sensor inframerah dan arduino UNO R3.

Label:

Tutorial Arduino untuk pemula : Cara Melakukan IR Send pada arduino

0 komentar

Pada kesempatan kali ini saya akan mebahas bagaimana melakukan ir Send pada arduino
berikut adalah syntax yang dapat digunakan untuk melakukan ir send

Label:

Tutorial Arduino Untuk Pemula : Cara melakukan pembacaan data digital dan analog

0 komentar


Arduino merupakan sebuah minsys yang memanfaatkan IC ATMEGA328. Arduino merupakan sebuah mikrokontroller yang mudah dimengerti bagi pemrogram yang sudah menguasai bahasa c.

pada kesempatan kali ini saya akan membahas tentang cara melakukan analogread dan digital read.