Minggu, 29 Mei 2016

Traffic Lights Arduino

You are now going to create a set of traffic lights that will change from green to red, via amber, and back again, after a set length of time using the four-state UK, you can modify the code and colors to meke them work like the traddic lights in your own country. First, though, make the project as it is and change it once you know how it works.

Parts Required

  • Breadboard
  • Red Diffused LED
  • Yellow Diffused LED
  • Green Diffused LED
  • 3 x 150 ohm Resistors*
  • Jumper Wires
*or whatever value you require for your type of LED

Connect It Up

Connect your circuits as show Figure below. This time you connect three LEDs with the anode of each one going to Digital Pins 8, 9 and 10 via a 150 ohm resistor each.

Take a jumper wire from ground of the Arduino to ground rail at the top of the breadboard; a connected to the cathode. (For this simple circuit, it doesn't matter if the resistor is connected to the anode or cathode).

Image Source: Book Beggining Arduino. Page: 36


Enter the Code

int ledDelay = 5000;// delay in between changes
int redPin = 10;
int yellowPin = 9;
int greenPin = 8;

void setup (){
  pinMode(redPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
}

void loop(){
  digitalWrite(redPin,HIGH);
  delay(ledDelay); // wait 5 seconds
 
  digitalWrite(yellowPin, HIGH);
  delay(2000);// wait 2 seconds
 
  digitalWrite(greenPin, HIGH); // turn green on
  digitalWrite(redPin, LOW); // turn red off
  digitalWrite(yellowPin, LOW); // turn yellow off
  delay(ledDelay); // wait ledDelay milliseconds
 
  digitalWrite(yellowPin,HIGH); // turn yellow on
  digitalWrite(greenPin, LOW); // turn green off
  delay(2000); // wait 2 seconds
 
  digitalWrite(yellowPin, LOW); // turn yellow off
  // now our loop repeats
}

Figure: The four states of the UK traffic lightsystem (Image Source: Book Beggining Arduino. Page: 37)
The code can be downloaded HERE.

Source: Excerpted and adapted from the Book Beginning Arduino, page 34-37.
Image Saurce: http://www.amazon.co.uk/Beginning-Arduino-Michael-McRoberts/dp/1430232404

Hope it's useful....

Kamis, 26 Mei 2016

LED Berkedip

Untuk projek pertama, Anda akan mengulangi sketsa LED berkedip yang digunakan selama tahap pengujian.Kali ini, Anda akan menghubungkan LED ke salah satu pin digital daripada menggunakan LED13, yang disolder ke papan. Anda juga akan belajar mengenai perangkat lunak untuk pengerjaan projek ini, belajar sedikit mengenai coding dalam bahasa Arduino (yang merupakan varian dari bahas C).

Komponen yang diperlukan
  • Breadboard
  • 5 mm LED
  • 100 ohm resistor (Nilai ini bisa berbeda tergantung LED yang Anda gunakan)
  • Kabel Jumper/Penghubung
Konfigurasi

Pertama, pastika Arduino Anda dimatikan dengan mencabut kabel USB. Sekarang, ambil papan breadboard Anda, LED, resistor, dan kabel penghubung, lalu hubungkan semuanya seperti gambar dibawah ini:
Sumber gambar: buku Beggining Arduino. Hal: 22

Kode Program:

int ledPin = 10;
void setup() {
  pinMode(ledPin, OUTPUT);
}

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

Penelasan program:

Didalam code kita menggunakan pin digital 10 (int ledPin = 10;), lampu LED akan menyala selama 1 detik dan mati selama 1 detik. Untuk mengatur kecepatan hidup mati LED kita tinggal mengganti waktu delay yang tertera (1000) (delay(1000);).

Kode dapat di download DISINI.

Sumber: Dikutip dan disesuaikan dari buku Beginning Arduino halaman 21-23.
Sumber Gambar: http://www.amazon.co.uk/Beginning-Arduino-Michael-McRoberts/dp/1430232404


 Semoga bermanfaat....

Post in English HERE.

LED Flasher

For the first project, you are going to repeat the LED blink sketch that you used during your testing stage. This time, you are going to connect an LED to one of the digital pins rather than using LED13, which is soldered to the board. You software for this project work, learning a bit about  coding in the Arduino langue (which is a variant of C).

Part Required
  • Breadboard
  • 5 mm LED
  • 100 ohm Resistor (this value may differ depending on what LED you use.)
  • Jumper Wires
Connecting Everything

First, make sure your Arduino is powered off by unplugging it from the USB cable. Now, take your breadboard, LED, resistor, and wires and connet everything as shown in Figure below:
Image Source: Book Beggining Arduino. Page: 22

Enter the Code:

Open up yout Arduino IDE and type in the code below:

int ledPin = 10;
void setup() {
  pinMode(ledPin, OUTPUT);
}

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

Code Overview

In code we use digital pin 10 (int ledPin = 10;), the LED will be On for 1 sec and off for 1 sec. To set the speed of On and Off, we just change LED delay time in the code (delay(1000);)

The code can be downloaded HERE.

Source: Excerpted and adapted from the Book Beginning Arduino, page 21-23.
Image Saurce: http://www.amazon.co.uk/Beginning-Arduino-Michael-McRoberts/dp/1430232404

Hope it's useful....
Related Posts Plugin for WordPress, Blogger...