Search This Blog

Monday, December 21, 2015

Hooking up SainSmart Motor Shield, Ultrasonic Range Finder with Arduino to Control my Chassis.

Its been long since the last post on the series, a lot has changed since then.

Motors to Motor Shield


I had problems with the right motor shield to use, however i finally settled with the sain smart motor shield, which has its library called AFMotor with a guide at the link on how to set it up.
Once you install in your arduino IDE, all is left is to connect it to your arduino like this:

and then first import the library with some few definitions.

#include 
#define MAX_SPEED 120
#define MIN_SPEED 95

You speed can vary, so make sure you experiment with various speed.
In my case i have 4 motors i want to control, so i hooked up the front motors to M1 and M2 respectively and the back to M3 and M4, then declare the motor instances like this:

 AF_DCMotor motorlf(1);
 AF_DCMotor motorrf(2);
 AF_DCMotor motorlb(3);
 AF_DCMotor motorrb(4);


after this, you will need to put this code in your setup. Setting the speed

   motorlf.setSpeed(MIN_SPEED);
   motorrf.setSpeed(MIN_SPEED);
   motorlb.setSpeed(SLOW_SPEED);
   motorrb.setSpeed(SLOW_SPEED);


then for each motor you can use for example
 motorlf.run(FORWARD);
 motorrf.run(BACKWARD);

The rest is basic programming. Also take not that if you want to turn right, you can set the left wheel to run forward and the right wheel to run backward, the converse for turning left.

Ultrasonic Range Finder


For the sensor, hook up the VCC to arduino board 5v, Gnd to Gnd, Trig to pin 12, echo to pin 13 like in the image above, you can see the 2 wires running into the board at both ends.
Then also define this in your code
 #define trig  12 
 #define echo 13 

and in setup add
   pinMode (trig,OUTPUT);
   pinMode (echo,INPUT);
  // initialize serial communication:
   Serial.begin(9600);  

then in your loop
   digitalWrite(trig, LOW);
   delayMicroseconds(2);
   digitalWrite(trig, HIGH);
   delayMicroseconds(10);
   digitalWrite(trig, LOW);
   duration = pulseIn(echo, HIGH);
   cm = (duration / 2) / 29.1;
    if(cm > 25){

     move_forward();

   }else{
    
     turn_right();
     delay(300);
    
   }

So what this basically does is it sets a low pulse for about 2 microseconds to ensure a clean high pulse for a longer period, set back to low and reads the echo using pulseIn. Thats the duration. You can see the calculation to CM in the code above.
Finally our robot looks like this

Upload your code and start your bot. Anytime it encounters an obstacle less than 25 cm, it turns right, from this you can make even more sophisticated computations.
Check out my Youtube video for detailed explanation. Earn free bitcoin

Monday, August 3, 2015

Multi Chassis 4WD Assembly

So its been quite sometime now, since i last blogged. Well recently i took upon myself an interesting hardware hack project which will last for sometime i think, but i promise to blog every step of it. Today was the first step towards this and i managed to assemble the multi chassis kit together. First of, the kit comes together with a short manual of the assembly, however i find it not really comprehensible, but it does get the job done.
This are all the parts, yea, you heard me right really all the parts, so basically the DC Motors go in first, you screw them with an M'2.5*20 (the shorter round head) screw at the top, and the longer M'2.5*25 screw at the bottom holding them with M2.5 nylon screw. So it basically looks like this with all the motors in.
Next we attach the battery case to the chassis top frame and screw it with the M'3*8 flat-head screw. Then you will need to attach four distance holders at the area specified with M3.8 screw so we can attach the chassis top frame to the bottom. Now in total you will need 8 M3.8 screws, 4 to hold the four distance holders to the bottom chassis frame, and four to attach the top chassis frame to the holders. After which to make sure your wires are exposed so as to easily attach them to whatever micro-controller you are going to be using. In my case i will be using the Arduino UNO R3 which i will introduce in the next phase of the project. You can see how the finished product looks like.
If you are interested in a visual look, I posted a Video to YouTube highlighting some important things one might need, but overall the assembly shouldn't take more than 10 minutes. Until next time. Tschüß

Saturday, January 24, 2015

Money hinders potentials

This is not the traditional write up for this blog, however something in my mind that have to be said.
I have been and still wondering why money should be a factor against potentials, there are lots of geniuses out there, raw ideas from bright minds and skills yet to be furnaced. But most of the time, all those cannot be mined without money, why?
Why can't an organization see a good idea and fund it? Why can't an institution see a determined potential and sponsor it? Why can't a country recognize bright minds and buy them. Why do people have to always struggle in order to contribute? I just can't understand the world's logic.

Potentials denied the right to mature in innovators, skilled tarnished and turned into homeless men, great minds ignored in place of radicals that destroy systems. Why does the world have to operate this way, why is it difficult to find a few .5 percent that really understand what is important?

Why why and why????