Need help with Arduino - RJB INDUSTRIES

Meaningful discussion outside of the potato gun realm. Projects, theories, current events. Non-productive discussion will be locked.
User avatar
evilvet
Specialist 2
Specialist 2
Posts: 267
Joined: Sat May 01, 2010 2:48 am
Been thanked: 2 times

Sat Apr 27, 2013 4:09 pm

Not a gun yet, just some bits on the bench.

For my next trick I need to design and construct an alignment circuit, something to tell me that the drum is in the correct starting position for the stepper to index from. I am thinking of an IR photodiode hooked up as a voltage divider with a LED illuminating the diode via a hole in the drum.

This might give you an idea of where I am headed.
Attachments
2013-04-24_12-37-10_498.jpg
User avatar
evilvet
Specialist 2
Specialist 2
Posts: 267
Joined: Sat May 01, 2010 2:48 am
Been thanked: 2 times

Sat Apr 27, 2013 10:53 pm

Update:

Grabbed a BP104 IR photodiode and an IR LED, changed some code and hey presto, it works.

Press Button 2 and the rotary magazine spins slowly and at the same time polls for voltage on Analogue Pin 1. The theory is a small hole in the magazine plate that aligns with two others, one on each side of the breech. When the holes are lined up the voltage at the pin goes high due to the IR LED shining on the photodiode and the rotation stops.

Now you can press Button 1 and the first relay fires, this activates the solenoid valve that pilots the QEV and launches the round. The next relay fires to open and close the solenoid that feeds from the bulk HPA source to the chamber. Finally the drum then rotates by a preset number of steps to align the next round.

TO DO:

**
Change the code on BUTTON TWO so that instead of looking for a threshold value it runs until the voltage has declined for two or more readings, that should mean the LED is being obscured by the drum moving past the best alignment point.

**
Finish the mechanical stuff so I can get the electronics bolted on.


It's starting to get cold, winter is coming so I foresee a long series of nights in the shed tinkering with this until Spring.

[edit]

[youtube]

[/youtube]

New code is below.

Code: Select all


const int StepPin =  13;      // the number of the Stepper Motor signal pin
const int ButtonPin1 = 2;     // the number of the pushbutton pin
const int ButtonPin2 = 5;     // the number of the pushbutton pin
const int RelayPin1 = 3;     // the number of the first relay
const int RelayPin2 = 4;     // the number of the second relay
int SensePin = 1; //the analog pin the anode of the IR photodiode is connected to
int SensorValue;
int ButtonState1 = LOW;
int ButtonState2 = LOW;


void setup() {
  // initialize the Stepper Driver pin and the relay pins as outputs:
  pinMode(StepPin, OUTPUT);
  pinMode(RelayPin1, OUTPUT);
  pinMode(RelayPin2, OUTPUT);
  // initialize the pushbutton pins as inputs:
  pinMode(ButtonPin1, INPUT);     
  pinMode(ButtonPin2, INPUT);     
  Serial.begin(115200);
}

void loop(){
  // read the state of the pushbutton value:
  ButtonState1 = digitalRead(ButtonPin1);
  ButtonState2 = digitalRead(ButtonPin2);
  if (ButtonState1 == HIGH) //Has the button been pushed ?
  {
    Serial.println("BUTTON ONE HAS BEEEN PRESSED");
    delay(1000); //remove after debug
    digitalWrite(RelayPin1, HIGH); //Fire the solenoid valve and reset the pin
    Serial.println("Relay 1 fired");
    delay(500); //Open the pilot valve for 500 milliseconds
    digitalWrite(RelayPin1, LOW);
    digitalWrite(RelayPin2, HIGH); 
    Serial.println("Relay 2 fired");
    delay(2000); //Leave the relay on for two secconds to fully pressurize the chamber
    digitalWrite(RelayPin2, LOW);
    for (int Step1Count = 1; Step1Count < 18 ; Step1Count++){ //change the number of steps to equal 1/8th rotation
      Serial.print("Step One Count = ");
      Serial.println(Step1Count); //Remove once debugging finished
      digitalWrite(StepPin, HIGH); // Send X pulses to the stepper controller
      delay(10);
      digitalWrite(StepPin, LOW);
      delay(10);
    }
  }
  else if (ButtonState2 == HIGH) //Has the button been pushed ?
  {
    Serial.println("BUTTON TWO HAS BEEEN PRESSED");
    delay(1000);
    for (int Step2Count = 1; Step2Count <2000>= 750) //0-1024 possible values, need to play with this to get max alignment
      {
        digitalWrite(StepPin, LOW);
        break;
      }
     }
  }
  else
  {
    Serial.println("Button 2 Waiting..........."); 
    Serial.println("Button 1 Waiting..........."); 
  }
}

Post Reply