Snakes have multiple forms of locomotion. My project depicts rectilinear: when the snake moves with its body straight without any bends using its belly muscles.
Setup
My project uses a stepper motor and reed switch as its main Arduino components. The stepper motor moves the snake around a circular rock formation and the reed switch senses if a magnet is placed in a specific location. If it senses the magnet, it stops the snake after it finishes its current rotation. To make the project look nicer, I added a mouse on top of the magnet.
The Code
My code functions by checking if the sensor senses a magnet. If it doesn’t, the motor makes a full rotation. After the rotation is made, the code checks if the sensor is sensing a magnet again and this repeats until the sensor senses the magnet. The sensor returns a 1 or a 0 depending on whether it is closed or open. To manipulate the speed of the motor, you set its speed as an int between 0-17. To manipulate the number of rotations, set its step to 2048 for a full rotation, 1024 for a half, and so on.
Difficulties
The main difficulty I had with my project was controlling the stepper motor and making the snake slither nicely around the rocks. My original plan was to have the motor make short incremental rotations so that it can stop anywhere. But when I tried working with the adjustable variables, the number of revolutions and revolution speed, I could not get the desired effect. Changing the revolution count does make the motor rotate less, but the speed would greatly decrease no matter how high the revolution speed is set. In the end, I decided on a fixed stopping location. The second issue was mainly caused by the body of the snake. If the motor spun too fast, the open segments that connect each part of the snake’s body segments would get caught on the rocks and ruin the setup. If my snake body was made with segments with rounded edges, it would probably work with higher rotation speeds.
Leave a Reply