IQ Gen 2 Optical Sensing

My students have been trying to complete the following challenges to learn the Optical Sensor: Color Sensing, Secret Code, and Follow the Light.

For the Color Sensing students are doing the code as its shown: drive forward until it senses an object then stop, if the object is blue turn left. Its doing everything but turning left. What could be wrong.

No questions yet on Secret Code but if anyone has a suggestion I will take it.

Follow the Light challenge seems to be working but its not moving very far. Is the light not bright enough? is the room not dark enough. They have the appropriate code.

Any suggestions?

Hi @Christopher_Foster! I’m going to tackle Color Sensing first :slight_smile:

Would you be able to send me a screenshot of your code in VEXcode IQ?

Also, I would suggest checking out the Sensor Dashboard when the Optical Sensor is close to the blue cube. It will show you exactly what the sensor is seeing (maybe it’s not seeing blue because of the light in the room, etc). Here is an article on how to do that.

You can also introduce an [If then else] block and [Print] blocks. This will help you see if the sensor is detecting blue, or something other than blue (a different shade of color).

I would also try setting the light on the Optical Sensor to 100% just to see if this helps with detecting blue.

Let me know if any of this helps! :slight_smile:

@Christopher_Foster, for “Follow the Light” the code that is listed in the Google Doc has the robot only driving forward 20mm at a time, which is not very far (less than an inch).

It’s also not in a [Forever] block, which means that the code is only going to be checked once, and then it stops. Here is an example of that code updated to increase the drive distance and include a [Forever] block.

I would suggest first trying this updated code. If this works, i’ll update the Google Doc with this updated code. If its still not working properly, we can print some values to the Brain’s screen to see what is happening :slight_smile:

Let me know if this helps!

Hey Lauren

Here is a copy of a students code. All classroom lights are turned on. I also had them turn the Optical Light to 100% like your second example shows. The first block it is detecting blue and turning left, I will attach a video as well that shows it after it turned left. However, at the second block it is always detecting not blue and it is turning right, however, the third one it is detecting blue and turning right. Is it a classroom lighting issue?

FYI Flash Light and the Secret Code all seem to be OK now.

Hi @Christopher_Foster! At least the sensor is working for 2 of the 3 cubes, so that’s good news!

I’m wondering if that second cube is giving trouble because it looks like in the video that it hit the corner of the cube, so it might have seen part of the cube itself, and part of the wall behind it.

I adjusted where the cubes are placed, so every time it turns left, it finds the next cube. I will update this in the activity.

I would suggest moving the Optical Sensor to the center of the plate in the front of the BaseBot and lining the robot up center with the cube. I’ve attached a video and image for reference.

I also adjusted the code slightly, let me know if this helps!