Raspberry PI Zero W

Initial SD card setup:

  • Add to cmdline.txt to enable Ethernet-over-USB:
    modules-load=dwc2,g_ether
  • Create empty file ssh to start SSH server automatically

Initial server setup:

  • Install x11vnc:
    # apt-get install x11vnc
    $ x11vnc -storepasswd
    # echo 'su -l -c "x11vnc -rfbauth /home/pi/.vnc/passwd" pi'
  • Other packages: apt-get install vim tmux

Arduino

Arduino Nano pinout Arduino RF-Nano pinout ESP8266 WeMos D1 mini ESP32 S2 mini NodeMCU V3 pinout NodeMCU V1 / V2 / V3 pinout ESP8266 models Wemos D1 mini versions

:INFO: When selecting ATmega328 vs ESP8266 based solution, consider that ATmega328 would need 5V sensors, but ESP8266 would need 3-to-5V step-up when controlling LEDs.

:INFO: ESP8266 has D3 / GPIO0 and D4 / GPIO2 10k pull-up + D8 / GPIO15 10k pull-down resistors, see LOLIN D1 mini description.

Name Price CPU CPU clock Flash SRAM / PSRAM Networking Power Interface PWM DAC Notes
Arduino Nano v3.0 €3.60 + €0.92 = €4.52 ATmega328P 16Mhz 32KB 2KB :NO: shield costs €2.51 + €0.67 = €3.18 5..12V MiniUSB :YES: :YES:
LoLin NodeMCU V3 €1.89 + €0.88 = €2.77 ESP8266 80MHz 4MB 64KB 2.4GHz WiFi 802.11 b/g/n 3.3..12V (e.g. 3.7V LiIon) MicroUSB :YES: :NO:
Wemos D1 mini V1 €1.76 + €0.66 = €2.42 ESP8266 80MHz 4MB 64KB 2.4GHz WiFi 802.11 b/g/n 3.3..12V (e.g. 3.7V LiIon) MicroUSB :YES: :NO:
Wemos D1 mini Pro V1.1 €2.67 + €0.65 = €3.32 ESP8266 80MHz 16MB 128KB 2.4GHz WiFi 802.11 b/g/n 3.3..12V (e.g. 3.7V LiIon) MicroUSB :YES: :NO:
Wemos ESP32-S2 Mini €2.69 240MHz 4MB 320KB / 2MB 2.4GHz WiFi 802.11 b/g/n 5V (USB) USB-C :YES: 2× (GPIO17+18)
ESP32-C3 SuperMini €2.39 ESP32C3FN4 160MHz 4MB 400KB 2.4GHz WiFi 802.11 b/g/n, Bluetooth 5.0 5V (USB) USB-C :YES: 43µA in deep sleep, 22.5×18 mm
ESP32-C6 €12.45 ESP32C6FH4 160MHz 4MB 512KB HP + 16KB LP Wi-Fi 6 (2.4 GHz), Bluetooth 5.0 (LE), Thread (802.15.4) 5V (USB) USB-C :YES: 26×18 mm

Check:

Arduino clones need FTDI CH430 drivers from here (CH341SER.ZIP).

ESP

  • ESPHome is a tool which reads in a YAML configuration file (just like Home Assistant) and creates a custom firmware binary. The tool also has many helpers that simplify flashing devices (uploading the new binary file) and aim to make managing your ESP boards as simple as possible.

LED strips

Smart meter

P1 port (ESMRv5.0 P1) pinout Connecting ESP8266 to the P1 meter

Logical inverter based on BS170 Logical inverter based on BS170 with additional resistor

Challenges:

ESPHome installation:

  • Install ESPHome from docker and open http://localhost:6052/:
    # docker run --rm --net=host --privileged -v "$(pwd):/config" esphome/esphome
  • Paste the following configuration then press Install → Manual Download which will compile the firmware and offer smart_meter.bin file which should be saved locally:
    esphome:
      name: smart_meter
      friendly_name: "Smart meter"
    
    esp8266:
      board: d1_mini  # For complete list check https://registry.platformio.org/platforms/platformio/espressif8266/boards
    
    logger:
      hardware_uart: UART1 # D4 on D1 mini
      tx_buffer_size: 4096
    
    ota:
      - platform: esphome
        password: "<replace password>"
    
    api:  # Expose API for Home Assistant integration
    
    wifi:
      ssid: "<replace network>"
      password: "<replace password>"
    
    substitutions:
      mqtt_prefix: "smart_meter"
    
    mqtt:
      broker: 192.168.1.10
      username: "<replace user>"
      password: "<replace password>"
      topic_prefix: "${mqtt_prefix}"
      log_topic: "${mqtt_prefix}/logs"
      keepalive: 300s  # Otherwise MQTT client reconnects every 15 seconds
    
    uart:
      rx_pin: GPIO3  # RX pin on D1 mini
      baud_rate: 115200
      rx_buffer_size: 1500  # A bit bigger than P1 message size
    
    sensor:
      - platform: dsmr
        power_delivered:
          name: "Power Currently Consumed"
          state_topic: "${mqtt_prefix}/power_consumed"
        power_returned:
          name: "Power Currently Produced"
          state_topic: "${mqtt_prefix}/power_returned"
        voltage_l1:
          name: "Voltage L1"
          state_topic: "${mqtt_prefix}/voltage_l1"
        current_l1:
          name: "Current L1"
          state_topic: "${mqtt_prefix}/current_l1"
        energy_delivered_tariff1:
          name: "Total Energy Consumed Tariff 1"
          state_topic: "${mqtt_prefix}/energy_consumed_tariff1"
        energy_delivered_tariff2:
          name: "Total Energy Consumed Tariff 2"
          state_topic: "${mqtt_prefix}/energy_consumed_tariff2"
        energy_returned_tariff1:
          name: "Total Energy Produced Tariff 1"
          state_topic: "${mqtt_prefix}/energy_returned_tariff1"
        energy_returned_tariff2:
          name: "Total Energy Produced Tariff 2"
          state_topic: "${mqtt_prefix}/energy_returned_tariff2"
  • Open https://web.esphome.io/ in Chrome, press Connect and choose the appropriate COM port ESP8266 is connected to. Press Install → Choose file, select previously downloaded smart_meter.bin and press Install.
  • After 1st installation it is possible to update firmware wirelessly using OTA (choose Wirelessly). ESPHome installator will automatically display logs using API connection.
  • Alternatively one can monitor logs using mosquitto_sub -v -t 'smart_meter/#' -u aaa -P bbb

