so I should have to create a int for IR sensor right?
Ah ok.
Have a look at the example in the pdf you posted : at some point you will read the IR receiver state (which will go LOW when the beam is obstructed and stay HIGH otherwise since you set the pin in INPUT_PULLUP mode), with something like
int sensorState = digitalRead(sensorPin);
You don't really care about what the state was previously with the way your sketch is written I guess, so you probably don't need a lastSensorState if you just want to detect the beam obstruction : you can put a quick internal loop inside the bool checkIRBeam() function that exits with true only when the pin goes LOW.
I'm thinking of something like :
bool checkIRBeam() { int sensorState = digitalRead(sensorPin); while (sensorState == HIGH) { sensorState = digitalRead(sensorPin); } return true; }
The issue with this approach is that until a ball passes in front of the beam, your sketch will endlessly run this very fast "inside loop", so it will not take any other event into account (like a button press)
Alternately, instead of looping, you could just exit with a result = false if the beam is not obstructed, but make sure that you don't have calls to delay() when in that "waiting IR" state, because otherwise you'll miss the ball passage
This approach would give something like :
bool checkIRBeam() { return(digitalRead(sensorPin) == LOW); }
Eric
so I should have to create a int for IR sensor right? right now IR is just coded as a Bool
https://www.arduino.cc/reference/en/language/variables/variable-scope--qualifiers/const/
https://www.arduino.cc/reference/en/language/variables/data-types/int/
https://www.arduino.cc/reference/en/language/variables/data-types/bool/
By the way I did give an internet link explaining pull up or pull down as well as the internal pull up option.Again I will repeat that your infrared circuit, your button circuit and each servo circuit are separate and can solved separately. Divide and conquer approach. Big circuits and big programs need to be made out of easy to understand and debug modules.
I am so sorry! I am getting lost... please for give me!!!!! I so wish I could get on a plane and fly to you... lol
@casey
ok I will look at these too!
I might have misspoke when I said the word Bool... let me refigure my thoughts... sorry
As Casey says :
Divide and conquer approach
Try to run some test sketches starting from simple examples, each focuses on a specific point : pushbutton management on one hand (simply lighting a LED or printing to Serial to see the results), then another for the IR sensor starting from the samples provided in the PDF.
You'll get the hang of it quickly and then can adapt to your overall setup with much more confidence
Eric
By the way I did give an internet link explaining pull up or pull down as well as the internal pull up option
Sorry I had missed that post, your link has the whole explanation.
Eric
By the way I did give an internet link explaining pull up or pull down as well as the internal pull up option
Sorry I had missed that post, your link has the whole explanation.
Yes sorry @casey too... so much good feed back it is kinda easy to get lost...
I am gonna have to go out and feed the steers... btw I live on a farm too... father in law is the farmer... I am mostly the handy man and feeder when not at work... lol
I'll be back I a little bit... I guess at this point anyway I should let you guys go and I can try to mess with this for a little...
Thank you every one again!!!!!!!
I notice you have activated the internal pull up resistor and also have one in the circuit?
If you are going to have an external resistor you should use,
pinMode(buttonPin , INPUT);
not
pinMode(buttonPin , INPUT_PULLUP);
You should also be able to remove the servo chatter. I would look for a solution.
https://learn.adafruit.com/adafruit-arduino-lesson-14-servo-motors/if-the-servo-misbehaves
I'm still not understanding why the wiring diagram has two 5V lines at the proto board from the UNO.
SteveG