Skip to main content

Proyek Arduino dengan 2 Buah Seven Segment

Proyek Arduino dilakukan dengan menggunakan dua buah 7-segment. Tujuan dari ptoyek yang dilakukan adalah membuat 7-segment menampilkan angka random setiap kali tombol ditekan. Alat dan bahan yang dibutuhkan untuk proyek kali ini adalah.
  1. Arduino UNO
  2. Jumpers
  3. Breadboard
  4. Resistor
  5. 2 buah 7-segment
  6. Komputer
  7. Button
Berikut ini adalah video hasil bagaimana proyek Arduino bekerja.


Terdapat kesalahan dalam pembuatan proyek ini. Tujuan awal adalah supaya angka yang ditampilkan di 7-segment benar-benar random. Namun hasil proyek ini justru menampilkan angka kanan dan kiri yang sama. Hal ini kemungkinan dikarenakan rangkaian Arduino menggunakan flip-flop.

Dan berikut ini adalah source code yang digunakan

/*  * SevenSegmentMpx sketch
    * Shows numbers ranging from 0 through 99 on a four-digit display
    * This example displays the value of a sensor connected to an analog input */
// bits representing segments A through G (and decimal point) for numerals 0-9
const int trigPin = 12;
const int echoPin = 13;
const int numeral[10] = {
  //ABCDEFG /dp
  B11111100,  // 0
  B01100000,  // 1
  B11011010,  // 2
  B11110010,  // 3
  B01100110,  // 4
  B10110110,  // 5
  B00111110,  // 6
  B11100000,  // 7
  B11111110,  // 8
  B11100110,  // 9
};

// pins for decimal point and each segment
// dp,G,F,E,D,C,B,A

const int segmentPins[] = { 4,7,8,6,5,3,2,9};
const int nbrDigits= 2;  // the number of digits in the LED display
                         //dig  1  2
const int digitPins[nbrDigits] = {11,10};
const int buttonPin = 4; 
int buttonState = 0;
int hasil = 0;
int digit = 1;
int x = 1;

void setup() {
  Serial.begin(9600);
  for(int i=0; i < 8; i++)
  pinMode(segmentPins[i], OUTPUT);

// set segment and DP pins to output
  for(int i=0; i < nbrDigits; i++)
  pinMode(digitPins[i], OUTPUT);
  
  pinMode(buttonPin, INPUT);
}

void loop() {
  // establish variables for duration of the ping,
  // and the distance result in inches and centimeters:
  long duration, inches, cm;
  buttonState = digitalRead(buttonPin);

  // The sensor is triggered by a HIGH pulse of 10 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  /*
  pinMode(trigPin, OUTPUT);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  */
  // Read the signal from the sensor: a HIGH pulse whose
  // duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  /*
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);
  */
  // convert the time into a distance
  /*
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
  cm = cm + 1;
  */
//  Serial.print(inches);
//  Serial.print(“in, “);
  /*
   * Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  */
//  delay(50);

   if (buttonState == LOW) {
    int x = random(1,52);
    
    showNumber(x);
    //
   
    
   // x++;
  }
  delay(50);  
}

void showNumber( int number) {
  if(number == 0)
    showDigit( 0, nbrDigits-1) ; // display 0 in the rightmost digit
  else  {    // display the value corresponding to each digit    // leftmost digit is 0, rightmost is one less than the number of places
  for( int digit = nbrDigits-1; digit >= 0; digit--)    {
    if(number > 0)      {
      showDigit( number % 10,digit)  ;
      number = number / 10;
    } else if (number == 0) {
      showDigit( number % 10,digit) ;
    }
    }
  }
}

// Displays given number on a 7-segment display at the given digit position

void showDigit( int number, int digit) {
  digitalWrite( digitPins[digit], HIGH );
  for(int segment = 1; segment < 8; segment++)  {
    boolean isBitSet = bitRead(numeral[number], segment);    // isBitSet will be true if given bit is 1
    // isBitSet = ! isBitSet; // remove this line if common cathode display

    digitalWrite( segmentPins[segment], isBitSet);
  }

  delay(10);

  digitalWrite( digitPins[digit], LOW );
}

long microsecondsToInches(long microseconds)
{
  // According to Parallax’s datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}

Comments

Popular posts from this blog

Proyek Arduino Kalkulator

Dalam proyek kali ini, akan dibuat sebuah kalkulator sederhana dengan Arduino. Kalkulator yang akan dibuat mampu memproses dua buah angka dan satu buah operator dan menampilkan hasil ke layar. Adapun operasi yang didukung oleh proyek kali ini adalah sebagai berikut. Penjumlahan Pengurangan Perkalian Pembagian Pangkat dua Untuk mengerjakan proyek, berikut ini adalah alat dan bahan yang dibutuhkan. Arduino Uno LCD Jumper Keypad Berikut ini adalah gambar susunan rangkaian.  /*References:  * https://circuitdigest.com/microcontroller-projects/arduino-calculator-using-4x4-keypad  * https://medium.com/@18214030_IMKA/tugas-4-kalkulator-sederhana-6dc775f9811c  * https://www.sunfounder.com/learn/Sensor-Kit-v2-0-for-Arduino/lesson-1-display-by-i2c-lcd1602\  * -sensor-kit-v2-0-for-arduino.html  * https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home  */ #include <Key.h> #include <Keypad.h> #include ...

Project Arduino

Dengan menggunakan Arduino, saya membuat sebuah alat yang akan memancarkan warna tertentu sesuai dengan nama warna yang saya ucapkan. Berikut adalah ilustrasi dari Arduino yang dibuat. Untuk sumber dapat dicek di  http://mechstuff.com/control-leds-with-voice-command-arduino-bluetooth-module-tutoria/  Perangkat yang dibutuhkan adalah  Arduino board Breadboard Jumpers/single stranded wires RGB led Bluetooth module Android Setelah menyisipkan code ke Arduino board (dapat dicek di :   http://mechstuff.com/control-leds-with-voice-command-arduino-bluetooth-module-tutoria/ ) , dan melakukan hal teknis lainnya, alat siap digunakan. Cara kerja alat adalah dengan mengucapkan nama warna yang sudah diprogram ke Android. Android akan mengirimkan sinyal ke Bluetooth module, untuk kemudian diproses oleh Arduino Board yang akhirnya LED akan memancarkan warna sesuai output Arduino Board.

Laporan Tugas Akhir Arduino

Laporan IMKA Arduino Laporan ini dibuat untuk memenuhi tugas kuliah mata kuliah IMKA Arduino 2019 Oleh : Andrew Dani A. (18216016), Thomas Robin (18216032), Mira Risty M. (18216037) Pada artikel blog ini, saya akan menjelaskan aplikasi IoT untuk Smartbin dengan penggunaan third-party app Blynk. Identifikasi Masalah Tempat sampah  berfungsi untuk menampung sampah yang dibuang oleh masyarakat. Produksi sampah terjadi setiap hari begitu pula dengan sampah yang ditampung di tempat sampah. Oleh karena itu, tidak heran apabila tempat sampah sering terisi penuh setiap hari di daerah dengan penduduk yang ramai. Sedangkan, di daerah yang sepi tempat sampah dapat menampung sampah buangan masyarakat selama kurun waktu beberapa hari. Hal ini bisa menjadi masalah ketika akan dilakukan pembersihan tempat sampah karena untuk daerah ramai, pembersihan sampah setiap hari mungkin tidak cukup cepat dan pembersihan tempat sampah untuk daerah sepi penduduk membuang biaya dan wakt...