Self-rolling Ball
a ball only rolls when someone or somethings hits it, well today I want to change that and create a self rolling ball.
why make this, you ask, well because I can.
in this instrucable I will show you how I make a simple ball a self rolling one.
later you can also tweak the code a bit to change it too your liking and add some other thing to make it a lot more personal.
the idea is to have the Arduino inside the ball, rolling around, making it look like the ball is alive and there is something inside it, trying to get out.
Supplies
Arduino Uno
L298N motor driver module
servo motor x2
wheels x2
Styrofoam ball (diameter of 25 cm)
double sided tape
power bank (small wide is preferable)
USB cable
screwdriver
scissors
isolation tube
Arduino size wood block
Adding Servo Motors to the L298N Motor Driver Module
first you will need to attach the servo motors to the motor driver.
connect the wires to the outer blue ports, where you can then screw them in place.
it does not matter which side in connected to which port, you can easily tweek this via the code that will be written later on in this guide
make sure the wire are thigh and can not easily fall out of the socket.
you can also choose to add the wheels to the servo motor, but this can be done throughout the whole prosses.
Connecting L298N Motor Driver Module to the Arduino
the next step is to connect the motor driver to the Arduino.
connect 6 male to female wires from pin 8 to 13 and connect them in the same order to the pins on the motor driver.
the outer left and right pin is to control how hard the wheels spin and the 4 middle pins are to control which direction the wheel will turn.
this guide we will not be using different speeds, only 100 and 0.
Adding Power to the Arduino and the Servos
in this step you will be needing the power bank and the USB cable, which you will need to cut in half with the scissors.
the USB cable had 4 wires coming out of it. Carefully cut the wires so that only the red and black wires are left. these are the power wires, the other wires are used for data transmission.
now with the red wire sticking out of the USB, it will be connecting to the left blue port of the three, the black one has to put screwed into the middle port.
finally from your Arduino you will need to connect one pin the the 5V and one to the ground. the ground pin must to put together with the black wire from the USB cable and the remaining 5V pin must be placed in the last port on the right.
it should look something like this:
left port: USB red cable
middle port: USB black cable and Arduino ground wire
right port: Arduino 5V wire
now when the USB is plugged into the power bank the light from the Arduino and the motor driver will both turn on.
The CODE
now that everything is connected we will step into the digital world of CODE.
first we must give the motor controllers that come from the motor driver an int that is the pin they use.
in the setup de pin modes must be determined.
under that is a small delay of 10 seconds that gives the user plenty of time to put the Arduino into the ball, this is optional but highly recommended.
in the loop is the random number generator that decides which direction the ball will move to, this direction comes from a random int and is then converted into the direction via 5 different if statements:
forward: both servos go forward
backwards: both servos go backwards
right: the right servo goes forward while the left goes backwards
left: the left servo goes forward while the right goes backwards
stop: both servo are set to 0 speed
under the loop are the voids that tell the servos to go forward or backwards and the speed, which is only 100 or 0 (which is completely off);
//motor A int ENA = 13; int in1 = 12; int in2 = 11; //motor B int in3 = 10; int in4 = 9; int ENB = 8; int dirNum; int waitTime; void setup(){ Serial.begin(9600); //set motor pins to outputs pinMode(ENA, OUTPUT); pinMode(in1, OUTPUT); pinMode(in2, OUTPUT); pinMode(in3, OUTPUT); pinMode(in4, OUTPUT); pinMode(ENB, OUTPUT); //delay to put arduino into ball delay(10000); } void loop(){ //take random number to make arduino move dirNum = random(1, 5); waitTime = random(2000, 5000); //print number Serial.println(dirNum); Serial.println(waitTime); //if staments for the directions if(dirNum == 1){ forward(); delay(waitTime); } if(dirNum == 2){ backward(); delay(waitTime); } if(dirNum == 3){ right(); delay(waitTime); } if(dirNum == 4){ left(); delay(waitTime); } if(dirNum == 5){ stopA(); stopB(); delay(waitTime); } } //turn motor on or off dependant of the direction void backward(){//both forwards digitalWrite(ENA, 100); digitalWrite(in1, HIGH); digitalWrite(in2, LOW); digitalWrite(ENB, 100); digitalWrite(in3, HIGH); digitalWrite(in4, LOW); } void forward(){//both backwards digitalWrite(ENA, 100); digitalWrite(in1, LOW); digitalWrite(in2, HIGH); digitalWrite(ENB, 100); digitalWrite(in3, LOW); digitalWrite(in4, HIGH); } void left(){ //Motor A Forwards, B Backwards digitalWrite(ENA, 100); digitalWrite(in1, HIGH); digitalWrite(in2, LOW); digitalWrite(ENB, 100); digitalWrite(in3, LOW); digitalWrite(in4, HIGH); } void right(){ //Motor B Forwards, A Backwards digitalWrite(ENA, 100); digitalWrite(in1, LOW); digitalWrite(in2, HIGH); digitalWrite(ENB, 100); digitalWrite(in3, HIGH); digitalWrite(in4, LOW); } void stopA(){ //Turn motor A off digitalWrite(ENA, 0); digitalWrite(in1, LOW); digitalWrite(in2, LOW); } void stopB(){ //Turn motor B off digitalWrite(ENB, 0); digitalWrite(in3, LOW); digitalWrite(in4, LOW); }<br>
once you have pushed this onto the Arduino you can test this first without putting it into the styrofoam ball.
Final Arduino Attachments / Adjustments
after putting all of the code onto the Arduino and plugging all the wires into the correct place you will need to put all of the components together to make it fit into the styrofoam ball.
place the Arduino on top of the wooden block and screw it into place, next place the motor driver on top of the Arduino, make sure it can not move from its spot on top.
next glue the servo motors with the wheels directly under the Arduino.
at last you can place your long power bank in between the servo motors to make a the third contact point of the machine when placed in the ball. to make it roll better it is highly recommended to wrap an isolation tube around the power bank, this helps it glide better on the styrofoam surface.
(optional)
to give the device extra grip in the ball you can add small metal pins inside the wheel. you will destroy the wheel slightly in the process, so if you are planning on reusing the wheel this step is not recommended.
Styrofoam Ball
the last and final step is to put the Arduino into the ball.
I personally decorated the ball in the style of a poke ball and gave it the illusion that there is a living Pokémon inside the ball, moving around. the way to decorate your ball is only limited to your own imagination and you can choose what to paint on your own styrofoam ball.