I built a 3D printer for use here at work, and we recently got 10Kg spools due to being out of the size we wanted. I had to build a spool holder, but the pull on the filament due to the weight of the spool is still causing issues. I have a 12 Volt windshield wiper motor and system for moving the spool, but I need some help with the web sensor. I have 2 sets of ADA2167 break beam sensors, I have an arduino relay board for doing the heavy lifting for the motor, but I am unable to write the program that will turn the motor on when the top sensor is tripped and turn off when the lower sensor is tripped. I'm an old mechanical engineer and software eludes me.
Please post a schematic. Written descriptions are always more ambiguous than a drawing. Hand drawn, photographed and posted is fine. Include all pin names/numbers, components, their part numbers and/or values and power supplies.
Supply technical data for the relevant components (motor, motor driver, power supply, sensors, etc.).
A drawing or photos of the mechanical setup would also be useful.
sensors are adafruit ADA2167, they signal and the arduino closes a sparkfun Beefcake relay to drive the windshield motor. they system maintains zero pull on the filament so that the printer drives never get overloaded.
Thanks for the suggestion, loaded and wired it, and discovered the adafruit sensors aren't precise enough to detect the 1.75mm filament. time to find different sensors
I was going to question whether the sensor could pick up anything that thin. Perhaps an idler wheel on an arm, that raises and lowers with the filament, would be a better detector mechanism.
Thank you all for the help, you taught me to fish instead of giving me a fish, got it working last night. might not be beautiful and streamlined but hey it works.
/*
IR Breakbeam sensor demo!
*/
#define LEDPIN 10
// Pin 10 digital pin controlling the Beefcake relay
#define SENSORPIN1 4 //filament tight turn on motor pin 10
#define SENSORPIN2 5 //Filament loose turn off motor pin 10
// variables will change:
int sensorState1 = 0, sensorState2 =0, lastState=0;
int PowerPin = 10; // variable for the motor relay drive signal
void setup() {
// initialize the LED pin as an output:
pinMode(PowerPin, OUTPUT);
// initialize the sensor pin as an input:
pinMode(SENSORPIN1, INPUT);
pinMode(SENSORPIN2, INPUT);
digitalWrite(SENSORPIN1, HIGH); // turn on the pullup
digitalWrite(SENSORPIN2, HIGH); // turn on the pullup
Serial.begin(9600);
}
void loop(){
// read the state of the filament sensors:
sensorState1 = digitalRead(SENSORPIN1);
sensorState2 = digitalRead(SENSORPIN2);
// check if the sensor beam is broken
// if it is, the sensorState is LOW:
if (sensorState1 == LOW) {
// turn motor drive pin 10 on:
digitalWrite(PowerPin, HIGH);
}
if (sensorState2 == LOW) {
// turn motor drive pin 10 off:
digitalWrite(PowerPin, LOW);
}
//if (sensorState1 && !lastState) {
//Serial.println("Unbroken");
//}
// if (!sensorState1 && lastState) {
//Serial.println("Broken");
//}
//lastState = sensorState1;
}
The way I've seen this done before is with a ring that the filament/thread passes through and that ring is on a pivoting arm that either controls a potentiometer to measure position, or toggles a switch (like in your case) at either extreme of travel.
as far as the code goes, this should get you started. It's missing some important things that a final version should have, but it's a start.
enum stateType {STOPPED, MOVE_UP, MOVE_DOWN};
#define UPPER_SWITCH 2
#define LOWER_SWITCH 3
#define MOTOR_PIN 4
void setup() {
// put your setup code here, to run once:
}
void loop()
{
bool upper = digitalRead(UPPER_SWITCH);
bool lower = digitalRead(LOWER_SWITCH);
static stateType state = STOPPED;
switch (state)
{
case STOPPED:
state = upper ? MOVE_DOWN : (lower ? MOVE_UP : STOPPED);
break;
case MOVE_UP:
// Turn on motor
digitalWrite(MOTOR_PIN, HIGH);
state = upper ? STOPPED : MOVE_UP;
break;
case MOVE_DOWN:
// Turn off motor
digitalWrite(MOTOR_PIN, LOW);
state = lower ? STOPPED : MOVE_DOWN;
break;
}
}