Adding a Proximity GP2D15 Sensor
A great advantage when using the SAMrI in sumo combat is to have proximity detection: The ability to "see" the other robot and act accordingly!
The GP2D15 infrared proximity sensor is a inexpensive and useful device that will allow your SAMrINO to sense objects about 25cm away.
It's very easy to connect and deploy in your program by simply using a digitalRead on the INPUT port you select.
The Vout signal of this sensor is "open collector" and so must have a pull up resistor of 10K tied to the 5V supply to make it read-able.
You can use any unused digital input to read this sensor, but in this example we are using PD0, so you can create an integer variable ( I called mine ir_sensor ), and use a digitRead() instruction to read it in.
Here is a simple code fragment:
pinMode(PD0,INPUT);
void loop()
{
ir_sensor = digitalRead(PD0);
if (ir_sensor == 0){
rightspin();
}
if (ir_sensor == 1){
forward();
}
}