help with faulty code

hi i decided to make a line following robot with two sensors
so i wrote this code :wink:

#define m1p1 8
#define m1p2 9
#define m2p1 10
#define m2p2 11
#define sensor_right 0
#define sensor_left  1
#define led_right 6
#define led_left  5
int val_left  = 0 ;
int val_right = 0 ;
void setup()
{
  pinMode(m1p1,OUTPUT);
  pinMode(m1p2,OUTPUT);
  pinMode(m2p1,OUTPUT);
  pinMode(m2p2,OUTPUT);
  pinMode(led_right,OUTPUT);
  pinMode(led_left,OUTPUT);
}
void loop()
{
  val_left == analogRead(sensor_left);
  val_right == analogRead(sensor_right);
  if ((val_left)>(val_right))
  {
    digitalWrite(m1p1,HIGH);
    digitalWrite(m1p2,LOW);
    digitalWrite(m2p1,LOW);
    digitalWrite(m2p2,LOW);
    digitalWrite(led_right,HIGH);
    digitalWrite(led_left,LOW);
  }
  else if ((val_right)>(val_left))
  {
    digitalWrite(m1p1,LOW);
    digitalWrite(m1p2,LOW);
    digitalWrite(m2p1,HIGH);
    digitalWrite(m2p2,LOW);
    digitalWrite(led_left,HIGH);
    digitalWrite(led_right,LOW);
  }
  else if ((val_right)==(val_left))
  {
    digitalWrite(m1p1,HIGH);
    digitalWrite(m1p2,LOW);
    digitalWrite(m2p1,HIGH);
    digitalWrite(m2p2,LOW);
    digitalWrite(led_right,HIGH);
    digitalWrite(led_left,HIGH);
  }
}

i just wanted to test it so i didnt connect the motors but checked if the led's went on and off if i put a black tape under one of the sensors i expected one of the led to turn off but nothing happened :frowning:
i checked the sensors on serial monitor if they were giving different values for white and black they give a value of 880 for white and around 600 for black
the sensors are led and ldr

Did you write an even simpler sketch to test the LEDs first?

why ?

This is your problem:

  val_left == analogRead(sensor_left);
  val_right == analogRead(sensor_right);

== means a comparation, change it to:

  val_left = analogRead(sensor_left);
  val_right = analogRead(sensor_right);

Now it should work.

ok i tried it they r working

oh thanks senso ill try

thanks it worked out
shall keep in mind "==" means to compare oh! :wink: :slight_smile:

why ?

To check that your wiring is correct.
Debug as few unknowns at any one time as possible, so build on simple, proven stuff.