I have received the parts ordered for the first stage of my project, the Arduino board, LCD unit, Ultrasonic range finder and the Shiftbrite LED. I have been running tests with the Arduino and these parts to learn how to implement them into my project.
The Arduino Uno
I ran some simple tests on the Arduino to begin with, just to gain some experience building on the board and understanding the software. Arduino software code is called a sketch. It runs off a setup and a loop function that have to be there and any other functions you add, providing they work! The Arduino software provides a IDE(Integrated development Environment) to develop an run these sketches.
But first I had to install the Arduino onto the PC. This just involved downloading directly from the Arduino website. The only glitch was I had to install the driver software manually. This just involved going into the security file and device manager and update the driver software. Once that was up and running, you simply initialised the Arduino program, chose the board you were using from the drop down menu, the Arduino Uno, and selected the correct serial port.
First test I simulated was a simple blinking light using a LED. I expanded this using other LEDs to simulate traffic lights and a night rider simulation. I then introduced a tactile switch to use as a button to control a LED. I also used a potentiometer to adjust the brightness of a LED. These were all basic test that can be found on the Arduino website. Once I had a grasp of the board I moved on to the Ultrasonic.
The Ultrasonic Sensor
I had a fair understanding of the Ultrasonic sensor and had even tried to start writing the code before I had the part, so it wasn't long before I was able to use this.
Connecting the Arduino to the Sensor involved only 3 pins. Vcc, Gnd and a pin to control the sensor, I used pin 13. Basically, I initially used the pin as an output to make the sensor send out a pulse for 10ms then stop. I then changed the pin to an input to wait for the Sensors reply.
The sensor sends this pulse then waits for it to be reflected off the nearest obstruction and return. When the signals echo is returned, the Sensor sends this information back to the pin on the Arduino. The Arduino times the amount of time it takes for the signal to return. Then using the following calculation, I was able to determine the distance the obstruction was from the sensor.
 |
| Formula calculating time for 1cm |
I did this using the pulseIn function on the Arduino software, the Arduino calculates the amount of time it takes in microseconds. The speed of sound through air is 340.29 meters per second. Based on all this, I was able to calculate the distance in cm by calculating the time it takes to travel 1 cm which is 29.386us. I divide this time by 2 because the distance it to and back from the obstruction. However long it took was divided by 14.693us giving me the distance.
I was able to display these results on the serial monitor of the Arduino's IDE. I then added LEDs into this design to simulate some kind of warning system. As the obstruction moved closer, the green LED was for okay, orange for warning and red for collision inevitable for simulation purposes.
 |
| Arduino including the Sensor |
 |
| Serial Monitor distance display |
 |
| Ultrasonic Sensor |
Next up, was the Shiftbrite and LCD unit.