Trouble Coding 2 28BYJ-48 5V DC (motor) with a LJ12A3-4-Z/AX (sensor).

I coded everything and everything is working properly, but I’m trying to make a true/false statement were the motors spin clockwise or anti-clockwise depending on what the sensor reads, I’m getting this error when I try to make a(n) if/else statement:

The code is attached below.
I would appreciate any help.

motor_sensor1.ino (3.49 KB)

Please always do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

This is invalid code:

  if (digitalRead(sensor) == HIGH){
    digitalWrite(dir) = true
  digitalWrite(dir) = false

It's not clear to me what you're trying to accomplish. In the rest of your sketch, you are using digitalWrite() correctly, so I'm not sure what happened here. Please spend some time studying the documentation to learn how to use digitalWrite() correctly:

Thank you,
So I fixed that problem but what I'm trying to do it make boolean = 0 according to what the sensor senses (if it senses something =1 if it doesn't =0).

I would really appreciate it if you could help me.

if (digitalRead(sensor) == HIGH){
  someVariable = 1;
  someVariable = 0;

Thank you so much :smiley:
and I apologize for being a pain.

You're welcome. I'm glad if I was able to be of assistance. Enjoy!