Hardware components | ||||||
  | × | 1 | ||||
![]()  | 
  | × | 1 | |||
![]()  | 
  | × | 1 | |||
  | × | 1 | ||||
![]()  | 
  | × | 1 | |||
![]()  | 
  | × | 1 | |||
  | × | 1 | ||||
Software apps and online services | ||||||
![]()  | 
  | |||||
I decided to make this because I was bored of pushing the button on the marble machine.
#include <Servo.h> //Includes the servomotor files that allow it to work (might need to download them)
Servo myservo; //Sets the myservo variable to later attach to pin D9
int pos = 0;   //Variable to keep the servos position
int marble = 0;  //Varialble that saya if the tracker sensor gives output
void setup() {
  myservo.attach(9); //Ataches the servo to pin D9
  Serial.begin(9600);
}
void loop(){
  marble =digitalRead(2); //Pin D2 reads the state of the tracker sensor
 delay(1);//delay
if (marble == 1) {              //If the sensor gives output (1)
  for (pos = 45; pos <= 90; pos += 5) {  //Move the servo by the amount needed to push the button 
    myservo.write(pos);  //tells the servo to move
    delay(75);                      //delay 
  }
  for (pos = 90; pos >= 45; pos -= 5) {  //Move the servo back
    myservo.write(pos);            //tells the servo to move
      delay(75);                 //delay 
  } 
 
}
}



_ztBMuBhMHo.jpg?auto=compress%2Cformat&w=48&h=48&fit=fill&bg=ffffff)








Comments