top of page

Arduino Quiz 3 - Emre



#include <Servo.h>

int sensorPin = A0;
int servoPin  = 9;

int sensorValue = 0;
int servoGrad = 90;
int tolerance = 40;

Servo myservo;

void setup() {
  pinMode( sensorPin, INPUT);
  myservo.attach( servoPin );
  myservo.write( servoGrad );
}

void loop() {
  sensorValue = analogRead(sensorPin);
  if ( sensorValue < (512-tolerance) )
  {
    if (servoGrad < 180) servoGrad++;
  }

  if ( sensorValue > (512+tolerance) )
  {
    if (servoGrad > 0) servoGrad--;
  }

  myservo.write( servoGrad ); 

  delay(100);
}
9 views1 comment

Recent Posts

See All

Quiz 4 Gyro Sensor Game [Craig and Shiv]

Files for game https://drive.google.com/file/d/1NmwgA79cN9MVYkUTXmYNy5E6dYMV16W8/view?usp=sharing The game is a rolling ball that picks up cubes, controlled by a gyro sensor arduino board.

bottom of page