Vous êtes sur la page 1sur 5

PRAKTIKUM INSTRUMENTASI DAN KENDALI

LAPORAN

Oleh:

Geza Sandhiyoga
161910101086

PROGRAM STUDI S1 TEKNIK


JURUSAN TEKNIK MESIN
FAKULTAS TEKNIK

UNIVERSITAS JEMBER
2018
A. Alat dan Bahan

1. Arduino

2. Bread board

3.Kabel Jumper

4. Lampu led

5.LDR

6.Resistor

7. Potensiometer

B. Prosedur/ Langkah Kerja

a. Siapkan alat dan bahan yang di butuhkan

b. Rangkailah rangkaian sesuai dengan gambar di bwah ini


c. Kemudian Masukkan progam sesuai dengan pr ogam di bawah ini

include <PID_v1.h>

const int photores = A0; // LDR input pin

const int pot = A1; // Potentiometer input pin

const int led = 9; // LED output pin

double lightLevel; // Indirectly store the light level

// Tuning parameters

float Kp = 0; // Proportional gain

float Ki = 10; // Integral gain

float Kd = 0; // Differential gain

// Record the set point as well as the controller input and output

double Setpoint, Input, Output;

// Create a controller that is linked to the specified Input, Ouput and Setpoint

PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);

const int sampleRate = 1; // Time interval of the PID control

const long serialPing = 500; // How often data is recieved from the Arduino

unsigned long now = 0; // Store the time that has elapsed

unsigned long lastMessage = 0; // The last time that data was recieved

void setup()

lightLevel = analogRead(photores); // Read the set point

// Arduino has an analogueRead() resolution of 0-1023 and an analogueWrite()


resolution of 0-255

Input = map(lightLevel, 0, 1023, 0, 255); // Scale the input


Setpoint = map(analogRead(pot), 0, 1023, 0, 255); // Scale the set point

Serial.begin(9600); // Initialise serial communications at 9600

bps
myPID.SetMode(AUTOMATIC); // Turn on the PID control

myPID.SetSampleTime(sampleRate); // Assign the sample rate of the


control

Serial.println("Begin"); // Let the user know that the set up s


complete

lastMessage = millis(); // Serial data will be recieved relative to

this first point

void loop()

Setpoint = map(analogRead(pot), 0, 1023, 0, 255); // Continue to read and scale


the set point

lightLevel = analogRead(photores); // Read the light level

Input = map(lightLevel, 0, 1023, 0, 255); // Scale the input to the PID

myPID.Compute(); // Calculates the PID output at a


specified sample time

analogWrite(led, Output); // Power the LED

now = millis(); // Keep track of the elapsed time

if(now - lastMessage > serialPing) // If enough time has passed send


data

Serial.print("Setpoint = ");

Serial.print(Setpoint);

Vous aimerez peut-être aussi