Part 17 – Using IR Sensors for flame and line detection for the Vex

I was running out of time and get all the code done for the robot so I just incorporated this into the main robot code. Here is a picture of the Fan, Ultrasonic and IR Sensors installed on the robot.


Some notes about the IR sensors and going in the right direction. The first thing we decided was that we were going to use 2 IR sensors, one mounted 90 degrees to forward direction and one mounted along the center line of the robot facing forward. We decided to use two because we wanted to be able to go forward across the area where the candle would be located while detecting the flame and then do a 90 degree turn to face the fire and use the front sensor to make our way forward to the flame. This didn’t add too much complexity and in the end worked out pretty good. In addition, to detect the flame from far away we used a 100k resistor on the side and then a 10k resistor in the front.

The side 100k resistor sensor gave us a good variability of return values (from 179 with nothing being sensed, to about 975 when we were very close) so that if we were far away and moving quickly by the flame we would still get a value big enough to get us to stop and turn 90 degrees left to face it.

We also noticed while testing that the IR sensors have a pretty broad range of detection, which wasn’t going to be good if we were going to use the IR sensors to pinpoint the fire and then turn on the fan. To reduce the angle of detection we tested putting the IR sensor inside of a straw. We tested different lengths of straw as well as covering the straw with electrical tape.

You see the front sensor in the picture above and here is a picture of the side sensor. Originally we had the sensor mounted below our bumper hidden from view (so that nobody would steal our idea) but once we started testing with the candles we decided that we needed the extra height for it to really be able to see all the flames.

Another thing you might notice if you look close enough is that the IR Sensor is not mounted at exactly 90 degrees from center. We angled the IR sensor a little bit forward so that we gave the robot a chance to slide to a stop and turn while still facing it.

Here is some of the code that was used to test the IR Sensors….

This code simply allowed me to manuallly move the robot around while in debug mode watching the values of the sensors. This allowed me to establish the minimums and maximums that we would see once we started moving the robot.

#pragma config(Sensor, in1,    irsensor1,      sensorReflection)
#pragma config(Sensor, in6,    irsensor2,      sensorReflection)
#pragma config(Sensor, in8,    fanout,         sensorDigitalOut)
//*!!Code automatically generated by ‘ROBOTC’ configuration wizard               !!*//

int runstatus = 0;

void runfan() {
runstatus = 3;
SensorValue[fanout] = true;
wait1Msec(10000);
SensorValue[fanout] = false;
}

task main()
{
int irsenval1 = 0;
int irsenval2 = 0;

while (true) {
irsenval1 = SensorValue[irsensor1];
irsenval2 = SensorValue[irsensor2];
}
}

Once we had the IR sensors working well enough, we used the following code to test blowing out the candle. We needed a lot of code to “watch” the IR sensors to make sure the fire was blown out.

#pragma config(Sensor, in1,    irsensor1,      sensorReflection)
#pragma config(Sensor, in2,    irsensor2,      sensorReflection)
#pragma config(Sensor, in3,    rightEncoder,   sensorRotation)
#pragma config(Sensor, in4,    leftEncoder,    sensorRotation)
#pragma config(Sensor, in7,    sonarSensor,    sensorSONAR, int1)
#pragma config(Sensor, in8,    fanout,         sensorDigitalOut)
//*!!Code automatically generated by ‘ROBOTC’ configuration wizard               !!*//

int runstatus = 0;

void runfan() {
/* function: runfan
creation: 2/14/2017
*/
// Set our runstatus for blowing out the candle.
runstatus = 6;
int fireout = 5;
bool onfire = true;
int firevals[10];
while (onfire) {
int fireavg = 999;
int icnt = 0;
for (icnt=0;icnt<10;icnt++) {
firevals[icnt]=999;
}
// Turn the fan on.
SensorValue[fanout] = true;
// Keep the fan running while we are detecting the flame.
while(fireavg > fireout) {
fireavg = 0;
for (icnt=0;icnt<9;icnt++) {
firevals[icnt+1] = firevals[icnt];
fireavg = fireavg + firevals[icnt+1];
}
firevals[0] = SensorValue[irsensor2];
fireavg = fireavg + firevals[0];
fireavg = fireavg / 10;
wait1Msec(1000);
}
// We blew out the flame, turn off the sensor.
SensorValue[fanout] = false;
wait1Msec(4000);
// Wait 4 seconds then check the value again to make sure the 
// Flame didn’t just dim, but went completely out.
if (SensorValue[irsensor2] < fireout) {
onfire = false;
}
}

}

task main()
{
runfan();
}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.