Problem reading signal from 12v through beam from arduino UNO

I want to make an 12v linear actuator to move from relay by receiving signal from my 12v through beam. i have make the connection and insert my coding however it does not work. Really hope someone view this

troubleshoot_through_beam.ino (431 Bytes)

The if-statement requires two '=' to compare something. The digitalRead() function returns HIGH or LOW.

I know something like your sketch is done in this example : https://www.arduino.cc/en/Reference/DigitalRead But that example is confusing. This example is better : https://www.arduino.cc/en/Tutorial/Pushbutton

I suggest not to use 'val', and compare it with HIGH or LOW.

  if (digitalRead(buttonpin) == HIGH)

Please use your brackets and indents and spaces always in the same way. If you start doing that now, you will have many advantages from it.

oh tq sir. the sensor looking in good condition but the arduino like received nothing to charge my relay for my actuator. the sensor sense when it is block and if its not.

should i use arduino voltage divider considering maybe the output from through beam is the same amount of the 12v sensor i use ? its for decreasing the voltage to around 5v same to arduino ?

I don't know what sensor that is, but if it has a 12V output, then you have to use two resistors to lower the voltage. https://learn.sparkfun.com/tutorials/voltage-dividers Choose 15k for R1 and 10k for R2. When the input is 12V the output will be 4.8V.

okayy tq very much sir . I will try your solution ;)