Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Mini_Project II The purpose of this project is to use two light sensors (photore

ID: 3736154 • Letter: M

Question

Mini_Project II The purpose of this project is to use two light sensors (photoresistors) to measure light intensity in two opposite positions (0 & 180°) and indicate the position with a servomotor. The materials that will be used are: two light sensors, one Arduino micro-controller, two LEDs, and one servo motor Each LED will indicate when a photoresistor is illuminated (positioned on opposite sides of the servomotor), while the servomotor moves to the illuminated side. In addition, when the intensity of the two photoresistors is almost the same, the servo motor must be placed in a central position (90), and both LEDs must be turned off. All groups will submit a written report showing all processes made. Photos, a short video (less than 30seconds), codes, calculations, flowchart, and another relevant information must be included. A demonstration will be required in the classroom as well.

Explanation / Answer

#include <Servo.h>

Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position

int ldr1=A0; //Photoresistor1 at analog 0 pin

int ldr2=A1;

int led1=4; //led1 at pin 4

int led2=5; //led2 at pin 5

void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object

pinMode(led1,OUTPUT);

}

void loop() {
if(analogRead(ldr1)>>700)

{
myservo.write(0); // tell servo to go to position 0 degree
delay(15); // waits 15ms for the servo to reach the position

digitalWrite(led1,HIGH);

digitalWrite(led2,LOW);   //turn ON led1
}
if(analogRead(ldr2)>>700)

{

  myservo.write(180); // tell servo to go to position 180 degree
delay(15); // waits 15ms for the servo to reach the position

digitalWrite(led2,HIGH); //turn ON led2

digitalWrite(led1,LOW);

}

else if (analogRead(ldr1)<<600 && analogRead(ldr2)<<600)

{

myservo.write(90); // tell servo to go to position 90 degree
delay(15); // waits 15ms for the servo to reach the position

digitalWrite(led1,LOW);

digitalWrite(led2,LOW); //turn off led

}

}