LAPORAN AKHIR 2
a. Prosedur
b. Hardware dan Diagram Blok
HARDWARE
Microcontroller | STM32G474RE (ARM Cortex-M4F) |
Operating Voltage | 3.3 V |
Input Voltage (recommended) | 5 V via USB (ST-LINK) atau 7–12 V via VIN |
Input Voltage (limit) | 4.5 – 15 V (VIN board Nucleo) |
Digital I/O Pins | ±51 GPIO pins (tergantung konfigurasi fungsi) |
PWM Digital I/O Pins | Hingga 24 channel PWM (advanced, general-purpose, dan high-resolution timers) |
Analog Input Pins | Hingga 24 channel ADC (12-bit / 16-bit dengan oversampling) |
DC Current per I/O Pin | Maks. 20 mA per pin (disarankan ≤ 8 mA) |
DC Current for 3.3V Pin | Hingga ±500 mA (tergantung regulator & sumber daya) |
Flash Memory | 512 KB internal Flash |
SRAM | 128 KB SRAM (termasuk CCM RAM) |
Clock Speed | Hingga 170 MHz |
2. FLOAT Sensor
SPESIFIKASI :
- Material: Umumnya Stainless Steel SUS304 (anti karat) atau PP Plastic.
- Maksimum Beban Kontak: 50W / 10W (tergantung model).
- Tegangan Maksimum: 220V DC/AC (perlu relay untuk beban AC tinggi).
- Arus Maksimum: 0.5A - 1.5A.
- Panjang Sensor: Tersedia dalam berbagai ukuran, seperti 45mm, 100mm, 150mm, 300mm, hingga 500mm.
- Pemasangan: Umumnya dipasang secara vertikal (atas atau dasar tangki).
- Prinsip Kerja: Menggunakan saklar magnetik (reed switch) yang aktif saat pelampung naik/turun.
3. Flame Sensor
4. LED
5. Buzzer
6. Resistor
d. Flowchart dan Listing Program
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.h
* @brief : Header for main.c file.
* This file contains the common defines of the application.
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32g4xx_hal.h"
#include "stm32g4xx_nucleo.h"
#include <stdio.h>
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/
/* ====== INPUT ====== */
#define FLAME_PIN GPIO_PIN_0
#define FLAME_PORT GPIOA
#define FLOAT_PIN GPIO_PIN_1
#define FLOAT_PORT GPIOA
/* ====== OUTPUT ====== */
#define LED_PIN GPIO_PIN_5
#define LED_PORT GPIOA
#define BUZZER_PIN GPIO_PIN_6
#define BUZZER_PORT GPIOA
#define RELAY_PIN GPIO_PIN_7
#define RELAY_PORT GPIOA
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
#ifdef __cplusplus
}
#endif
#endif /* __MAIN_H */
main.c:
#include "main.h"
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
while (1)
{
GPIO_PinState flame_state;
GPIO_PinState float_state;
flame_state = HAL_GPIO_ReadPin(FLAME_PORT, FLAME_PIN);
float_state = HAL_GPIO_ReadPin(FLOAT_PORT, FLOAT_PIN);
/* ===== FLAME SENSOR ===== */
if (flame_state == GPIO_PIN_RESET)
{
/* Api terdeteksi */
HAL_GPIO_WritePin(LED_PORT, LED_PIN, GPIO_PIN_SET);
HAL_GPIO_WritePin(BUZZER_PORT, BUZZER_PIN, GPIO_PIN_SET);
}
else
{
HAL_GPIO_WritePin(LED_PORT, LED_PIN, GPIO_PIN_RESET);
HAL_GPIO_WritePin(BUZZER_PORT, BUZZER_PIN, GPIO_PIN_RESET);
}
/* ===== RELAY / POMPA ===== */
if ((flame_state == GPIO_PIN_SET) || (float_state == GPIO_PIN_SET))
{
/* Api ATAU tangki penuh → pompa MATI */
HAL_GPIO_WritePin(RELAY_PORT, RELAY_PIN, GPIO_PIN_RESET);
}
else
{
/* Aman & tangki belum penuh → pompa HIDUP */
HAL_GPIO_WritePin(RELAY_PORT, RELAY_PIN, GPIO_PIN_SET);
}
HAL_Delay(100);
}
}
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
__HAL_RCC_GPIOA_CLK_ENABLE();
/* INPUT */
GPIO_InitStruct.Pin = FLAME_PIN | FLOAT_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* OUTPUT */
GPIO_InitStruct.Pin = LED_PIN | BUZZER_PIN | RELAY_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* Relay default ON */
HAL_GPIO_WritePin(RELAY_PORT, RELAY_PIN, GPIO_PIN_SET);
}
void SystemClock_Config(void)
{
/* Clock default CubeIDE */
}
void Error_Handler(void)
{
while (1) {}
}
g. Download File
Komentar
Posting Komentar