Sunday, 2 February 2014

FREE HAND CONTROL OF COMPUTER GAME WITH A PROXIMITY SENSOR


                                                Yesterday, we have seen yesterday how to make a cheap and simple proximity sensor. Today this post is about reading the output given by the sensor, by removing the ambient light intensity from the total amount of light falling on the sensor and making the measurements more reliable with the surrounding lighting conditions.



                                               This arduino code works well in different ambient light conditions. This code has control over the IR led too instead of keeping the led on forever. First the led is kept switched off and the intensity of light is measured, this being the ambient light intensity. Next the led is switched on and analog voltage is sampled from arduino's ADC pin now this being the amount of reflected light + ambient light. The difference between these values gives the amount of light reflected. This thing is repeated a few times and average amount is calculated as the final value. The code was actually taken from here. So you can take away code from there and modify it.
                                               Now, as the sensor is ready to be used, we will try having fun controlling a game on PC (here Jetpack Joyride). A program continuously reads the sensor's output from Arduino via serial communication and simulates the space key press when there is a value from the sensor greater than a threshold value.

So here's a demo video...



And here's the code....

clear all
clc
%Your Arduino's COM port
s = serial('COM6');
%Importing java classes for simulating key press or release
 import java.awt.Robot; 
 import java.awt.event.*; 
 SimKey=Robot; 
%Threshold value for sensor
th = 100;
fopen(s);
s.BaudRate = 9600;
readasync(s)
while(1)
out = fscanf(s);
x = str2num(out)
%press Space if x > threshold and release if lesser
if (x > th)
 SimKey.keyPress(java.awt.event.KeyEvent.VK_SPACE);
end
if (x<th)
SimKey.keyRelease(java.awt.event.KeyEvent.VK_SPACE);
end                                     
end

So, all you need to do is connect the sensor to Arduino as shown in previous post and upload the code from mentioned link (here) into your arduino and run the above code in matlab, then start the game and have fun. Well, the code is very simple but is'nt it cool... I got the game for my PC from Windows 8 appstore... Hope you will find it for yours..

Saturday, 1 February 2014

PROXIMITY SENSOR USING A PHOTO DIODE AND AN INFRARED LED


                                           A proximity sensor is a device which detects the presence of an object in its proximity. Well the sensor which we are going to make here works well for short distance ranges and is very cheap and easy to build. Photo diode and matching Infrared Led pair will cost you about Rs.12 and all you will need is a resistor and small wires to solder for strength. 

                                   A photo diode operates as a normal diode in forward bias and acts as a light sensor in reverse direction. It produces a current proportional to the intensity or amount of light falling on it.
                                              An Infrared led is similar to a normal led except that the former emits out Infrared light instead of visible light. So it works when operated in forward bias condition.


Infrared Led
So here is a circuit diagram which converts the light into current and then the current to voltage using a resistor.


                               The output voltage can now be checked with a multimeter. The arrangement of two led's should be in such a way as shown in the figure below (both adjacent to each other). So when an object comes above these the light from infrared led gets reflected from the object and falls on the photo diode. Closer the object, more the amount of reflected light and more the output voltage.


                                This simple sensor can be used and applied in many exciting ways which we will see in the upcoming posts. So keep making stuff you like and enjoy !!!
Powered by Blogger.

Blog Archive

 

© 2013 The Repository. All rights resevered. Designed by Templateism

Back To Top