코딩정보




● esp32 에 led 구성 회로와 동작 esphome 소스

♨ 카랜더 일정 : 2024년03월06일
  • 링크

  • 첨부

  • 컨텐츠 정보

    본문

    ● esp32 에 led 구성 회로와  동작 esphome 소스


    3232235521_1709652484.8895.png

    User

    esp32 에 led 구성 회로와  동작 esphome 소스를 만들어 주세요

    ChatGPT

    ESP32를 사용하여 LED를 제어하는 회로 및 ESPHome 소스 코드를 제공해 드리겠습니다.

    이 예제에서는 ESP32의 GPIO 핀을 사용하여 LED를 제어하는 간단한 회로를 구성하고,

    ESPHome를 사용하여 이 LED를 제어하는 소스 코드를 작성할 것입니다.


    LED 구성 회로:


    위의 회로에서는 ESP32의 GPIO 핀과 LED 사이에 220옴의 저항을 연결하여 LED를 제어합니다.

    이 회로를 구성한 후에는 ESPHome를 사용하여 이 LED를 제어하는 소스 코드를 작성할 것입니다.

    3232235521_1709684645.3151.png

    ESPHome 소스 코드:

    yaml

    Copy code

    ===============
    esphome:
      name: led_control
      platform: ESP32
      board: esp32dev
    wifi:
      ssid: "YOUR_WIFI_SSID"
      password: "YOUR_WIFI_PASSWORD"
    api:
    ota:
    output:
      - platform: gpio
        pin: GPIO_NUM   # 여기에 GPIO 핀 번호를 입력하세요
        id: led_output
    light:
      - platform: binary
        name: "LED"
        output: led_output


    위의 코드에서 주석으로 표시된 GPIO_NUM을 사용할 GPIO 핀의 번호로 대체해야 합니다.

    또한 WiFi에 연결할 SSID와 암호를 해당 필드에 입력해야 합니다.

    이제 위의 ESPHome 소스 코드를 사용하여 LED를 제어하는 환경을 설정했습니다.

    코드를 ESPHome에 업로드하고 플래시 한 후에는 ESPHome 대시보드에서 LED를 켜고 끌 수 있습니다.

    3232235521_1709654806.0358.png

    Giop23에 220옴과 led연결 + gnd 

    output:
      - platform: gpio
        pin: GPIO_NUM   # 여기에 GPIO 핀 번호를 입력하세요
        id: led_output
    light:
      - platform: binary
        name: "LED"
        output: led_output

    ======

    output:
      - platform: gpio
        pin: GPIO23   # 여기에 GPIO 핀 번호를 입력하세요
        id: led_output
    light:
      - platform: binary
        name: "LED"
        output: led_output

    3232235521_1709655342.5363.png

    3232235521_1709655253.7525.png

    ============

    자동화1
    ---------------
    alias: 1_on_door_esp32_sensor_led_on_off
    description: door_esp32_sensor_led_on_off
    trigger:
      - type: motion
        platform: device
        device_id: e96622a74f26a33af9cd8cc8e8d2101f
        entity_id: c7414ff21859f7042be574cf24608322
        domain: binary_sensor
        for:
          hours: 0
          minutes: 0
          seconds: 1
    condition: []
    action:
      - delay:
          hours: 0
          minutes: 0
          seconds: 0
          milliseconds: 100
      - type: turn_on
        device_id: e96622a74f26a33af9cd8cc8e8d2101f
        entity_id: 325cf3020d65635e54f2a79028b9c6d4
        domain: light
        flash: long
      - delay:
          hours: 0
          minutes: 0
          seconds: 0
          milliseconds: 100
      - service: tts.edge_tts_say
        data:
          cache: false
          entity_id: media_player.speaker_1
          message: 현관 esp32의 센서가 감지 되었습니다. 현관 esp32의 센서가 감지 되었습니다.현관 esp32의 센서가 감지 되었습니다.
      - delay:
          hours: 0
          minutes: 0
          seconds: 0
          milliseconds: 100
    mode: single

    =====================
    자동화2
    ----------
    alias: 2_off_door_esp32_sensor_led_on_off
    description: door_esp32_sensor_led_on_off
    trigger:
      - type: no_motion
        platform: device
        device_id: e96622a74f26a33af9cd8cc8e8d2101f
        entity_id: c7414ff21859f7042be574cf24608322
        domain: binary_sensor
        for:
          hours: 0
          minutes: 0
          seconds: 1
    condition: []
    action:
      - delay:
          hours: 0
          minutes: 0
          seconds: 0
          milliseconds: 100
      - type: turn_off
        device_id: e96622a74f26a33af9cd8cc8e8d2101f
        entity_id: 325cf3020d65635e54f2a79028b9c6d4
        domain: light
      - delay:
          hours: 0
          minutes: 0
          seconds: 0
          milliseconds: 100
    mode: single
    ================

    ...end,,,,

    자동화 구성

    on 동작

    3232235521_1711367160.8921.png

    off 동작

    3232235521_1711367216.383.png



    [ 추가 정보 ... 더보기) ]
    뷰PDF 1,2



    office view

    관련자료

    댓글목록

    profile_image

    11qkr님의 댓글

    11qkr 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 아이피 (192.♡.0.1) 작성일

    output:
      - platform: gpio
        pin: GPIO0
        id: led_output

    light:
      - platform: binary
        name: "LED_Sensor_only_GPIO3"
        output: led_output
    # wifi 옵션 power_save_mode: LIGHT 적용햐야 컴파일 됩니다esp32_ble_tracker:
    esp32_ble_tracker:

    binary_sensor:
      - platform: ble_presence
        ibeacon_uuid: 'a26fbca9-870e-4293-ad0b-aab3e0defc4e'
        name: "myphone"

      - platform: ble_presence
        ibeacon_uuid: '7cad13d3-e06e-4493-b771-c2a27e46695c'
        name: "mywife"

      - platform: gpio
        pin: GPIO2
        name: "PIR Sensor"
        device_class: motion
        id: pir_sensor_only_GPIO2
        on_press:
          then:
            - text_sensor.template.publish:
                id: pir_countup
                state: !lambda |-
                  static int pir_counter = 0;
                  pir_counter++;
                  id(pir_last_trigger).publish_state(std::to_string(pir_counter));
                  // 매 60분마다 초기화
                  if ((millis() / 60000) % 60 == 0) pir_counter = 0;
                  return std::to_string(pir_counter);

    switch:
      - platform: restart
        name: "Restart Node"
        id: restart_node

      - platform: template
        name: "Reset PIR Sensor Count"
        id: reset_pir_count
        icon: "mdi:refresh"
        turn_on_action:
          - text_sensor.template.publish:
              id: pir_countup
              state: "0"
          - text_sensor.template.publish:
              id: pir_last_trigger
              state: "0"

    sensor:

      - platform: uptime
        name: Uptime Sensor 
        update_interval: 1s
        entity_category: "diagnostic"
        id: uptime_sensor

      - platform: wifi_signal
        name: "WiFi Signal dB"
        id: wifi_signal_db
        update_interval: 30s
        entity_category: "diagnostic"

      - platform: copy
        source_id: wifi_signal_db
        name: "WiFi Signal Percent"
        filters:
          - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
        unit_of_measurement: "Signal %"
        entity_category: "diagnostic" 

    text_sensor:
      - platform: version
        name: "Install restart time ESPHome Version"

      - platform: template
        name: Uptime
        update_interval: 1s
        lambda: |-
          auto s = millis() / 1000;
          return str_snprintf("%02d:%02d:%02d:%02d", 11, s / 86400, s / 3600 % 24, s / 60 % 60, s % 60);

      - platform: template
        name: "PIR Sensor Counter"
        id: pir_countup
      - platform: template
        name: "PIR Last Trigger"
        id: pir_last_trigger

      - platform: template
        name: Uptime_PIR_Off
        update_interval: 1s
        entity_category: diagnostic
        lambda: |-
          static unsigned long last_pir_time = 0;
          if (id(pir_sensor_only_GPIO2).state) {
            last_pir_time = millis();
          }
          unsigned long uptime_seconds = (millis() - last_pir_time) / 1000;
          return esphome::optional<std::string>(std::to_string(uptime_seconds));

    답변
    profile_image

    11qkr님의 댓글

    11qkr 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 아이피 (192.♡.0.1) 작성일

    alias: 현관센서led2_감지센서_to_led_gpio23
    description: 현관센서led2_on_senser_to_led_gpio23
    trigger:
      - type: motion
        platform: device
        device_id: e96622a74f26a33af9cd8cc8e8d2101f
        entity_id: c7414ff21859f7042be574cf24608322
        domain: binary_sensor
    condition: []
    action:
      - service: light.turn_on
        data: {}
        target:
          entity_id: light.sensor_only_led_sensor_only_gpio3
      - service: light.turn_off
        data: {}
        target:
          entity_id: light.sensor_only_led_sensor_only_gpio3
    mode: single

    답변



    ♥간단_메모글♥


    최근글


    새댓글



    PHP 안에 HTML ☞ 홈페이지 화면갱신 시간은 ♨
    ▶ 2024-04-29 00:40:36

    오늘의 홈 현황


    • 현재 접속자♨ 150 명
    • 오늘 가입자※ 0 명
    • 어제 가입자※ 2 명
    • 주간 가입자※ 17 명
    • 오늘 방문자 376 명
    • 어제 방문자 1,688 명
    • 최대 방문자 13,042 명
    • 전체 방문자 4,293,830 명
    • 전체 게시물※ 8,540 개
    • 전체 댓글수※ 24,526 개
    • 전체 회원수 10,935 명

    QR코드


    ☞ QR코드 스캔은 kakao앱 자체 QR코드

    알림 0








    최신글↑