How do you feel about this article? Help us to provide better content for you.
Thank you! Your feedback has been received.
There was a problem submitting your feedback, please try again later.
What do you think of this article?
Designing a custom plate for the Arduino Robot, adding jumbo LEDs and displaying readings from an ultrasonic distance sensor to the LCD.
My previous post on the Arduino Robot described how I took the Runaway Robot sketch and modified it work with the PING ultrasonic distance sensor. This post is still based around the same example sketch, however the code was not only further modified but additional components were connected to the control board, and a custom acrylic top plate was designed and laser cut to mount these.
After having got the PING sensor to work with Runaway Robot I wanted to add some new features:
LEDs to indicate when the robot was free to move or if it was blocked.
Using the LCD on the control board to display distance values obtained from the PING.
Custom top plate to mount the LEDs and PING sensor, so that it is aesthetically pleasing and robust.
Where to start?
I decided rather than attempt to add all the features at once it would be wise to add each one a step at a time. This meant that if there happened to be and issue it would be much easier to determine where the problem was rather than having to start all over again.
The housing for the robot had to be left until last, when all the components were added. So it was a case of deciding to tackle the LEDs first or the LCD. Since the LCD just involved modifying code I though it might be fun to start by adding the LEDs.
I wanted the LEDs to stand out and so I ordered some 10mm LEDs instead of the more common 5mm. As I hadn't used these ones before I wanted to test them before adding them to the robot. To test the LEDs I used a breadboard to connect them to an Arduino Uno and checked the LED manufacturer data sheet to calculate the correct size resistors(I used 150Ω).
As the LEDs worked fine with the Uno I was confident about adding them to the Arduino Robot. First I had to find the remaining unused digital pins. When I found which digital headers were available I decided which three of these to use, and soldered on a three pin header to each. This was so the LEDs could be removed if the pins were needed in another project, instead of soldering the LEDs straight into the control board.
Wires were soldered to the LEDs, with a resistor in series and terminals crimped to the other end. I had to ensure that the wires from the LED were connected to the robot the right way round. The anode had to go to SIG and the cathode to GND. To check this I compared the positioning against the way the PING was connected, then confirmed this with a multimeter.
When it was finished I had created something akin to a custom TinkerKit LED.
Now the physical part of adding the LEDs was complete it was time to look at the code. I found a simple LED blink sketch and realised I could easily use this in my sketch. This really involved three main steps.
Declare the variables for the sketch. e.g. int led1 = TKDO
In setup() initialise each digital pin as an output and set them to LOW.
In loop() call digitalWrite() using HIGH to turn the LEDs on and LOW for off, calling delay() in between.
All that was left to do was to compile and upload the sketch and test it.
* Note: It is always a good idea to 'save as' and rename your sketch after the addition of new code. This means you get an error at compilation you know the problem is in the new code rather than the old.
Using the LCD display
I knew that using the LCD to display distances was going to be trickier than adding the LEDs. To start with I used debug.print() to test the LCD and this worked for displaying the values. However, it only printed these really small and in the corner. Because this is a debug function it was clear it probably wasn't the best one to use.
I created my own function named displayNumber() that called getCm() and printed the results the screen. These functions were called at the beginning of the main loop and at the end of while loop (the sketch stays in the latter while the distance is less than 20cm). By doing this it ensured that values were being retrieved and displayed both when the robot was moving and when the robot was blocked and turning.
I also wanted to change the position and size of the cursor on the screen, and I did this by experimenting with Robot.setCursor() and Robot.setTextSize(), until I felt the positioning and size of the text looked right. Then I played around with the colours to see what looked best by using Robot.stroke() and Robot.background(). I found that black stroke with a white background was easiest to read.
When I had done this I found everything worked the way I wanted. However, I hadn't taken into account the orientation of the screen, which was displaying portrait and the correct way round when someone was stood in front of the robot. This wouldn't be ideal when walking behind it. To rotate the text 180 degrees I called another function named Robot.setRotation().
Testing the LCD and LED's together
Once I had made all the changes to the parts of the sketch which controlled the LCD and the LEDs I had to compile it and test these two new features together. At this point there were not any proper fixings to secure the PING and LEDs and everything was held on by blue tac during testing.
Designing the mechanical parts
The custom mechanical parts would need to:
Have some mechanism for holding the PING in place without any objects protruding in front of the sensor which could affect readings obtained.
Accommodate mounting the LEDs and remain visible.
Maintain access to the controls on the motor board such as the potentiometer and reset button etc.
Not obstruct visibility of the LCD.
I decided a neat solution would be to add another tier onto the Arduino Robot. This would have a front attachment with housing for the PING, push fit holes for mounting the LEDs, access for reaching controls and it would be made from clear acrylic so you can see the LCD. By designing the housing like this it would not only serve the function of mounting the components but would also provide a layer of protection to the control board.
I looked at data sheets both for the Arduino Robot and the PING, I took some careful measurements and drew a sketch that included all the dimensions and positions.
Having not used a laser cutter or design software since high school I needed some help with drawing the design in Illustrator. A colleague, Stuart, kindly offered to show me how to use the laser cutter and showed me how to do the design.
For making the LED holes we decided it would be wise to create a test piece in acrylic with small variations from the size specified in the manufacturer data sheet. We did this to allow for the thickness of the laser beam which would be cutting the holes. The size on the data sheet specified a 10mm LED, so we tested sizes increasing by 0.1mm ranging from 9.6mm-10.4mm. We found 9.9mm provided the most secure fit.
Once the drawing was complete we cut a prototype in 3mm MDF.
After fitting the prototype to the robot a few small adjustments to positions needed to be made, as well as adding “Johnny 6” to be etched. Once complete it could send it to the laser cutter to be made in acrylic.
Putting the housing together
I wanted the new tier to be around 30mm above the control board, so used some 30mm M-F M3 hex spacers and screwed down the top tier to assemble everything together.
Once I was happy with the way everything had fitted together it was time to test the robot.
After compiling and uploading the code I put the robot down and let it do its work. The LEDs and PING worked, distance values were being displayed to the LCD and Johnny 6 had a shiny new acrylic top plate!