Hi,
I'm new to coding in ardunio and need some help, so please excuse the coding.
I'm trying to write a program to drive s servo motor, while checking the status of 2 IR sensors. when i active the sensor the code stops looping, and I cant understand why, can any one help?
code as follows:
[#include <Servo.h>
// setup inputs
int irPin1 = 2; // Setup pin 2 as IR effect sensor 1
int irPin2 = 3; // Setup pin 3 as IR effect sensor 2
int irval1 = 0; // Setup intial IR sesnor 1 value as low.
int irval2 = 0; // Setup intial IR sesnor 2 value as low.
int induct1 = 0;
// Setup outputs
int servoirPin=10;
Servo servoir; // Define servo IR sensor
int irpos = 0; // Define servo start postion
int ledPin1 = 8; // Setup pin 8 as LED
int ledPin2 = 9; // Setup pin 8 as LED
void setup()
{
pinMode(ledPin1, OUTPUT); // set the ledPin as an output
pinMode(ledPin2, OUTPUT); // set the ledPin as an output
pinMode(irPin1, INPUT); // set the IR sensor1 as an input
pinMode(irPin2, INPUT); // set the IR sensor 2 as an input
Serial.begin(9600); // attach PC monitor for testing
servoir.attach(servoirPin); // attach IR servo
}
void loop() {
irval1 = digitalRead(irPin1); // read the current state of IR sensor 1
irval2 = digitalRead(irPin2); // read the current state of IR sensor 2
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
while (irval1 == HIGH && irval2 == HIGH) { //While Sensors Clear servo runs
digitalWrite(ledPin1, HIGH); // trun on LED to show senspors clear
for(irpos = 90; irpos < 180; irpos++) // set servo psotion
{
servoir.write(irpos); //write psotion to servo
delay(15)
}
digitalWrite(ledPin1, LOW); // turn off LED 1
digitalWrite(ledPin2,HIGH); // Show sensors activiated
}
]