0
\$\begingroup\$

I have desined a circuit with a motor that controls an opening\closing door (of a Skinner box). Below attached a figure of the circuit.

The switches are for the door, not to keep moving when it is already in desired position. (i.e., not to continue openong when it is already open, and not to continue closing when it is already closed). When the door is fully open, the Op_switch is pressed and when it is fully closed, the Cl_switch is pressed.

The problem is, I want the switches not to be controlled by the arduino. I want them to be mechanically connected to the circuit.

  1. If the Cl_switch is pressed, I want the door not to be able to keep closing (but to be able keep opening).
  2. If the Cl_switch is pressed, I want the door not to be able to keep closing (but to be able keep opening).

Is there a way to do that without the arduino? (I attach also my arduino program).

Thank you! enter image description here enter image description here

Here is the full arduino code:

int IN1=8;
int IN2=9;
int IN4=4;
int ENA=7;
const int IRLEDpin = 3;
const int PhotoPins = A1;
int thr = 0;
int temp;
int numPorts = 1;
int PhotoSensor = 0;
int swtch_open=2;
int swtch_close=1;
int swtch_stat=0; // 0 means pressed 1 means not pressed
int motor = 2; 
void setup() {
 Serial.begin(9600);
 initPorts();
 reset();
 pinMode(IN1,OUTPUT);
 pinMode(IN2,OUTPUT);
 pinMode(IN4,OUTPUT);
 pinMode(swtch_open,INPUT);
 digitalWrite(IN4,HIGH);
 //pinMode(swtch_close,INPUT);
}
void loop(){ 
 analogWrite(ENA, 250); // motor speed
 readmyPorts();
 if (PhotoSensor == 1) { 
 motor = 0;
 }
 if (motor == 2){ 
 OpenDoor();
 }
 if (motor == 1) {
 readswtch();
 if (swtch_stat == 0) { // 0 means switch pressed
 motor = 0;
 }
 }
 if (motor == 0) {
 StopDoor();
 }
 //delay (3000);
 //motor = 2;
}
void OpenDoor() {
 motor = 1;
 digitalWrite(IN1,HIGH);// rotate forward
 digitalWrite(IN2,LOW);
}
void CloseDoor() {
 motor = 1;
 digitalWrite(IN1,LOW);// rotate backwards
 digitalWrite(IN2,HIGH);
}
void StopDoor() {
 motor = 0;
 digitalWrite(IN1,LOW);// stop motor
 digitalWrite(IN2,LOW);
}
void initPorts() {
 pinMode(IRLEDpin, OUTPUT);
 digitalWrite(IRLEDpin, HIGH);
}
void reset() {
 thr = 0;
 for (int j = 0; j < 5; j++) {
 temp = analogRead(PhotoPins);
 if (temp > thr){ 
 thr = temp;
 }
 }
 thr = thr - 20;
}
void readswtch() {
 if (digitalRead(swtch_open) == HIGH)
 { 
 swtch_stat = 1;
 }
 else if (digitalRead(swtch_open) == LOW)
 { 
 swtch_stat = 0;
 }
 }
void readmyPorts() {
 int value = analogRead(PhotoPins);
 if (value < thr) {
 Serial.println("object in the way");
 PhotoSensor = 1;
 }
 else {
 Serial.println("clear to go");
 PhotoSensor = 0;
 }
}
asked Apr 16, 2018 at 13:29
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Why do you wish them to be mechanically connected to the circuit? If you have it working in principle, it would be pretty simple to wire the switches to the pins of the arduino, and have the arduino respond to these switches... this way your switches are likely to be cheaper, and you can then use software to change or update functionality. You might even get away with a single push button switch this way. Your failsafe conditions are easy to implement this way. \$\endgroup\$ Commented Apr 16, 2018 at 14:05
  • 1
    \$\begingroup\$ Tip: Turn off the grid before taking screengrabs if you want people to be able to read your schematic. \$\endgroup\$ Commented Apr 16, 2018 at 17:20

2 Answers 2

3
\$\begingroup\$

So you want the limit switches to be a hardware interlock to the motor.

You can use a logic gates to force the inputs of the motor driver to remain off should the arduino try to move beyond the limits.

For example if the close limit switch is pressed it then forces the output the driver sees coming from pin9 to be LOW regardless what the arduino tries to do. But it still allows the other pin to be pulled high so the motor can reverse.

schematic

simulate this circuit – Schematic created using CircuitLab

Repeat for the other pin.

You can still connect the switch to the arduino to read the switch state. In this configuration a HIGH signal means the switch is not hit and a LOW signal means the limit switch is hit.

answered Apr 16, 2018 at 14:20
\$\endgroup\$
2
\$\begingroup\$

schematic

simulate this circuit – Schematic created using CircuitLab

Figure 1. With addition of D5 and D6 motion can be stopped by limit switches at the motor. The diodes prevent further motion in the same direction when the limit is reached but allow reversal of the motor.

answered Apr 16, 2018 at 17:18
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.