Tugas Pendahuluan 2 Modul 2

Percobaan 6 Kondisi 1

1. Prosedur [Kembali]

1. Rangkai rangkaian di proteus sesuai dengan kondisi percobaan.
2. Tulis program untuk arduino di software Arduino IDE.
3. Compile program tadi, lalu upload ke dalam arduino.
4. Setelah program selesai di upload, jalankan simulasi rangkaian pada proteus.

2. Hardware dan Diagram Blok [Kembali]

Hardware :

1. Arduino





2. Push Button




3. Motor Stepper
                                                            

4. ULN2003A
                                                  

5. LM35



6. 7- Segment



Diagram Blok :





3. Rangkaian Simulasi dan Prinsip Kerja [Kembali]


Prinsip Kerja:

Pada percobaan 6 kondisi 1 digunakan input berupa sensor suhu LM35 yang dihubungkan ke pin A0 arduino dan button dihubungkan pada pin A1- A5 arduino. Input suhu berfungsi untuk memberikan kondisi dimana ketika suhu besar dari 30, maka motor akan berputar ke kanan, sedangkan button berfungsi untuk mengatur pergerakan motor sesuai dengan sudut- sudut atau langkah- langkah sudutnya. output dari arduino pertama pin 8- 11 dihubungkan dengan LN2003A, yaitu driver untuk menjalankan motor stepper. selain itu pin arduino juga dihubungkan dengan seven segment sebagai output, yang mana 7 segment akan menampilkan suhu LM35.


Flowchart :


Listing Program:

#define A 8
#define B 9
#define C 10
#define D 11
#define PB1 A1
#define PB2 A2
#define PB3 A3
#define PB4 A4

const int motorPin1 = 2;
const int motorPin2 = 3;
const int temperaturePin = A0;

// Pins for the 7-segment display (common ANODE)
const int segmentPins[] = {7, 6, 5, 4, 3, 2, 1};

void setup() {
  Serial.begin(9600);
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT);
  pinMode(PB1, INPUT_PULLUP);
  pinMode(PB2, INPUT_PULLUP);
  pinMode(PB3, INPUT_PULLUP);
  pinMode(PB4, INPUT_PULLUP);

  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);

  for (int i = 0; i < 8; i++) {
    pinMode(segmentPins[i], OUTPUT);
    digitalWrite(segmentPins[i], HIGH); // Turn off all segments initially
  }
}

void pergerakan_1(){
  digitalWrite(A, 0);
  digitalWrite(D, 1);
  digitalWrite(B, 0);
  digitalWrite(C, 1);
}

void pergerakan_2(){
  digitalWrite(A, 1);
  digitalWrite(D, 1);
  digitalWrite(B, 0);
  digitalWrite(C, 0);
}

void pergerakan_3(){
  digitalWrite(A, 1);
  digitalWrite(D, 0);
  digitalWrite(B, 1);
  digitalWrite(C, 0);
}

void pergerakan_4(){
  digitalWrite(A, 0);
  digitalWrite(D, 0);
  digitalWrite(B, 1);
  digitalWrite(C, 1);
}

void nonpergerakan(){
  digitalWrite(A, 0);
  digitalWrite(D, 0);
  digitalWrite(B, 0);
  digitalWrite(C, 0);
}

void displayTemperature(int temp) {
  int tens = temp / 10;
  int ones = temp % 10;

  for (int i = 0; i < 7; i++) {
    digitalWrite(segmentPins[i], LOW); // Turn off all segments
  }

  // Display tens digit
  displayDigit(tens, 0);
  delay(5);
  digitalWrite(segmentPins[0], LOW); // Turn off DP
  delay(5);

  // Display ones digit
  displayDigit(ones, 1);
  delay(5);
}

