Sunday, March 31, 2013

Catch a Squirrel with Arduino Electronics

There are lots of squirrel in my town, and I want to catch one of them for fun. So I made a laser trap using Arduino to catch a squirrel.


The electronics circuit is very simple. It goes: 3.3V pin -> Photoresistor -> Pull-down resistor -> Ground, so digital I/O pin measures voltage between the photoresistor and pull-down resistor. I used 5V pin and another digital pin  to run the servo that closes the trap if the reading from photoresistor drops too much (i.e. laser is blocked by the presence of squirrel.). This is the photo of the arduino setup. Notice how I try to entice a squirrel with Korean food. 


I will post the photo of the unfortunate squirrel later. Here goes the Arduino sketch.
-----------------------------------------------------------

Servo myservo;  
int pos = 0; 

void setup()
{
  Serial.begin(9600); 
}

void loop()
{
  float v = analogRead(0)* .004882814;  
  Serial.println(v);
  delay(500);

if (v > .5)
{
 myservo.attach(9); 
  for(pos = 0; pos < 180; pos += 1) 
  {                                  
    myservo.write(pos);          
    delay(1);                      
  }
myservo.detach();
delay(1000000);
}
}

No comments:

Post a Comment