Arduino Projects‎ > ‎

Motion Activated Cat Toy

The gadget spec URL could not be found



Bill of Materials:
  • Arduino Uno
  • Arduino Motor Shield
  • Arduino Ethernet Shield
  • SM-42BYG011-25 Stepper Motor
  • HC-SR501 Motion Sensor
  • Radio Shack Project Enclosure
Arduino Sketch: (Please note this is still a working project so this code will change often... I will be adding in HTML coding to generate a website to log my cat's playing activity soon)

int rollDelay = 0;
int command = 0;
int rollSteps = 0;
int Step = 0;
int cycle = 0;
byte senseMotion = 0;

void setup() 
{
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(2, INPUT);
}

void loop()
{
  //Motion Sensor 
  senseMotion = digitalRead(2);
  if (senseMotion == HIGH) {
    for(cycle = 0; cycle < 10; cycle += 1)
    {
      //Non Random Rotation
      command = !command;
      rollDelay = 20;
      rollSteps = 10;
      if (command == 0)
      {
        for(Step = 0; Step < rollSteps; Step += 1)
        {
          digitalWrite(9, LOW);
          digitalWrite(8, HIGH);
          digitalWrite(12, HIGH);
          analogWrite(3, 1023);
          delay(rollDelay);
          digitalWrite(9, HIGH);
          digitalWrite(8, LOW);
          digitalWrite(13, LOW);
          analogWrite(11, 1023);
          delay(rollDelay);
          digitalWrite(9, LOW);
          digitalWrite(8, HIGH);
          digitalWrite(12, LOW);
          analogWrite(3, 1023);
          delay(rollDelay);
          digitalWrite(9, HIGH);
          digitalWrite(8, LOW);
          digitalWrite(13, HIGH);
          analogWrite(11, 1023);
          delay(rollDelay);
        }
      }
      if (command == 1)
      {
        for (Step = 0; Step < rollSteps; Step += 1)
        {
          digitalWrite(9, LOW);
          digitalWrite(8, HIGH);
          digitalWrite(12, HIGH);
          analogWrite(3, 255);
          delay(rollDelay);
          digitalWrite(9, HIGH);
          digitalWrite(8, LOW);
          digitalWrite(13, HIGH);
          analogWrite(11, 255);
          delay(rollDelay);
          digitalWrite(9, LOW);
          digitalWrite(8, HIGH);
          digitalWrite(12, LOW);
          analogWrite(3, 255);
          delay(rollDelay);
          digitalWrite(9, HIGH);
          digitalWrite(8, LOW);
          digitalWrite(13, LOW);
          analogWrite(11, 255);
          delay(rollDelay);
        }
      }
    }
  }
  else {
    delay(1000);
  }
}
Comments