Network:

Ethernet Shield ENC28J60 pinout

Power saving:

Sensors

IR infrared universal receiver TL1838 VS1838 pinout SR602 motion detector pinout BME280 (humidity, pressure and temperature) vs BMP280 (pressure and temperature)

Vibration

Curtain

Temperature

The BME280 has more precise measurements but has its own problems too, as it suffers from self-heating in its default configuration (sampling data continuously). The library should switch the sensor into forced mode to make it sleep when the measurement is finished, see this comment and this post.

Infrared thermograph / temperature sensor

Climate control / CO₂

Oximeter / pulsometer

Door bell

Measuring current:

  • Схема детектора тока на оптопаре:

    В сумме резисторы определяют ток протекающий через светодиод. Чем он меньше, тем больше сопротивление перехода коллектор эмитер транзистора. Поскольку транзистор работает на высокоомный вход GPIO, то, думаю, конденсатор на 5-10 мкф + резистор подтяжки в пределах 10-20 кОм хватит. Наверно можно отойти от рекомендаций даташита и ограничить ток светодиодов парой милиампер (резисторы меньше греться будут) – тогда можно поставить два резистора в пределах 50 кОм.

    Для вычисления мощности резисторов берём закон Ома и считаем. Как на постоянном токе, считаем действующие значения тока и напряжения. 220В у нас падает на двух последовательных резисторах и диоде. Ну на диоде упасть больше 2В в принципе не может (как и меньше тоже) – им пренебрегаем – и считаем ток в цепи 220В/(50+50) кОм = 2.2 мА. Мощность рассеиваемая на резисторе считаем по формуле I×I×R = 2мА×2мА×50кОм=0.24 Вт плюс на втором резисторе ещё 0.24Вт, т.е всего рассеивается 0.48Вт чистым теплом. Поверьте это не мало. Один резистор в 100 кОм должен был бы рассеять почти 0.5Вт тепла. Хотя для варианта с детекцией дверного звонка этот кратковременный нагрев можно не считать проблемой.

Logical converter

USB-UART converter

Front PCB Schematic

CH340E:

CH340 supports 5V and 3.3V operation. When using 5V operation, supply 5V to VCC pin, and decouple the internal 3.3V reference with a capacitor of 4.7-20nF from V3 pin to ground. When using 3.3V operation, tie V3 pin to VCC pin and supply 3.3V power.

Controlling the power

Using relay

Using MOSFET e.g. IRLB3034PbF

  • Drain-to-Source Breakdown Voltage (V(BR)DSS): 40V
  • Gate Threshold Voltage (VGS(th): 1.0-2.5V
  • Static Drain-to-Source On-Resistance (RDS(on)): 1.6-2.0 mΩ
    • Рассеиваемая мощность при токе 5A: Pdis = 2mΩ × (5A)2 = 0.002Ω × 25A = 0.05W → температура корпуса транзистора будет RθJA × Pdis + Croom = 0.05W × 62°C/W + 25°C = 27.1°C

See also:

Using Solid State Relays (SSR)

Using dedicated controller + MOSFET

Dimmer

Other automations

FAQ

Arduino Nano uploading gives error: avrdude: stk500_recv(): programmer is not responding

In Arduino UI choose Tools → Processor → ATmega328P (Old Bootloader).

Arduino Nano build-in LED conflicts with Ethernet shield

This is because the LED is on pin 13 and pin 13 is the clock pin for SPI device like Ethernet shield.

Alternative way to flash Wemos D1

Flash ESP-01 with your NodeMCU

With NodeMCU:

Connect the following pins between NodeMCU and Wemos D1:

  • RX → RX
  • TX → TX
  • D3 → D3
  • RST → RST
  • 3.3V → 3.3V
  • GND → GND
  • EN → GND

With USB-TTL converter:

  • RX → TX
  • TX → RX
  • 3.3V → 3.3V
  • GND → GND
  • D3 → GND (GPIO0 should be grounded when ESP is starting)

NodeMCU v3 (LoLin) built-in LED features

:WARN: LEDs operate in “inverted” mode, with regard to the pin levels – when the pin is LOW, the LED is on.

:WARN: Runnning pinMode(1, OUTPUT); breaks serial communication (when doing Serial.println("..."); nothing is printed) because pin 1 and 3 are reserved for TX/RX.

:WARN: Builtin LED on NodeMCU v3 (LoLin) is on D4 (pin 2) i.e. use pinMode(2, OUTPUT);

hardware/arduino.txt · Last modified: 2025/04/29 02:41 (external edit)
 
 
Recent changes RSS feed Driven by DokuWiki