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:
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;
}