Recently I acquired the Sentro knitting machine for my wife to knit beanies for her business. She quickly let me know that the row counter on the machine was faulty. After some googling I found that this was a common occurrence and that a digital counter was available for purchase.
But why buy when you can build?
I grabbed some components and threw together a basic row counter for her that outputs the row numbers to a webpage. My next iteration will include a digital display but I didn't have the components handy.
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
const char* ssid = "SSID_XXXXXX";
const char* password = "PAssword_XXXXXX";
// Initialize Hall effect sensor on pin D2
const int hallSensorPin = D2;
int magneticFieldCount = 0;
ESP8266WebServer server(80);
void handleRoot() {
server.send(200, "text/plain", "Magnetic field count: " + String(magneticFieldCount));
}
void setup() {
pinMode(hallSensorPin, INPUT_PULLUP);
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("WiFi connected!");
server.on("/", handleRoot);
server.begin();
}
void loop() {
if (digitalRead(hallSensorPin) == LOW) {
// Hall effect sensor detected a magnetic field
magneticFieldCount++;
delay(1000); // Debounce delay
}
server.handleClient();
}





Comments