7. Complete program of our project - P-Division-2019-2020-Even/Repo-16 GitHub Wiki
int IRSensor = 4;
int LED1 = 13;
int LED2 = 8;
void setup() {
pinMode(IRSensor,INPUT);
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
Serial.begin(9600);
}
void loop()
{
int statussensor = digitalRead(IRSensor);
Serial.println(statussensor);
if(statussensor == 1)
{
digitalWrite(LED1,HIGH);
}
else
{
digitalWrite(LED2,HIGH);
}
}
#include <Servo.h>
Servo servo;//create servo object to control a servo
int angle = 10;
void setup() { servo.attach(7);
servo.write(angle);
}
void loop()
for(angle = 10; angle < 180; angle++)
{
servo.write(angle);
delay(15);
}
// now scan back from 180 to 0 degrees
for(angle = 180; angle > 10; angle--)
{
servo.write(angle);
delay(15);
}
#include <Servo.h> //servo motor
Servo servo;
int angle = 10;
int IRSensor = 4; //ir sensor initialisation
int LED1 = 13;
int LED2 = 8;
//Motor1
const int MotorPin1 = 5;
const int MotorPin2 = 6;
//Motor2
const int MotorPin3 = 9;
const int MotorPin4 = 10;
//Motor3
const int MotorPin5 = 2;
const int MotorPin6 = 3;
//Motor4
const int MotorPin7 = 11;
const int MotorPin8 = 12;
void setup()
{
servo.attach(7); //servo motor pin attached to 7
servo.write(angle);
pinMode (IRSensor, INPUT); //statements of ir sensor
pinMode (LED1, OUTPUT);
pinMode(LED2,OUTPUT);
//motor pins
pinMode(MotorPin1, OUTPUT);
pinMode(MotorPin2, OUTPUT);
pinMode(MotorPin3, OUTPUT);
pinMode(MotorPin4, OUTPUT);
pinMode(MotorPin5, OUTPUT);
pinMode(MotorPin6, OUTPUT);
pinMode(MotorPin7, OUTPUT);
pinMode(MotorPin8, OUTPUT);
}
void loop()
//declaration of angle of servo motor
{
for(angle = 10; angle < 180; angle++) //scan from 0 to 180 degrees
{
servo.write(angle);
delay(15);
}
// now scan back from 180 to 0 degrees
for(angle = 180; angle > 10; angle--)
{
servo.write(angle);
delay(15);
}
int statusSensor = digitalRead (IRSensor);
if (statusSensor == 1)
{
digitalWrite(LED1, HIGH);
}
else
{
digitalWrite(LED2, HIGH);
}
//Turn on motor1 and motor2 in clockwise
digitalWrite(MotorPin1, HIGH);
digitalWrite(MotorPin2, LOW);
digitalWrite(MotorPin3, LOW);
digitalWrite(MotorPin4, HIGH);
digitalWrite(MotorPin5, HIGH);
digitalWrite(MotorPin6, LOW);
digitalWrite(MotorPin7, LOW);
digitalWrite(MotorPin8, HIGH);
delay(20000);
//Turn off motor1 and motor2
digitalWrite(MotorPin1, LOW);
digitalWrite(MotorPin2, LOW);
digitalWrite(MotorPin3, LOW);
digitalWrite(MotorPin4, LOW);
digitalWrite(MotorPin5, LOW);
digitalWrite(MotorPin6, LOW);
digitalWrite(MotorPin7, LOW);
digitalWrite(MotorPin8, LOW);
}