Friday, November 29, 2013

Fun With a New Arduino

I was visiting my Mom and sister and nephew over the Thanksgiving holiday.  My nephew is, like me, interested in electronics and microcontrollers.  We spent a lot of time just goofing around with different projects.  It was a great couple of days.

There is a neat store near his house called Gateway Electronics.  They have pretty much everything you could want for electronic projects for good prices (and free Twizzlers).  I bought an Arduino Uno, a continuous operation servo, and a couple of potentiometers.  My nephew bought the DFRobot Arduino LCD keypad shield for his Arduino.  We spent the rest of the day trying to get the Arduinos working with LCD displays and the servo.

Adafruit has a web page that explains how to connect an Arduino to an LCD.  The LCD in the example was a 16x2 LCD.  I had an LCD display from the Milwaukee Makerspace.  It looks like most LCDs are the same.  They have 14 or 16 pins.  Pin one is ground.  Pin two is power in.  Pin three is to control contrast.  Pins 15 and 16 control the backlight, if the LCD has that feature.  Pins 4 through 14 are to send data to the LCD.  Check out the Adafruit web page for more details.

The Arduino IDE comes with several example programs for displaying on an LCD.  Plus, there is a built-in library called LiquidCrystal that makes it very easy to work with LCDs.  The Adafruit page does a good job explaining the basics for first-time users like me.

Our first try at connecting the Arduino to the LCD was a bit flaky.  The display would go a bit crazy after the first boot-up.  If we wiggled the cables, the display would change.  We replaced all of the cables with different ones and the LCD worked perfectly.

Various web pages say that a potentiometer is needed to control the contrast.  You can see it in the picture above next to the right-hand corner of the LCD.  It basically needs power and ground on the outside pins.  The middle pin connects to the contrast pin on the LCD.

My nephew hooked his DFRobot LCD shield to his Arduino.  Their web page has some sample code.  He downloaded the code to the Arduino and the board worked great -- at first.  After about 30 seconds, the display started getting flaky.  Tapping on the screen would settle it momentarily.  Everything works functionally, but the display is not stable.  Looks like he will have to exchange it for a better one.

Next, I hooked the servo to the Arduino.  I found an Arduino sketch to control the servo with pulse width modulation.  It basically lets you press keys on the computer keyboard to speed up and slow down the servo.  I played around with the minimum and maximum settings and was able to get the servo to go both clockwise and counter clockwise.  I also added the LCD code to the sketch to display the pulse width setting on the screen.  Nice!

The Arduino IDE comes with a library for the servo called the Servo Library.  I did not play with the Library much but I was able to get it to go clockwise, counterclockwise, and stop.  The library did not control the time, nor the speed.  Maybe it will, but I could not get it to work that way.

In the picture to the right, you can see the Arduino in the front, the LCD in the middle, and the servo in the rear.  I would like to use the Servo to control the automated pet food dispenser.  In theory, I could connect the Arduino to the servo and plug the power for the Arduino to a timer that will turn it on once or twice a day for five minutes.  The program I wrote moves the augur counter-clockwise for about 1 second.  Then, it rotates clockwise for 2 seconds.  According to the Instructable about the dispenser, this will keep the augur from jamming on food pieces.  One weird thing is that the program works great when the Arduino is connected to the PC but not when it is connected to a USB power converter.

Here is the code to control the servo.

#include <server.h>

Servo augur; 

void setup() 

void loop()

  // Make the servo turn clockwise then counter 
  // Set up the servo 

  // Spin counter clockwise 

  // Spin clockwise 


No comments:

Post a Comment