This week the aim was to use the Arduino, by connecting it to an ultrasonic rangefinder, to measure distance. I downloaded the project code from student central and opened it up. Once this was loaded onto the Arduino, It was possible to see the distance of a surface from the range finder in mm using the serial bus (the window shown in the video below). I put my hand in front of the range finder and varied the distance to see the variation in the numbers on screen. I found if my hand was not in front of it, the reading was -1 because nothing was within range to see.
I decided to test whether or not the Rangefinder was accurately measuring diustance. In order o do this, I set it up next to a 30cm ruler and then moved a piece of card to various places on the ruler, then checked the reading on the serial bus. From this test, it appeared that the range finder was accurate to within around +-5mm of the actual distance. I also found that its maximum range was around 360mm and when moving the card back to this kind of distance, the readings tended to vary a lot more.
Once we were happy with this, we were then tasked to copy this code and input into the LCD code from last week so that we could get the LCD to display the result from the rangefinder. I was able to get these two bits of code to work together by copy and pasting the ultrasonic code in chunks into the LCD code. Basically each set of lines of code had to match up with the LCD’s corresponding set of lines. E.g. where the LCD code defines the pins it will use, I also had to define the ultrasonic range finder’s pins at the same time.