Capaian Pembelajaran

  • Memahami jenis-jenis sensor dan prinsip kerjanya
  • Mengimplementasikan interface sensor analog dan digital
  • Mengontrol berbagai jenis aktuator dengan mikrokontroler
  • Membuat sistem kontrol closed-loop dengan feedback
  • Mengintegrasikan sensor dan aktuator dalam sistem embedded

1. Konsep Dasar Sensor & Aktuator

Sensor adalah perangkat yang mengubah besaran fisik menjadi sinyal elektrik, sedangkan Aktuator adalah perangkat yang mengubah sinyal elektrik menjadi aksi fisik.

Karakteristik Sensor

  • Range - Batas minimum dan maksimum pengukuran
  • Resolution - Perubahan terkecil yang dapat dideteksi
  • Sensitivity - Perubahan output per unit input
  • Accuracy - Kedekatan nilai terukur dengan nilai sebenarnya
  • Response Time - Waktu yang dibutuhkan untuk merespons perubahan

Karakteristik Aktuator

  • Torque/Force - Kemampuan menghasilkan torsi atau gaya
  • Speed - Kecepatan operasi
  • Power Consumption - Daya yang dibutuhkan
  • Control Interface - Cara pengontrolan (PWM, digital, dll)
  • Efficiency - Rasio output power vs input power

2. Jenis-jenis Sensor dalam Embedded Systems

Kategori Jenis Sensor Prinsip Kerja Contoh Aplikasi
Suhu Thermistor, LM35, DHT22 Perubahan resistansi/tegangan terhadap suhu Thermostat, weather station
Cahaya LDR, Photodiode, BH1750 Perubahan resistansi/arus terhadap intensitas cahaya Automatic lighting, security
Gerak PIR, Accelerometer, Gyroscope Deteksi perubahan posisi/kecepatan Security, gaming, navigation
Jarak Ultrasonic, Infrared, LiDAR Waktu tempuh gelombang/pantulan cahaya Parking sensor, robotics
Tekanan BMP180, MPX5100 Deformasi material terhadap tekanan Weather, altitude, flow control
sensor_interface.c - Interface Berbagai Jenis Sensor

#include 
#include 
#include 

// ADC Initialization untuk sensor analog
void ADC_Init() {
    ADMUX = (1 << REFS0); // Reference AVcc
    ADCSRA = (1 << ADEN) | (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); // Enable ADC, prescaler 128
}

uint16_t ADC_Read(uint8_t channel) {
    ADMUX = (ADMUX & 0xF8) | (channel & 0x07); // Select channel
    ADCSRA |= (1 << ADSC); // Start conversion
    while (ADCSRA & (1 << ADSC)); // Wait for conversion
    return ADC;
}

// Sensor Suhu LM35 (Analog)
float Read_LM35() {
    uint16_t adc_value = ADC_Read(0); // Channel 0
    float voltage = (adc_value * 5.0) / 1024.0;
    return voltage * 100; // 10mV per °C
}

// Sensor Cahaya LDR dengan voltage divider
int Read_LDR() {
    uint16_t adc_value = ADC_Read(1); // Channel 1
    return adc_value; // Nilai 0-1023
}

// Sensor Ultrasonic HC-SR04
float Read_Ultrasonic() {
    // Trigger pulse
    PORTD |= (1 << PD2);
    _delay_us(10);
    PORTD &= ~(1 << PD2);
    
    // Wait for echo
    while (!(PIND & (1 << PD3)));
    
    // Measure pulse width
    uint32_t count = 0;
    while (PIND & (1 << PD3)) {
        count++;
        _delay_us(1);
    }
    
    return (count * 0.034) / 2; // cm
}

// Sensor DHT22 (Digital)
typedef struct {
    float temperature;
    float humidity;
} DHT22_Data;

int Read_DHT22(DHT22_Data *data) {
    // Implementasi protokol DHT22
    // ... kode lengkap untuk komunikasi dengan DHT22
    return 1; // Success
}
                        

3. Jenis-jenis Aktuator dalam Embedded Systems

