Infrared Sensor to Detect Range and Kinect Actuator

Fritzing

rear_front

This is simple and basic guide to detect object using infrared sensor. Hardware requirements : – an arduino or any arduino compatible board ( here I use sduino because it has enough pins to control 2 motor servos) – an infrared sensor – jumper wires (any color doesn’t matter) – 2 motor servo as kinetic actuator (front leg and rear leg)

all

First, plug jumper wires to infrared sensor, here we use sharp infrared sensor. Actually jumper wires color doesn’t matter, but to make it easy, we’ll plug red for 5v, black for ground and yellow for analog input :

ir1

Here we plug red jumper wires to 5v pin on sduino, black jumper wires to ground pin (ground is minus), plug yellow jumper to A5 (analog input pin 5). Plug 2 Servos Next we’ll be plugin 2 motor servos directly to our board using jumper wires, Plug the first motor servo for front leg :

ir2

for analog input we’ll be using pin number 9, for voltage we use 3,3v pin (actually to control a motor servo we can also use 3,3 v pin beside using 5v pin), next we plug the last jumper wire for ground. After plug the first motor, we plug the second motor (rear leg) :

ir3

for analog input, we plug jumper wire to pin 0, for voltage we plug red jumper wire to 5v pin, and the last jumper wire, plug it to ground pin. Actually colors of jumper wire doesn’t matter as long as the arrangement of cable that comes from motor servo plugged correctly with the pins on arduino. Programming The final step is uploading a program to use ir sensor, here’s our code for arduino ide :

/*
simple kinetic actuator using infrared
made by : Antonius (sw0rdm4n)
twitter :  @sw0rdm4n
http://www.ringlayer.net - https://sw0rdm4n.wordpress.com - http://sw0rdm4n.blogspot.com - http://www.indonesianbacktrack.or.id
*/
#include <Servo.h>
int sensorval;
int pos_front_leg = 0;
int pos_rear_leg = 0;
Servo front_leg, rear_leg;
void setup()
{
              front_leg.attach(9);
              rear_leg.attach(0);
}
void loop()
{
               sensorval = analogRead(5);
               if ((sensorval > 200) && (sensorval <300)) {
                           if (pos_rear_leg == 0) {
                                 rear_leg.write(180);
                                 pos_rear_leg = 180;
                           }
                           else {
                                 rear_leg.write(0);
                                  pos_rear_leg = 0;
                           }
              }
              else if (sensorval > 300) {
                          if (pos_front_leg == 0) {
                                front_leg.write(180);
                                pos_front_leg = 180;
                          }
                          else {
                                front_leg.write(0);
                                pos_front_leg = 0;
                          }
              }
              delay(500);
}

Upload that code to arduino board. To test we’ll be using 6 x 1,5 v battery :

ir4

On successfull, if we put any object near the infrared at sensor val range 201-299 the rear leg servo will be moving, if we put any object at sensor val range above 300 the front leg servo will be moving.

Advertisements

.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s