ESP8266 servo not working

Hi All,

(I’m a complete beginner - this is my first project - so appologies if I’m using the wrong terminology)

I’m trying to controll a M995 servo throug an ESP8266 NODEMCU board. With the servo I want to open/close the “garage door” of the robot vacuum.

I’m struggling a bit with getting the servo to work, and control manually via HA.

The ESP8266 is connected with the servio with 3 pins:

  • Ground
  • 3.3V
  • Data pin: D2 or D4 (I’m still not sure which one to use)

The ESP is powerd via the USB port.

I have the following code in ESPHOME:

esphome:
  name: esphome-web-51c3d9
  friendly_name: ESPHome Web 51c3d9

esp8266:
  board: esp01_1m

# Enable logging
logger:

ota:


wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password


mqtt:
  broker: 192.168.1.30
  username: "mqtt-user"
  password: "mqtt-user"

captive_portal:

api:
  encryption:
    key: "oARUE9evAMuivfhAH2VX0E1KbAhcSLtjqlzWmlf3ChI="
  services:
    - service: control_servo
      variables:
        level: float
      then:
        - servo.write:
            id: my_servo
            level: !lambda 'return level / 100.0;'


output:
  - platform: esp8266_pwm
    id: pwm_output
    pin: GPIO2
    frequency: 50 Hz

servo:
  - id: my_servo
    output: pwm_output

Log:

INFO ESPHome 2023.9.3 
INFO Reading configuration /config/esphome/esphome-web-51c3d9.yaml... 
INFO Starting log output from esphome-web-51c3d9.local using esphome API 
INFO Successfully connected to esphome-web-51c3d9.local 
[01:30:22][I][app:102]: ESPHome version 2023.9.3 compiled on Oct 7 2023, 01:23:17 
[01:30:22][C][wifi:546]: WiFi: 
[01:30:22][C][wifi:382]: Local MAC: 8C:AA:B5:51:C3:D9 
[01:30:22][C][wifi:383]: SSID: 'Proximus-Home-8800'[redacted] 
[01:30:22][C][wifi:384]: IP Address: 192.168.1.31 [01:30:22][C][wifi:385]: BSSID: AC:15:A2:F4:E4:E4[redacted] 
[01:30:22][C][wifi:387]: Hostname: 'esphome-web-51c3d9' 
[01:30:22][C][wifi:389]: Signal strength: -65 dB ▂▄▆█ 
[01:30:22][C][wifi:393]: Channel: 9 
[01:30:22][C][wifi:394]: Subnet: 255.255.255.0 
[01:30:22][C][wifi:395]: Gateway: 192.168.1.1 
[01:30:22][C][wifi:396]: DNS1: 192.168.1.1 
[01:30:22][C][wifi:397]: DNS2: 0.0.0.0 
[01:30:22][C][logger:357]: Logger: 
[01:30:22][C][logger:358]: Level: DEBUG 
[01:30:22][C][logger:359]: Log Baud Rate: 115200 
[01:30:22][C][logger:361]: Hardware UART: UART0 
[01:30:22][C][esp8266_pwm:022]: ESP8266 PWM: 
[01:30:22][C][esp8266_pwm:023]: Pin: GPIO2
 [01:30:22][C][esp8266_pwm:024]: Frequency: 50.0 Hz
[01:30:22][C][servo:013]: Servo: 
[01:30:22][C][servo:014]: Idle Level: 7.5% 
[01:30:22][C][servo:015]: Min Level: 3.0% 
[01:30:22][C][servo:016]: Max Level: 12.0% 
[01:30:22][C][servo:017]: auto detach time: 0 ms 
[01:30:22][C][servo:018]: run duration: 0 ms 
[01:30:22][C][captive_portal:088]: Captive Portal: 
[01:30:22][C][mdns:115]: mDNS:
[01:30:22][C][mdns:116]: Hostname: esphome-web-51c3d9 
[01:30:22][C][ota:097]: Over-The-Air Updates: 
[01:30:22][C][ota:098]: Address: esphome-web-51c3d9.local:8266 
[01:30:22][C][mqtt:133]: MQTT: 
[01:30:22][C][mqtt:134]: Server Address: 192.168.1.30:1883 (192.168.1.30) 
[01:30:22][C][mqtt:136]: Username: 'mqtt-user'[redacted] 
[01:30:22][C][mqtt:137]: Client ID: 'esphome-web-51c3d9-8caab551c3d9'[redacted] 
[01:30:22][C][mqtt:139]: Discovery prefix: 'homeassistant' 
[01:30:22][C][mqtt:140]: Discovery retain: YES 
[01:30:22][C][mqtt:142]: Topic Prefix: 'esphome-web-51c3d9' [01:30:22][C][mqtt:144]: Log Topic: 'esphome-web-51c3d9/debug' 
[01:30:22][C][mqtt:147]: Availability: 'esphome-web-51c3d9/status' 
[01:30:22][C][api:138]: API Server: 
[01:30:22][C][api:139]: Address: esphome-web-51c3d9.local:6053 
[01:30:22][C][api:141]: Using noise encryption: YES 
[01:30:27][I][ota:117]: Boot seems successful, resetting boot loop counter.

Is this ok?

I don’t fully understand this part:
"Successfully connected to esphome-web-51c3d9.local "
=> shouldn’t it connect to my wifi? Strange enough, I see it online in HA. So I’m confused.

Now the next step: how do I manually move spin the servo? Should I be using the D2 or D4 pin?
What do I have to do in HA?
I see the device under ESPHome, and also under MQTT. But I can’t seem to change anything.
Under MQTT there is a slicer:


But again, it’s not working. When I move the sliver, the servo is not moving. Also when I refresh the page, the value goes back to it’s original value (-30).

Any clue what I’m doing wrong?
Regards,
Jonas

I am fairly new myself and currently having my own trouble with PWM but here is what i do know from your questions.

1.The servo should be connected to D4 which is GPIO2 as you have defined.
2. The .local in the log is the “local” domain that your server is in and should mean you are connected to the server via wifi just fine. You should be able to see it on the connected client list of your wifi access point.

Sorry I can’t help more but hopefully someone else can fill in the gaps!

1 Like

Hello. Maybe try to use frendly name that does not contain spaces. For example in your ESP YAML file:
" esphome:
name: “ESP1”
friendly_name: ESP1 " ← here
This is a name that Home Assistant use and so the name that should be in automations.yaml:
" action:

  • service: esphome.ESP1_control_servo " ← change the ESP1 if you have set diffrent friendly name earlier.
    It worked for me after a long time of flustration…