Sunday, 16 August 2015

Tracker Camera


I will start with : It was a difficult project . Very challenging.
From learning to work with servos, to using the opencv library , to getting my mind around using a raspberry pi , this was one hell of a learning experience.
The camera basically tracks objects based on their unique colour. The camera feeds what it sees into a raspberry pi , which then uses its computing might , to threshold , morph, and the extract features , all in real time. The extracted coordinate of the centroid of the object are then used to position , the servos. This ,trust me, is no easy task. All of this is implemented using the opencv library for image processing. The GPIO library(wiring pi) for raspberry pi helps me interface with the servos.
I spent a lot of time on this project. It has made me fall in love with the raspberry pi.
Post this project , what has mostly changed is my hair pulling threshold ( meaning the failed attempts after which I start to pull my hair). This has definitely increased, for good.
Here , have a look at what came of the madness :


Friday, 24 July 2015

Line follower

I made this over winter. It took me a week to complete this. Making a line follower is pretty simple.
This one has a special something though. I made my own light sensors , unlike those available in the market. It was based on what I had learned in my first semester electrical course class. Also this one need not be calibrated in different light conditions. It does so itself , with a very simple tweak , that just came to me , somehow. It thus does not run on the same piece of program that is flooded over the internet.
I have shared how to make a line follower :
Here is mine , in action.

Thursday, 23 July 2015

How to run a motor using L293D (double H-bridge) and interfacing it with the Arduino


Motor drivers are needed because the pins of a micro-controller cannot source the required current to run a motor.
The arduino can provide a maximum 200mA per pin and can sink a total of 400mA current.

You will damage the micro - controller or pins if you try to draw more current. A motor cannot run on such small current. Thus an amplifier circuit or a relay is needed. To drive the motor in both directions , an H-bridge is needed.

Lo and behold ! Let me present to you L293D. It is a transistor implementation of both an amplifier and an H-bridge , in other words , the solution to our problem.

This is what an h-bridge looks like:

 

This is the pin layout of L293D:




















It can run two motors.
Vss needs to be connected to 5v for either h-bridge to run.
Enable1, if connected to 5v enables the left h- bridge.
Enable2, is for right H- bridge.
Gnd pins go to ground. 
Vs  is the voltage you want to give the motor.


 WIRE IT UP


Created Using Fritzing



THE PROGRAM


#define M1pin1 9  
#define M1pin2 10
void setup()
{
pinMode(M1pin1, OUTPUT);
pinMode(M1pin2, OUTPUT);
}
void loop()
{
 Clockwise();  // motor turns in clockwise direction
 delay(2000);  // Arduino sleeps for 2 seconds
 AntiClockwise(); // motor turns in anticlockwise direction
 delay(2000);
}

void Clockwise()
{
    digitalWrite(M1pin1, HIGH); // digitalWrite is a predefined function to control pin state.
    digitalWrite(M1pin2, LOW);
}  
void AntiClockwise()
{
 
    digitalWrite(M1pin2, HIGH);
    digitalWrite(M1pin1, LOW);
}



If You Are looking for speed control :
// You need to connect input wires to a pmw enabled pins on Arduino. These are identified by ~ sign on the arduino board. Notice 9 has a ~ before it on the board.


#define M1pin1 9       
#define M1pin2 10
int pmw=128;
void setup()
{
pinMode(M1pin1, OUTPUT);
pinMode(M1pin2, OUTPUT);
}
void loop()
{
 Clockwise();  // motor turns in clockwise direction
 delay(2000);  // Arduino sleeps for 2 seconds
 AntiClockwise(); // motor turns in anticlockwise direction
 delay(2000);
}

void Clockwise()
{
    analogWrite(M1pin1, pmw); // analogWrite is a predefined function to control pin state.
    digitalWrite(M1pin2, LOW);
}  
void AntiClockwise()
{
 
    analogWrite(M1pin2, pmw);
    digitalWrite(M1pin1, LOW);
}

//pmw can take values between 0 and 256. At 256, it will run at max speed. At 128, it will run at half the speed.