Arduino LCD Keypad Shield – Basic Menu System

LCD1After recently purchasing an LCD and Keypad Shield for my Arduino Uno. I thought I best test it out and write a quick sketch to use with it.

The shield has a 16×2 (LCD1602) LCD and 6 Button Keypad , extremely useful for controlling your projects without hooking the Arduino board up to anything. I believe this cost me just under £4 delivered and is well worth the money.

I have made a basic options selection menu which will allow you to scroll through a list of entries and select one of them, using the least amount of screen updates. It doesn’t yet support sub-menus, but it’s dead easy to implement using this code found below.

Click here to read more..

Arduino Open Source Electronics Platform – What is it?

Arduino Uno R3You’ve probably noticed that quite a few posts on here talk about an Arduino, however we haven’t really gone into detail about what one is or where to get one from.

An Arduino is an open source platform that is based on a microcontroller and an easy to use development environment for building electronic projects. The amount of uses for an Arduino is infinite, you use pins on the board to communicate with other hardware such as sensors, motors, lights, switches, and other circuits or systems.

The development environment for the Arduino is also open source; the programming language is based on Wiring – The IDE is downloadable from the Arduino.cc website and is available for Windows, Linux and MAC OSx.

So, how do I get an Arduino?

You have a few choices here. The first one is if you’re familiar and comfortable with building circuits and have experience with electronics you can build your own. The Arduino is an open platform and there are plenty of guides available to build it from scratch.

The other option is to buy it from the Arduino.cc store, or official reseller. You can normally just buy this as an individual product, or get a kit if you need the additional components. The third option is to buy a cheaper, compatible version of the Arduino – again, as this is open-source there is a number (if not hundreds) of manufacturers. Keep in mind the last option that you get what you pay for (e.g. sometimes cheaper/lower quality parts)

You can find a link to the Arduino Store here. Or a list of distributors here.

There are multiple versions and types of Arduino

There are many types of Arduino, the version you start with entirely depends on your experience and preference, or if you have a project in mind already, your requirements. So what versions of Arduino are there?

 

Which one is right for me?

This all depends on what you want to gain from it. If you’re just starting out the Arduino Uno is a great product to begin with. This will allow you to get to grips with using an Arduino, there are also a good variety of shields available.

If you have any experience with programming then that will be a huge advantage when working with the Arduino.

Shields are extra boards that fit directly on top of the Arduino, some examples are of Ethernet Shields, Motor Drivers, Relay, Proto Shields, LCD Shields, Sensor Shields.. there are a lot.

How can I learn?

You can learn and download resources from hundreds of websites (this one included) but the best place for information is the Arduino.cc website and Forums. Check out the Getting Started Guide linked here if you’re a beginner, this will allow you to understand some basic concepts of the Arduino.

There is much more to talk about, I haven’t even covered 1% of what the Arduino is and can be used for – Searching for Arduino projects into Google or Youtube will give you some idea of the vast array of uses for it. Or if you prefer to learn by reading then Amazon have a huge collection of electronics, microcontroller and Arduino specific books available.

I hope that’s covered some of the questions people may have about our Arduino posts! There will certainly be more on here soon.

Arduino – sorting array integers with a bubble sort algorithm

As it happens, I needed to sort an array of integers in ascending order and also find the minimum and maximum number from the array on my Arduino. I decided to knock up a quick bubble sorting function which you can find below.

Bubble sorting is probably one of the easiest and quickest (to write, not actually sort!) algorithms to produce in C. It works by iterating through the array of values comparing pairs and swapping them around if need be, it then performs the same action again until no swapping is needed. You can read more on the Bubble Sorting algorithm by clicking here.

The above Arduino sketch has debug Serial output which should look like the following one uploaded:

bubble

This code isn’t limited to the Arduino, there are no special function requirements needed and should work in any C based application. The only thing that you may want to change is finding the size of the array instead of having it static however I did not need this as I knew how many elements I needed.

Arduino based task scheduler/threading functions

ardIf you’ve used the Arduino before then you’ll know that any code you write in the loop() function is executed on every cycle. But what happens when you have code that needs to run at certain intervals? A delay() will just cause that iteration of loop() to hang and pause.

Arduino released a tutorial BlinkWithoutDelay which introduced the concept of checking the “uptime since last boot” and comparing that to make a basic function scheduler.

The code below basically does the same job, except it’s cleaner and easier to manage. This is by no means original, there have been hundreds of productions of this code, this is just one way to go about it.

The naming structure is shown below, instances of the Timer are prefixed with t_FunctionName to indicate this is a timer.

Instead of checking a single variable for the current milliseconds since boot, this will create a new instance of a structure that can be used to store timings for functions. This way you can easily change when to run a certain portion of code without digging through the sketch or remembering which variables contain the correct values.

The loop() portion of the sketch should be kept clean and only be checking the cycles of the functions from the structure. There should be no need to place any program code inside of the loop() function except for these checks.

This should provide the following benefits:

  1. Enable you to run code every [x] milliseconds or [x] seconds.
  2. Structure the program so that you know when code is running and being able to easily change this.
  3. Have a faster running program. e.g. if you know a portion of code is slower and delaying the loop() you can have this run on a larger interval so it isn’t executed as often.

This code is compatible with all versions of the Arduino and most likely other boards where the language is also based on C.

Fixing erratic LDR values

ldr

After working with a few different sensors hooked up the Arduino, I was experiencing some strange issues where as the value of the LDR would constantly jump up and down within a specific range. I am not sure if this is the quality of the sensor, but it was doing it for all of the LDRs that I have.

I decided that it needed some artificial smoothing in the code to get a useful value. See sample code below for smoothing out LDR values. We need to change the value from an erratic analog value to a digital percentage as an integer.

As you can see, the function takes two parameters samples and sampleInterval The samples is how many times it should query the LDR for the value and the second parameter is how long it should wait before each query.

Depending on the size of the LDR and quality, the min and max smooth value may need to be adjusted (550 and 1023) depending on the range you get back from your LDR.

The function will return an Integer between 0 and 100 depending on the amount of light.

Page 3 of 3123