Jenis Aktuator Prinsip Kerja Control Method Contoh Aplikasi
DC Motor Elektromagnetik, rotasi kontinu PWM, H-Bridge Robot, conveyor, fan
Servo Motor Kontrol posisi dengan feedback PWM (1-2ms pulse) Robotic arm, camera gimbal
Stepper Motor Rotasi step-by-step presisi Digital pulses 3D printer, CNC
Solenoid Elektromagnetik, linear motion Digital ON/OFF Locking mechanism, valves
Relay Switch elektromekanis Digital ON/OFF Power control, isolation
actuator_control.c - Kontrol Berbagai Jenis Aktuator

#include 
#include 

// PWM Initialization untuk motor control
void PWM_Init() {
    // Fast PWM mode, non-inverting
    TCCR0A = (1 << WGM00) | (1 << WGM01) | (1 << COM0A1);
    TCCR0B = (1 << CS01); // Prescaler 8
}

// DC Motor control dengan PWM
void DC_Motor_SetSpeed(uint8_t speed) {
    OCR0A = speed; // 0-255
}

// Servo Motor control (50Hz PWM)
void Servo_Init() {
    // Timer1 untuk servo (16-bit)
    TCCR1A = (1 << COM1A1) | (1 << WGM11);
    TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS11);
    ICR1 = 39999; // 50Hz
}

void Servo_SetAngle(uint8_t angle) {
    // Convert angle to pulse width (1-2ms)
    uint16_t pulse_width = 1000 + (angle * 1000 / 180);
    OCR1A = pulse_width;
}

// Stepper Motor control
void Stepper_Init() {
    DDRC |= 0x0F; // PC0-PC3 sebagai output
}

void Stepper_Step(uint8_t direction, uint16_t steps) {
    const uint8_t sequence[] = {0x09, 0x08, 0x0C, 0x04, 0x06, 0x02, 0x03, 0x01};
    
    for(uint16_t i = 0; i < steps; i++) {
        for(uint8_t j = 0; j < 8; j++) {
            uint8_t index = direction ? j : (7 - j);
            PORTC = sequence[index];
            _delay_ms(2);
        }
    }
    PORTC = 0x00; // Turn off
}

// Relay control
void Relay_Control(uint8_t state) {
    if(state) {
        PORTD |= (1 << PD4); // Relay ON
    } else {
        PORTD &= ~(1 << PD4); // Relay OFF
    }
}
                        

4. Simulator Sensor & Aktuator

Simulator Sistem Sensor dan Aktuator

Monitor dan kontrol berbagai jenis sensor dan aktuator secara real-time

Sensor Suhu LM35

25.0°C

Sensor Cahaya LDR

512 lux

Sensor Jarak Ultrasonic

50 cm

Kontrol Aktuator

Servo Motor

DC Motor

0%

Relay Control

Status: OFF

5. Sistem Terintegrasi dengan Feedback

Smart Home Control System

Sistem otomasi rumah dengan sensor dan aktuator terintegrasi

Temperature Sensor
25°C
Microcontroller
AVR ATMega328P
Fan Control
OFF

Closed-Loop Control System

Sistem ini menerapkan closed-loop control dengan feedback dari sensor suhu. Mikrokontroler membandingkan suhu aktual dengan setpoint, kemudian mengontrol kipas untuk mempertahankan suhu yang diinginkan.

Latihan Praktikum

Implementasikan sistem kontrol dengan sensor dan aktuator

Tugas 1: Temperature Control System

Buat sistem kontrol suhu otomatis dengan komponen berikut:

  • Sensor suhu LM35 (analog) atau DHT22 (digital)
  • Kipas DC dengan driver motor (L298N atau transistor)
  • Display LCD atau serial monitor untuk status
  • Potensiometer untuk setpoint adjustment
  • Implementasikan PID controller sederhana

Tugas 2: Smart Lighting System

Buat sistem pencahayaan otomatis dengan fitur:

  • Sensor cahaya LDR atau BH1750
  • Relay module untuk kontrol lampu
  • RTC module untuk waktu operasi
  • Mode manual/otomatis dengan switch
  • LED indicator untuk status sistem