void displayDigit(int digit, int digitNum) {
  switch (digit) {
    case 0:
      digitalWrite(segmentPins[0 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[1 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[2 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[3 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[4 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[5 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[6 + (4 * digitNum)], HIGH); // DP
      break;
    case 1:
      digitalWrite(segmentPins[0 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[1 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[2 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[3 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[4 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[5 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[6 + (4 * digitNum)], LOW); // DP
      break;
    case 2:
      digitalWrite(segmentPins[0 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[1 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[2 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[3 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[4 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[5 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[6 + (4 * digitNum)], LOW); // DP
      break;
    case 3:
      digitalWrite(segmentPins[0 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[1 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[2 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[3 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[4 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[5 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[6 + (4 * digitNum)], LOW); // DP
      break;
    case 4:
      digitalWrite(segmentPins[0 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[1 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[2 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[3 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[4 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[5 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[6 + (4 * digitNum)], LOW); // DP
      break;
    case 5:
      digitalWrite(segmentPins[0 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[1 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[2 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[3 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[4 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[5 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[6 + (4 * digitNum)], LOW); // DP
      break;
    case 6:
      digitalWrite(segmentPins[0 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[0 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[1 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[2 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[3 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[4 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[5 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[6 + (4 * digitNum)], LOW); // DP
      break;
    case 7:
      digitalWrite(segmentPins[0 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[1 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[2 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[3 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[4 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[5 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[6 + (4 * digitNum)], LOW); // DP
      break;
    case 8:
      digitalWrite(segmentPins[0 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[1 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[2 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[3 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[4 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[5 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[6 + (4 * digitNum)], LOW); // DP
      break;
    case 9:
      digitalWrite(segmentPins[0 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[1 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[2 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[3 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[4 + (4 * digitNum)], LOW);
      digitalWrite(segmentPins[5 + (4 * digitNum)], HIGH);
      digitalWrite(segmentPins[6 + (4 * digitNum)], LOW); // DP
      break;
     }
}

void loop() {
int b4 = digitalRead(PB4);
int b3 = digitalRead(PB3);
int b2 = digitalRead(PB2);
int b1 = digitalRead(PB1);

if (b4 == LOW) {
pergerakan_4(); // Pindahkan servo ke 45 derajat
}
else if (b3 == LOW) {
pergerakan_3(); // Pindahkan servo ke 45 derajat
}
else if (b2 == LOW) {
pergerakan_2(); // Pindahkan servo ke 45 derajat
}
else if (b1 == LOW) {
pergerakan_1(); // Pindahkan servo ke 45 derajat
}
else {
nonpergerakan();
delay(100);
}

// Baca suhu dari sensor LM35
int sensorValue = analogRead(temperaturePin);
// Konversi nilai analog ke suhu dalam derajat Celsius
float temperatureC = (sensorValue * 5.0 / 1023) * 100;

// Tampilkan suhu di 7-segment display jika lebih besar dari 30 derajat
if (temperatureC > 30) {
displayTemperature(temperatureC);
// Gerakkan motor searah jarum jam
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
}
else {
// Matikan motor jika suhu tidak lebih besar dari 30 derajat
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
// Hidupkan semua segmen pada display 7-segmen
for (int i = 0; i < 7; i++) {
digitalWrite(segmentPins[i], HIGH);
}
}
}

Percobaan 5 Kondisi 1 : 
Sertakan dengan LM35 dan 7- Segment, ketika suhu bernilai >30 motor searah jarum jam 






7. Download File [Kembali]


HTML                        klik disini
fILE RANGKAIAN     klik disini
Video Percobaan      klik disini
Listing Program         klik disini
datasheet arudino     klik disini
Datasheet Button      klik disini
Datasheet LED         klik disini


Tidak ada komentar:

Posting Komentar

MODUL 4 PRATIKUM uP dan uC

[KEMBALI KE MENU SEBELUMNYA] DAFTAR ISI     1. Pendahuluan     2. Tujuan     3. Alat dan Bahan     4. Dasar Teori     5. Percob...