Make a motor turn "random"

Hello,

I am kind of a beginner with the arduino software and i have a litle problem with the random function.
I would like to have a motor turning "random" from left to right or right to left en then back to where it starts.

so if it start turnig right fore 2 sec, it needs to turn left fore 2 sec after it turned right and vice versa.

in the atachement i have put my .ino file where i try to do it with an lr[]

i hope someone knows the solution, it would realy help me out :slight_smile:

Greetz, Joris

jorisprojectStuurmotor.ino (1.29 KB)

You don't say what your problem actually is.

Which commands in the program make the motor move ?

  if (actie == 1 || actie == 50){

Do you intend that this handle all the values between 1 and 50? It does not do that now.

PaulS:

  if (actie == 1 || actie == 50){

Do you intend that this handle all the values between 1 and 50? It does not do that now.

thanks,
the intension is to handle all values between 1 and 50, how do i do that?
that is the actual question indeed.

the intension is to handle all values between 1 and 50, how do i do that?

if (actie >= 1 && actie <= 50)
{
"if actie is greater than or equal 1 and actie is less than or equal 50". And notice that the { is on the next line, where it belongs (IMHO).