Continuous servo code not working - any errors? Automatic feeder

Hi, I am using a servo to turn a food dispenser, which is triggered when a word is said by my Twitch chat bot. This works with a normal servo, however I chose to switch to a continuous servo to better control the amount of food. The setup is like this:

I am using a NodeMCU ESP8266 like this:

diagram

When I connect the power or signal cable, the servo twitches slightly. It only does this on the D1 (5) signal pin. However, nothing happens when the keyword is triggered. I don't believe the problem is the Twitch chatbot setup as this works with a normal servo.

Code:

/*******************************************************************
Connect to Twtich Chat with a Bot
Created with code from TheOtherLoneStar (Twitch)
Hackaday IO: theotherlonestar's Profile | Hackaday.io
By Brian Lough (Twitch)
YouTube: https://www.youtube.com/channel/UCezJOfu7OtqGzd5xrP3q6WA
Created with code from noycebru Twitch
*******************************************************************/

#include <ESP8266WiFi.h> //GitHub - esp8266/Arduino: ESP8266 core for Arduino
#include <IRCClient.h>
#include <Servo.h>

Servo servo;

//define your default values here, if there are different values in config.json, they are overwritten.
#define secret_ssid "my ssid"
#define IRC_SERVER "irc.chat.twitch.tv"
#define IRC_PORT 6667

//------- Replace the following! ------
char ssid[ ] = "redacted"; // your network SSID (name)
char password[] = "redacted"; // your network key

//The name of the channel that you want the bot to join
const String twitchChannelName = "redacted"; //this is case sensitive!

//The name that you want the bot to have
#define TWITCH_BOT_NAME "squirrel_cam"

//OAuth Key for your twitch bot
// Twitch Chat Password Generator
#define TWITCH_OAUTH_TOKEN "redacted"

//------------------------------

int feeder = 5;
String ircChannel = "";

WiFiClient wiFiClient;
IRCClient client(IRC_SERVER, IRC_PORT, wiFiClient);

// put your setup code here, to run once:
void setup() {

servo.attach(5);
pinMode(feeder, OUTPUT);
delay(2000);
Serial.begin(115200);
Serial.println();

// Set WiFi to station mode and disconnect from an AP if it was Previously
// connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);

// Attempt to connect to Wifi network:
Serial.print("Connecting Wifi: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
IPAddress ip = WiFi.localIP();
Serial.println(ip);

ircChannel = "#" + twitchChannelName;

client.setCallback(callback);
}

void loop() {

// Try to connect to chat. If it loses connection try again
if (!client.connected()) {
Serial.println("Attempting to connect to " + ircChannel );
// Attempt to connect
// Second param is not needed by Twtich
if (client.connect(TWITCH_BOT_NAME, "", TWITCH_OAUTH_TOKEN)) {
client.sendRaw("JOIN " + ircChannel);
Serial.println("connected and ready to rock");
sendTwitchMessage("It's feeding time!");
} else {
Serial.println("failed... try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
return;
}
client.loop();
}

void sendTwitchMessage(String message) {
client.sendMessage(ircChannel, message);
}

void callback(IRCMessage ircMessage) {
//Serial.println("In CallBack");

if (ircMessage.command == "PRIVMSG" && ircMessage.text[0] != '\001') {
//Serial.println("Passed private message.");

ircMessage.nick.toUpperCase();

String message("<" + ircMessage.nick + "> " + ircMessage.text);

//prints chat to serial
Serial.println(message);

//this is where you would replace these elements to match your streaming configureation.

if (ircMessage.text.indexOf("nuts!") > -1 && ircMessage.nick == "SQUIRREL_CAMBOT")
  {

  servo.write(180);
  delay(9000);
  servo.write(90);
 
}

}

return;

}

If you really would connect a servo to 6V AC (alternating current) the servo and your nodeMCU-board would have been damaged.
It has to be DC .

servo.write(180);

180 is the maximum-value which might be behind what some servos can deal with. Did you try something like
servo.write(140); ?

If your full code is not working. Go back to small test-programs
which means use a small testprogram that does nothing more than
servo.write(10);
delay(2000);
servo.write(90);
delay(2000);
servo.write(140);
delay(2000);

to test if the continous servo is working with the RC-signal generated by the microcontroller.

best regards Stefan

Hello
Please post a link for the used servo.

hI,

@juanshot2 If you have developed you code in stages you should already have the code suggested by @StefanL38

Tom..... :grinning: :+1: :coffee: :australia:

Why attach() servo to pin 5 then also have a pin 'feeder' which is also 5 and specifically set to OUTPUT?

And are you sure that having a continuous servo rotating at full speed for 9 seconds will give "better control" than moving a normal servo into position and then back?

Steve

juanshot2, did you ever figure this out?
I'm trying to figure out this exact same issue right now
Hopefully you are still active on here!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.