Hello,
We are french and we are in high school and we are a group of 4 for TPE.
We are building a car following a line.
We already realize the engine spinning the rear wheels and the servo motor by directing the front wheels of our car.
We have 3 sensors positioned at the front used to capture the line and thereby rotate the car according to the line drawn on the floor.
We Arduino code for the engine that works.
We tried to assemble the engine code with the servo code and sensors, which gives:
#include <Servo.h>
#define PIRD 2
#define PIRM 3
#define PIRG 4
#define MOTEUR 8
int val = 0;
int pirState = LOW;
int servoPin = 9;
Servo servo;
int pos = 0;
void setup()
{
servo.attach(servoPin);
pinMode(MOTEUR, OUTPUT);
pinMode(PIRD, INPUT);
pinMode(PIRM, INPUT);
pinMode(PIRG, INPUT);
Serial.begin(9600);
}
void loop()
{
Serial.println(digitalRead(PIRM));
val = digitalRead(PIRM);
if(val == LOW)
{
if(pirState == LOW)
{
digitalWrite(MOTEUR, HIGH);
pirState = HIGH;
}
}
{
Serial.println(digitalRead(PIRM));
val = digitalRead(PIRM);
if(val == HIGH);
Serial.println(digitalRead(PIRD));
val = digitalRead(PIRD);
if(val == HIGH)
if(pirState == LOW)
{
digitalWrite(MOTEUR, HIGH);
for (pos = 0; pos <= 45; pos += 1)
servo.write(pos);
delay(15);
pirState = HIGH;
}
}
{
Serial.println(digitalRead(PIRM));
val = digitalRead(PIRM);
if(val == HIGH);
Serial.println(digitalRead(PIRG));
val = digitalRead(PIRG);
if(val == HIGH)
if(pirState == LOW)
{
digitalWrite(MOTEUR, HIGH);
for (pos = 45; pos >= 0; pos -= 1)
{
servo.write(pos);
delay(15);
}
pirState = HIGH;
}
}
}
When performing all the connections, nothing works, could you help us?
We must make it next week so we need to help faster.
Thank you in advance