We built a robot that we could control using python and code that we had written. The bot was from LEGO and we used the instructions that they had online. We could add different sensors to the bot so that it could detect different things like the ultrasonic sonar sensor uses sound to detect how close something is to it. The touch sensor detects if the sensor was touched and the color sensor detects color if it is close enough.


Our first project consisted of making a scatter bot. This is when we made the bot go forward until either the touch sensor was activated or when the sonar sensor detected something in front of it and turned around. For my code I decided that when the robot went backwards, it would make a right turn and keep driving.

Color Sensor

The second project we had to do was to attach a color sensor to the bot and make it stay within a region by detecting the color. I created a loop so that the bot could keep detecting the color repeatedly after checking the conditions. I created two conditions within the loop that let the bot check if it detected green(3) or blue(2). If it was green then the bot would reverse then switch direction. If it was blue then it would print "Found Blue". If none of these was applicable then the loop would restart again. There is part of my code commented out because the sensors weren't currently attached to the bot so having that part of the code uncommented wouldn't allow for the code to work properly.

Mars Project

This is the code I wrote to get the robot to drive on a surface that represented the Mars surface. The first block checked for water using the color detector and made it look for the color blue and print if it had found it. The second part of the code was to keep the robot from falling into a crater or from falling off of the surface. In order to do this I used the sonar sensor and told it to check if the distance was greater than a certain amount of units then it would stop and switch direction. I only got to test this coed out once because one of the motors on the robot we were using didn't work well. When we tested it one of the other robots, it worked fine. The middle picture is of the design of the robot; It had to be compact in order to not fall into the craters. On the right there is a picture of the floor we used to simulate the Mars surface.

Back to Home Server Project Programming Gaming Project Circuits Artificial Intelligence