Infrared sensor follow line

Hello
I would like to know if this code (made to work with this type of infrared sensor (IR Infrared Obstacle Avoidance Sensor Module | Sensores Ópticos | P...) will be able to work with this type (https://mauser.pt/catalog/product_info.php?products_id=096-8830)


 #define Motor11 7
 #define Motor12 6
 #define Motor21 9
 #define Motor22 8
 #define PWMmotor1 5
 #define PWMmotor2 10

 int valuePWM1=120; // speed motor 1 
 int valuePWM2=150; // speed motor 2
 
void setup() {
  
  pinMode(Motor11,OUTPUT);
  pinMode(Motor12,OUTPUT);
  pinMode(Motor21,OUTPUT);
  pinMode(Motor22,OUTPUT);
  pinMode(PWMmotor1,OUTPUT);
  pinMode(PWMmotor2,OUTPUT);

pinMode(A0, INPUT); // initialize Right sensor as an inut
pinMode(A1, INPUT); // initialize Left sensor as as input

}

void loop() {

  int LEFT_SENSOR = analogRead(A0);
  int RIGHT_SENSOR = analogRead(A1);
  
if(RIGHT_SENSOR<36 && LEFT_SENSOR<36) //FORWARD
{
            digitalWrite(Motor11, HIGH);
            digitalWrite(Motor12, LOW);
            digitalWrite(Motor21, HIGH);
            digitalWrite(Motor22, LOW);
            analogWrite(PWMmotor1, valuePWM1);
            analogWrite(PWMmotor2, valuePWM1);
}

 else if(RIGHT_SENSOR>36 && LEFT_SENSOR<36) //LEFT
 {
            digitalWrite(Motor11, LOW);
            digitalWrite(Motor12, HIGH);
            digitalWrite(Motor21, HIGH);
            digitalWrite(Motor22, LOW);
            analogWrite(PWMmotor1, valuePWM2);
            analogWrite(PWMmotor2, valuePWM2);
}

else if(RIGHT_SENSOR<36 && LEFT_SENSOR>35) //RIGHT
 {
              digitalWrite(Motor11, HIGH);
              digitalWrite(Motor12, LOW);
              digitalWrite(Motor21, LOW);
              digitalWrite(Motor22, HIGH);
              analogWrite(PWMmotor1, valuePWM2);
              analogWrite(PWMmotor2, valuePWM2);
}

else if(RIGHT_SENSOR>35 && LEFT_SENSOR>35) //BACK
{
              digitalWrite(Motor11, LOW);
              digitalWrite(Motor12, LOW);
              digitalWrite(Motor21, LOW);
              digitalWrite(Motor22, LOW);
              delay(10000);
 }
}

Why not buy a little bag of IR leds and a little bag of IR detectors (the price each of 10 or more parts is much less than buying 1, you can sell excess as 1's) and connect them directly with resistor for the led to the Arduino.

Cheap chip sockets will take and hold leads from leds, resistors, chips in place.

If the code had some meaningful comments I might spend the time to figure it out. Also post a schematic of your circuit, this will help a lot.

this is for a scolar work, i only have things that are at the school

Your frizzy wiring diagram does not help much. Your link to non technical information on the sensor also was not much help. I have several sensors that look exactly like what your picture shows and they are NOT analog devices, the trim pot sets the threshold level and the output is digital, not analog. The second no clue as I do not have one and your link provides no technical data.
I am assuming your native language is not english from your links but I do not know what to translate this to I will take a SWAG.

Seu diagrama de fiação frisado não ajuda muito. Seu link para informações não técnicas sobre o sensor também não ajudou muito. Eu tenho vários sensores que se parecem exatamente com o que sua imagem mostra e eles NÃO são dispositivos analógicos, o potenciômetro ajusta o nível de limiar e a saída é digital, não analógica. A segunda nenhuma pista, pois não tenho uma e seu link não fornece dados técnicos. Estou assumindo que seu idioma nativo não é o inglês de seus links, mas não sei para o que traduzir isso.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.