Programming Photoelectric sensor issues?

Hello all! I am making a automated can crusher and am using a "atc" photoelectric sensor it is a 10-30v dc sensor so i am using a 12v power supply to power both the sensor and the arduino. My question is does anybody have any advice to make this program work properly? Basically i want the sensor to tell when a can is present and activate my program. I have to program setup already but without the sensor or any switch period. I was just curious on the best way to go about using it to start my program? I have already searched through the forum to see how to go about doing this and couldn't quite find what would suit my application. I figured this was the best forum for help considering the amount of experienced users with arduinos. Thanks for any advice or ideas it is greatly appreciated! :slight_smile:

Post a Link to the doc of your device (is that http://entherm.com/ATC/7703.pdf)?

"ATC" doesn't tell us enough. We need a pointer to the specifications or user manual. Is it one of these?
http://www.alliedelec.com/sensors-switches-relays/sensors/?navigation=4294965385

My crystal ball says that the problem is on line 42 of the code that wasn’t posted.

To post code and/or error messages:

  1. Use CTRL-T in the Arduino IDE to autoformat your code.
  2. Paste the autoformatted code between code tags (the </> button)
    so that we can easily see and deal with your code.
  3. Paste the complete error message between code tags (the </> button)
    so that we can easily see and deal with your messages.

Before posting again, you should read the three locked topics at the top of the Programming Questions forum, and any links to which these posts point.

If your project involves wiring, please provide a schematic and/or a wiring diagram and/or a photograph of the wiring.

Good Luck!

Sorry for the late reply but i really appreciate your help guys. I should have been more clear im not exactly looking to use the photoelectric sensor just yet. I really just want to use a button switch for now while its still in prototype. I just need some help on how to write the program for my needs. I just want to press the button and have it start the program from beginning to end and not start again till it is pressed. Thanks again!!!

Here is my program so far sorry for not being clear on what i needed

Can_Crusher_sequence_no_loop1.ino (1.66 KB)

I just want to press the button and have it start the program from beginning to end and not start again till it is pressed.

So, when the state of the switch changes from released to pressed, do something. When the state of the switch changes from pressed to released, do nothing.

The state change detection example shows how to determine that the state has changed.