Posts | Comments

Planet Arduino

Archive for the ‘Arduino Tutorial’ Category

May
16

Getting Started with Arduino! – Chapter Six addendum

74HC595, arduino, Arduino Tutorial, education, learning electronics, microcontrollers Comments Off on Getting Started with Arduino! – Chapter Six addendum 

This is part of a series titled “Getting Started with Arduino!” – A tutorial on the Arduino microcontrollers, to be read with the book “Getting Started with Arduino” (Massimo Banzi).

The first chapter is here.

Welcome back fellow arduidans!

After reviewing Chapter Six of our tutorials, I felt that there was some important information missing about the section regarding driving 4-digit 7-segment LED display modules. Although we have discussed displaying numbers using the module, and hopefully you have done this yourself with exercise 6.2, those numbers were constantly being written to the display as the sensor was being repeatedly read.

But how do we send a number to the display – and hold it there? We need a function that can accept the number to display – and the length of time (in cycles) to hold it there. I have rewritten the function displaynumber() from the solution to exercise 6.2 – now it accepts another value, “cycles”. This is the number of times the number will be shown on the display.

void displaynumber(int rawnumber, int cycles)
// takes an integer and displays it on our 4-digit LED display module and HOLDS it on the display for ‘cycles’ number of cycles
{
for (int q=1; q<=cycles; q++)
{
if (rawnumber>=0 && rawnumber<10)
{
onedigitnumber(rawnumber);
}
else if (rawnumber>=10 && rawnumber<100)
{
twodigitnumber(rawnumber);
}
else if (rawnumber>=100 && rawnumber<1000)
{
threedigitnumber(rawnumber);
}
else if (rawnumber>=1000)
{
fourdigitnumber(rawnumber);
}
}
}
Here is a sketch to demonstrate this function, the hardware is the same as exercise 6.2, except there is no need for the variable resistor: exercise6p2addendum.pdf.

And my day wouldn’t be complete without another video demonstration. This example has cycles set to 500.

So there you have it! Now you have the knowledge to use these multi-digit displays effectively. And now that we have mastered them, we can move onto more interesting and useful display types. To find out, subscribe using the methods at the top right of this web page – and join our Google Group!

So have fun, stay safe and see you soon for our next instalment!


Hello readers

I would like to announce the opening of our own tronixstuff discussion email list via Google Groups: http://groups.google.com/group/tronixstuff

Through this group we can discuss posts, projects, products and anything else mentioned on the tronixstuff or related websites. For the time being it will be moderated until we get going and see what the level of conversation is like. However, please feel free to ask questions, offer suggestions, or make constructive criticism about anything in the tronixstuff world.

It is also meant for support with any of the Arduino tutorials or products mentioned in the blog. I will do my best to help you, so don’t be afraid to ask!

However it is not for spam, discrimination, attacking others, or blatantly selling things.

So sign up now!

http://groups.google.com/group/tronixstuff


This is part of a series titled “Getting Started with Arduino!” – A tutorial on the Arduino microcontrollers, to be read with the book “Getting Started with Arduino” (Massimo Banzi).

The first chapter is here.

Welcome back fellow arduidans!

Hello once again to our regular Arduino tutorial instalment. This week are up to all sorts of things, including: distance sensing, using prototyping shields, even more shiftiness with shift registers and 4-digit 7-segment displays, and some exercises to refresh and expand your knowledge. Wow – let’s get cracking…

Do you know how to keep your distance? Some people do, some do not. The same goes for mechatronical things (i.e. robots, those little autonomous vacuum cleaners, etc). So to solve that problem you can integrate a distance sensor into your design. Hopefully by following this section you will gain an understanding of such sensors, and be able to make use of them later on in your own projects. Anyhow, today we are looking at the Sharp GP2Y0A21YK0F infra-red distance sensor. What a mouthful… The funny thing is that it looks like a robot head:

That white JST connector is for three leads, +5V, GND, and analogue out. When purchasing it you should also get a matching lead to save time and mucking about.

How it works is quite simple (I must stop writing that, some things are not as simple as they seem…) – the sensor contains an infra-red transmitter and a receiver. It returns a voltage that is relative to the distance between itself and the object in front of it. This output voltage is inversely proportional to the distance; which is explained better with this graph from the data sheet:

However it is always fun to test these things out yourself. So I placed a sensor up over my desk, measured out 80cm, and attached the multimeter to the analogue output of the sensor.

A crude setup but effective. I held a white piece of cardboard in front of the sensor, starting from more than one metre away, then moved closer to the minimum, then back out again. As shown in this video clip:

Although watching that multimeter may not have been too interesting, hopefully the next task will be!

Exercise 6.1

Using the values from the graph from the Sharp data sheet (above), make yourself a distance-measuring device. Use an LCD module to display the measurements. Metric and imperial! This shouldn’t be too hard at all, you’re just using one analogue input from the sensor, some basic maths, and displaying some data on an LCD. Furthermore, to make it truly portable, you could wire up a 9v PP3 battery to a DC plug and use it for power. A hint – before calculating distances, run a sketch to just return the analogRead() value from the sensor. Then you can make your own judgement on voltage-distance calculations. To save time I used the Electronic Bricks to rapidly construct this prototype.

You will need:

Anyhow, here is a photo of what I came up with:

and the ubiquitous video clip

Finally, my sketch for the solution: Exercise 6.1.pdf. You may have to adjust the values in the decision tree for more accuracy. After spending some time with this sensor, I wouldn’t rely on it for exact distance calculations, however it would be very useful for general item detection, air switches and so on. In the next week or two we will examine another type of distance sensor.

What else could this be used for? Robotics sensors, burglar alarms, switching things on and off. Hopefully you have gained some knowledge about this sensor and have some ideas for implementation.

Coffee time.

Now that we have spent a few weeks constructing our prototypes on breadboards and electronic bricks, it is now time to look at how we can do this in a more compact, and/or permanent method. As you already know, the Arduino system allows for “shields”, PCBs that plug on top of your Arduino board to add some sort of extra functionality. One of these was the Electronic Brick chassis, another popular shield is the ethernet shield.

Well that’s all very nice, but can we do this ourselves? Of course. You need a prototyping shield. There are two main types of protoshield, one that contains a small solderless breadboard that can be used on the shield:

or a shield that is plainly a PCB, ready to solder a circuit onto it. This one below is great, it includes two extra LEDs and a button. Furthermore, the yellow PCB makes things easier to see:

As you can imagine, one is more permanent than the other. In this chapter you can follow me create my own circuit on the plain PCB protoshield.

Recently I purchased a couple of blank protoshields (the yellow one above) in order to make a shield with two 7-segment LED displays and 74HC595 shift registers – as it takes a long time to wire these up on a breadboard. So after composing a diagram of which pins are connected to which pins, it was time to place the components and start soldering.

The board basically a matrix of through-plated holes, so you can solder into them from both sides. Which makes linking them together very simple:

However you really need to be careful planning your board, top and bottom, to avoid things getting messy:

Another trap to look out for is trying to squeeze too much in at once. This can cause you to do some very creative soldering:

The plan was to have two wires in the one hole, a lead and a resistor tail. Very difficult for me to do neatly. However at the end it all came together… somehow!

With this example, some wires have been soldered on the read. In fact, most of them were on the rear. Anyhow, the last thing to do is solder in the header pins in order for our new protoshield to stack on top of our Arduino. You can either solder on full header sockets, just like the Arduino, or pins if you don’t need to stack another shield on top of yours. In this case you would not cover up the displays, so only pins will be used. The best way to solder the pins is to place them into your Arduino, put your shield on top, then solder. Example:

And once it came time to set my shield down on the pins, a very amusing (to me) thing happened – it would not sit straight! All those wires underneath the PCB interfered with the microcontroller on the Arduino itself:

So there is a useful tip for you: always plan  your protoshields in all three dimensions! Otherwise things may not go as planned, and you don’t want a leaning tower of shields. But finally, it did work with some careful wire repositioning:

So there you have it, a quick demonstration of what to do and not do when using a blank prototyping shield. In the near future we shall make more use of these.

Moving on…

In previous instalments we have worked with 7-segment LED displays, using up to three at once, being controlled by 74HC595 shift registers. As you may have realised by now that involved a lot of wiring, resistors, time and effort. But what if you need four or more digits? Use an LCD… Maybe. Sometimes you need to use LED displays for aesthetic reasons, price, clarity, or just because you love that LED look. Thankfully you can find four digit displays, instead of having to use 2 x 2 or 4 x 1 digit displays. Let’s have a look at one now:

For the newcomer there would be a surprising lack of pins on this display module. That is a good thing, and a slightly tricky thing – but we can overcome the obstacles and use it very easily. How? Again, with two 74HC595 shift registers and some brainpower. Firstly, let’s have a look at the pins – from left to right they are: E, D, C, G, F, B, A, C1, C2, C3, C4, decimal point, unused, unused. This display is common cathode, so to display (for example) the number 1 on digit 3, you would apply ~+2 volts to pins 6 and 7, and attach ground to pin 10. Very much the same as using a single-digit display, except you need to choose the cathode that corresponds with the digit you wish to use. In this tutorial we are using a Common Cathode unit. Out of curiosity’s sake, here is the data sheet for the module used in this chapter: data sheet.pdf.

Secondly, how are we going to control the cathodes with out Arduino? Current comes out of a cathode, so it would not accept a signal from our digital out pins. What we need to do is have a simple switch on each cathode between the display pin and ground, so we can control which digit we want to use. How can we do this with our Arduino? Easy… we can use a simple NPN transistor as a switch. Remember we did this with a relay in chapter three!

But using 4 digital out pins for cathode control is a waste of pins, we can use our trusty shift register again to control the cathodes. So that means we need two shift registers in total, the first to control the digit (0~9), and the second to switch on the cathode of the position we wish to display our digit in. Time to do it!

The first (left-hand) shift register from the Arduino controls the segments on the display, via 560 ohm resistors. Just like last time. The second (right-hand) shift register controls the cathodes. Pins Q0~Q3 connect to the base of a BC548 transistor via a 1k ohm resistor. The collector of the transistor is connected to the cathode on the display, and the emitter to ground. For example:

Note that the schematic above is a guide only. But here it is in real life, below:

After a few projects, wiring up displays and shift registers should be a lot quicker for you now. Here is the matching sketch I came up with for the demonstration video below: Example 6.1.pdf

You’d have to admit, even in the year 2010, LED displays still look mesmerising. Or maybe that’s just me! Here is the data sheet display.pdf for the LED display I used. You can use other ones,as long as they are common cathode; just match the LED element pins with your first shift register, and the cathode pins with the second shift register.

But on to making something useful…

Exercise 6.2

Using the hardware from example 6.1 above, create a device that displays the value of an analogue sensor. For example, if we connect a 10k variable resistor to an analogue input, the Arduino will return a reading of between 0 and 1023. From a hardware perspective, all you need to do is add an analogue sensor (e.g. LDR, 10k variable resistor, the infra-red sensor from earlier on, etc.). The software will be a little tricky, but if you completed exercise 5.1, or 5.2 you shouldn’t have a problem at all. As you will be displaying one digit at a time, but very quickly, try to minimise the number of times you clear the display – in doing so you will keep the brightness at a maximum.

You will need:

  • Your standard Arduino setup (computer, cable, Duemilanove)
  • One 4-digit, 7-segment LED display, common cathode
  • Two 74HC595 shift registers
  • Four BC548 or equivalent NPN transistors
  • 8 x 560 ohm 0.25 W resistors. For use as current limiters between the LED display segments and ground
  • One 10k variable resistor
  • a breadboard and some connecting wire

For motivation, here is a video clip of my result. There are two examples, one with leading zeroes, and one without:

And the sketch as well: exercise 6.2.pdf

That wasn’t too hard was it? Now that you can use such a display, it will become easier to display output from your various projects.

Another week over! And again, I’m already excited about writing the next instalment… Congratulations to all those who took part and built something useful! Please subscribe (see the top right of this page) to receive notifications of new articles. High resolution photos are available from flickr.

If you have any questions at all please leave a comment (below). If you would like to showcase your work from this article, email a picture or a link to john at tronixstuff dot com.

You might even win a prize. Don’t forget to check out the range of gear at Little Bird Electronics!

So have fun, stay safe and see you soon for our next instalment!


This is part of a series titled “Getting Started with Arduino!” – A tutorial on the Arduino microcontrollers, to be read with the book “Getting Started with Arduino” (Massimo Banzi).

The first chapter is here.

Welcome back fellow arduidans!

Hello once again to our weekly Arduino instalment. This week are up to all sorts of things, including: more shiftiness with shift registers, more maths, 7-segment displays, arduinise a remote control car, and finally make our own electronic game! Wow – let’s get cracking…

In the last chapter we started using a 74HC595 shift register to control eight output pins with only three pins on the Arduino. That was all very interesting and useful – but there is more! You can link two or more shift registers together to control more pins! How? First of all, there is pin we haven’t looked at yet – pin 9 on the ’595. This is “data out”. If we connect this to the data in pin (14) on another ’595, the the first shift register can shift a byte of data to the next shift register, and so on.

Recall from our exercise 4.1, this part of the sketch:

digitalWrite(latchpin, LOW);

shiftOut(datapin, clockpin, MSBFIRST, loopy);

digitalWrite(latchpin, HIGH);

If we add another shiftOut(); command after the first one, we are sending two bytes of data to the registers. In this situation the first byte is accepted by the first shift register (the one with its data in pin [14] connected to the Arduino), and when the next byte is sent down the data line, it “pushes” the byte in the first shift register into the second shift register, leaving the second byte in the first shift register.

So now we are controlling SIXTEEN output pins with only three Arduino output pins. And yes – you can have a third, fourth … if anyone sends me a link to a Youtube clip showing this in action with 8 x 74HC595s, I will send them a prize. So, how do we do it? The code is easy, here is the sketch: Example 5.1

On the hardware side, it is also quite simple. If you love blinking LEDs this will make your day. It is the same as exercise 4.1, but you have another 74HC595 connected to another 8 LEDS. The clock and latch pins of both ’595s are linked together, and there is a link between pin 9 of the first register and pin 14 of the second. Below is a photo of my layout:

and a video:

Can you think of anything that has seven or eight LEDs? Hopefully this photo will refresh your memory:

Quickie – if you want to find out the remainder from a quotient, use modulo – “%”. For example:

a = 10 % 3;

returns a value of 1; as 10 divided by 3 is 3 remainder 1.

and

If you need to convert a floating-point number to an integer, it is easy. Use int();. It does not round up or down, only removes the fraction and leaves the integer.

Anyhow, now we can consider controlling these numeric displays with our arduino via the 74HC595. It is tempting to always use an LCD, but if you only need to display a few digits, or need a very high visibility, LED displays are the best option. Futhermore, they use a lot less current than a backlit LCD, and can be read from quite a distance away. A 7-segment display consists of eight LEDs arrange to form the digit eight, with a decimal point. Here is an example pinout digram:

Note that pinouts can vary, always get the data sheet if possible.

Displays can either be conmmon-anode, or common-cathode. That is, either all the LED segment anodes are common, or all the cathodes are common. Normally we will use common-cathode, as we are “sourcing” current from our shift register through a resistor (560 ohm), through the LED then to ground. If you use a common-anode, you need to “sink” current from +5v, through the resistor and LED, then into the controller IC. Now you can imagine how to display digits using this type of display – we just need to shiftout(); a byte to our shift register that is equavalent to the binary representation of the number you want to display.

Huh?

Let’s say we want to display the number ’8′ on the display. You will need to light up all the pins except for the decimal point. Unfortunately not all 7-segment displays are the same, so you need to work out which pinout is for each segment (see your data sheet) and then find the appropriate binary number to represent the pins needed, then convert that to a base-10 number to send to the display. I have created a table to make this easier:

And here is a blank one for you to print out and use: blank pin table.pdf.

Now let’s wire up one 7-segment display to our Arduino and see it work. Instead of the eight LEDs used in exercise 4.1 there is the display module. For reference the pinouts for my module were (7,6,4,2,1,9,10,5,3,8) = (a,b,c,d,e,f,g,DP, C, C) where DP is the decimal point and C is a cathode (which goes to GND). The sketch: example5p2.pdf. Note in the sketch that the decimal point is also used; it’s byte value in this example is 128. If you add 128 to the value of loopy[] in the sketch, the decimal point will be used with the numbers.

and the video:

There you go – easily done. Now it is time for you to do some work!

Exercise 5.1

Produce a circuit to count from 0 to 99 and back, using two displays and shift-registers. It isn’t that difficult, the hardware is basically the same as example 5.1 but using 7-segment displays.

You will need:

  • Your standard Arduino setup (computer, cable, Duemilanove)
  • Two 7-segment, common-cathode displays
  • Two 74HC595 shift registers
  • 16 x 560 ohm 0.25 W resistors. For use as current limiters between the LED display segments and ground
  • a breadboard and some connecting wire
  • some water

You are probably wondering how on earth to separate the digits once the count hits 10… a hint: 34 modulo 10 = 4. 34 divided by 10 = 3.4 … but 3.4 isn’t an integer. While you are thinking, here is the shot of my layout:

and the ubiquitous video:

And here is my sketch: exercise5.1.pdf

I hope you have gained more of an understanding of the possibilities available with shift registers. We will contiunue with more next week.
However, next on our agenda is some real-world hacking. This section of the chapter is more of a commentary than the usual format, but I hope you find it interesting and you receive some inspiration or ideas after reading it.

Although we have been having fun (well I have been, hopefully someone else is as well) making things on our desks or work benches, it is time to slowly enter the real world and hack something up. The other day I was in a variety store to buy some glue, and happened across a very cheap remote-control car. After noticing it had full directional control (left/right, forwards/backwards) it occured to me that we could control it with an arduino. So $9 later here it is on my desk:

Naturally I stopped everything else and had a play with it. But by crikey it was very fast:

The first thing to do would be slow this baby down. Due to the …cheapness of the product it did not have variable speed control. So the first thing to do was pull the body off to see what we had to work with:

The design is very simple, with one motor controlling the steering, and one for the speed. Luckily for me there were four wires heading to the motor from the PCB, and the were very easy to get to.

Normally we could use pulse-width modulation to slow motors down, but I don’t think we could send a PWM signal over radio control. Instead, it would be easier to reduce the voltage going to the drive motor in order to slow it down. So with the car up on blocks, the motor was set to forward with the remote and I measure the voltages across the four wires. Black and green was +3.7 in forwards, nothing in reverse, black and red was the same in reverse, and nothing forwards. Easy – just find out how much current the motor draws at full speed and then we can use Ohm’s law (voltage = current x resistance) to calculate the value of a resistor to slow it down about 70% or so.

The motor initially drew ~500 mA to start up and then reduced to ~250 mA once it got going after around one second. However, a various range of resistors from 10 to 120 ohm didn’t really seem to have much effect, and a 560 ohm knocked it out all together. So instead of trying to control speed with a hardware method, we will try with a software method… perhaps try PWM after all, or create our own.

But now, time to get the arduino interfaced with the transmitter unit. Firstly I reassembled the car, then started on the transmitter:

After cutting my finger trying to get the transmitted open, it eventually gave in and cracked open. But the effort was worth it – the control buttons were very simple rubber pads over the PCB spots:

Excellent – each controller was basically a SPDT switch, and there is plenty of space on the PCB to solder in some wires to run to the Arduino and a breadboard. The push buttons could be replaced with BC548 transistors controlled by our Arduino – the same we we controlled a relay in Chapter Three.

Next was to solder some wires from the PCB that could run to my breadboard:

The green wire is a common return, and the yellow wires are forwards, reverse, left and right. Now to set up the breadboard. Four digital out pins, connected to the base of a BC548 transistor via a 1k resistor. The emitters are connected to GND, which is also connected to the GND of the transmitter.

Just as I had finished making up the breadboard, after turning around to close a window my arm brushed the transmitter and it made a ‘crack’ noise.

My soldering had come unstuck. Oh well, it was only reverse! Time to get moving anyhow. Once again, I put the car up on blocks and uploaded the following sketch:

/*

Example 5.3

Control a toy remote control car with arduino
Chapter Five @ http://www.tronixstuff.com/tutorials
*/
int forward = 12;
int left = 9;
int right = 7;
int del = 5000;
void setup()
{
pinMode(forward, OUTPUT);
pinMode(left, OUTPUT);
pinMode(right, OUTPUT);
}
void loop()
{
digitalWrite(right, HIGH);
delay(1000);
digitalWrite(right, LOW);
delay(1000);
digitalWrite(left, HIGH);
delay(1000);
digitalWrite(left, LOW);
delay(1000);
digitalWrite(forward, HIGH);
delay(del);
digitalWrite(forward, LOW);
delay(1000);

}

It cycles throgh the three (working!) function of the car. Let’s see what happens:

That’s a good start, things are moving when we want them to move. However the car’s motors seem to be pulsing. Perhaps the resistor-transistor bridge to the arduino had something to do with that. So I threw caution to the wind and connected the digital output pins directly to the transmitter. Wow! That fixed it. The motors are going at full speed now

Using our knowledge of Arduino sketches it will be east to make this car to drive around. Let’s try that now… here is our sketch:

/*

Example 5.4

Control a toy remote control car with arduino – figure eight

Chapter Five @ http://www.tronixstuff.com/tutorials

*/

int forward = 12;

int left = 9;

int right = 7;

int del = 5000;

void setup()

{

pinMode(forward, OUTPUT);

pinMode(left, OUTPUT);

pinMode(right, OUTPUT);

}

// to make creating the car’s journey easier, here are some functions

void goleft(int runtime)

{

digitalWrite(left, HIGH);  // tell the steering to turn left

digitalWrite(forward, HIGH); // move the car forward

delay(runtime);

digitalWrite(forward, LOW);

digitalWrite(left, LOW);  // tell the steering to straighen up

}

void goright(int runtime)

{

digitalWrite(right, HIGH);  // tell the steering to turn right

digitalWrite(forward, HIGH); // move the car forward

delay(runtime);

digitalWrite(forward, LOW);

digitalWrite(right, LOW);  // tell the steering to straighen up

}

void goforward(int runtime)

// run the drive motor for “runtime” milliseconds

{

digitalWrite(forward, HIGH);  // start the drive motor forwards

delay(runtime);

digitalWrite(forward, LOW); // stop the drive motor

}

void loop()

{

goforward(1000);

goleft(1000);

goright(1000);

}

For some reason now forwards made the car go backwards. And only when I removed the GND wire from the Arduino to the breadboard. Interesting, but perhaps a problem for another day.

There we have it. Our first attempt at taking over something from the outside world and arduinising it. Now it is back to our normal readings with an exercise!

Exercise 5.2

Once again it is your turn to create something. We have discussed binary numbers, shift registers, analogue and digital inputs and outputs, creating our own functions, how to use various displays, and much more. So our task now is to build a binary quiz game. This is a device that will:

  • display a number between 0 and 255 in binary (using 8 LEDs)
  • you will turn a potentiometer (variable resistor) to select a number between 0 and 255, and this number is displayed using three 7-segment displays
  • You then press a button to lock in your answer. The game will tell you if you are correct or incorrect
  • Basically a “Binary quiz” machine of some sort!

I realise this could be a lot easier using an LCD, but that is not part of the exercise. Try and use some imagination with regards to the user interface and the difficulty of the game. At first it does sound difficult, but can be done if you think about it. At first you should make a plan, or algorithm, of how it should behave. Just write in concise instructions what you want it to do and when. Then try and break your plan down into tasks that you can offload into their own functions. Some functions may even be broken down into small functions – there is nothing wrong with that – it helps with planning and keeps everything neat and tidy. You may even find yourself writing a few test sketches, to see how a sensor works and how to integrate it into your main sketch. Then put it all together and see!

You will need: (to recreate my example below)

  • Your standard Arduino setup (computer, cable, Duemilanove)
  • Three 7-segment, common-cathode displays
  • eight LEDs (for binary number display)
  • Four 74HC595 shift registers
  • 32 x 560 ohm 0.25 W resistors. For use as current limiters between the LED display segments and ground
  • a breadboard and some connecting wire
  • 10k linear potentiometer (variable resistor)
  • some water

For inspiration here is a photo of my layout:


and a video of the game in operation. Upon turning on the power, the game says hello. You press the button to start the game. It will show a number in binary using the LEDs, and you select the base-10 equivalent using the potentiometer as a dial. When you select your answer, press the button  - the quiz will tell you if you are correct and show your score; or if you are incorrect, it will show you the right answer and then your score.

I have set it to only ask a few questions per game for the sake of the demonstration:

And yes – here is the sketch for my answer to the exercise: exercise 5.2.pdf

At this point we are taking a week off from the tutorials, however chapter six will be published around 21st May. But stick around – we will have two new kit reviews, some great part reviews, and a new project published in the next 7 days, so subscribe and follow us – see the top right of this web page!

High resolution images available at flickr.

If you have any questions at all please leave a comment (below). If you would like to showcase your work from this article, email a picture or a link to john at tronixstuff dot com.

You might even win a prize. Don’t forget to check out the range of gear at Little Bird Electronics!

So have fun, stay safe and see you  for our next instalment!


This is part of a series titled “Getting Started with Arduino!” – A tutorial on the Arduino microcontrollers, to be read with the book “Getting Started with Arduino” (Massimo Banzi).

The first chapter is here.

Welcome back fellow arduidans!

Hello once again to our weekly Arduino instalment. This instalment is a little early this week. This time we will be looking at getting more outputs from less pins, listening to some tunes, saying hooray to arrays, and even build a self-contained data logger!

So let’s go!

More pins from less – sounds too good to be true, doesn’t it? No, it is true and we can learn how to do this in conjunction with a special little IC, the 74HC595 Serial In/Parallel Out 8-bit Shift Register. Let’s say hello:

Before we get too carried away, we need to understand a little about bits, bytes and binary numbers.

A binary number can only uses zeros and ones to represent a value. Thus binary is also known as “base-2″, as it can only use two digits. Our most commonly used number types are base-10 (as it uses zero through to nine; hexadecimal is base-16 as it uses 0 to 9 and A to F). How can a binary number with only the use of two digits represent a larger number? It uses a lot of ones and zeros. Let’s examine a binary number, say 10101010. As this is a base-2 number, each digit represents 2 to the power of x, from x=0 onwards.

See how each digit of the binary number can represent a base-10 number. So the binary number above represents 85 in base-10 – the value 85 is the sum of the base-10 values.

Another example – 11111111 in binary equals 255 in base 10.

Now each digit in that binary number uses one ‘bit’ of memory, and eight bits make a byte. A byte is a special amount of data, as it matches perfectly with the number of output pins that the 74HC595 chip controls. (See, this wasn’t going to be a maths lesson after all). If we use our Arduino to send a number in base-10 out through a digital pin to the ’595, it will convert it to binary and set the matching output pins high or low.

So if you send the number 255 to the ’595, all of the output pins will go high. If you send it 01100110, only pins 1,2,5, and 6 will go high. Now can you imagine how this gives you extra digital output pins? The numbers between 0 and 255 can represent every possible combination of outputs on the ’595. Furthermore, each byte has a “most significant bit” and “least significant bit” – these are the left-most and right-most bits respectively.

Now to the doing part of things. Let’s look at the pinout of the 74HC595: (from Philips/NXP 74HC595 datasheet)

Pins Q0~Q7 are the output pins that we want to control. The Q7′ pin is unused, for now. ’595 pin 14 is the data pin, 12 is the latch pin and 11 is the clock pin. The data pin connects to a digital output pin on the Arduino. The latch pin is like a switch, when it is low the ’595 will accept data, when it is high, the ’595 goes deaf. The clock pin is toggled once the data has been received. So the procedure to get the data into a ’595 is this:

1) set the latch pin low (pin 12)

2) send the byte of data to the ’595 (pin 14)

3) toggle the clock pin (pin 11)

4) set the latch pin high (pin 12)

Pin 10 (reset) is connected to the +5V.

Thankfully there is a command that has parts 2 and 3 in one; you can use digitalWrite(); to take care of the latch duties. The command shiftOut(); is the key. The syntax is:

shiftout(a,b,c,d);

where:

a = the digital output pin that connects to the ’595 data pin (14);

b = the digital output pin that connects to the ’595 clock pin (11);

c can be either LSBFIRST or MSBFIRST. MSBFIRST means the ’595 will interpret the binary number from left to right; LSBFIRST will make it go right to left;

d = the actual number (0~255) that you want represented by the ’595 in binary output pins.

So if you wanted to switch on pins 1,2,5 and 6, with the rest low, you would execute the following:

digitalWrite(latchpin, LOW);

shiftOut(datapin, clockpin, MSBFIRST,102);

digitalWrite(latchpin, HIGH);

Now, what can you do with those ’595 output pins? More than you could imagine! Just remember the most current you can sink or source through each output pin is 35 milliamps.

For example:

  • an LED and a current-limiting resisor to earth… you could control many LEDs than normally possible with your Arduino;
  • an NPN transistor and something that draws more current like a motor or a larger lamp
  • an NPN transistor controlling a relay (remember?)

With two or more ’595s you can control a matrix of LEDs, 7-segment displays, and more – but that will be in the coming weeks.

For now, you have a good exercise to build familiarity with the shift-register process.

Exercise 4.1

Construct a simple circuit, that counts from 0~255 and displays the number in binary using LEDs. You will require the following:

  • Your standard Arduino setup (computer, cable, Duemilanove)
  • 8 LEDs of your choosing
  • One 74HC595 shift register
  • 8 x 560 ohm 0.25 W resistors. For use as current limiters between the LEDs and ground.
  • a breadboard and some connecting wire

The hardware is quite easy. Just remember that the anodes of the LEDs connect with the ’595, and the cathodes connect to the resistors which connect to ground. You can use the Arduino 5V and GND.

Here is what my layout looked like:

and of course a video – I have increased the speed of mine for the sake of the demonstration.

How did you go? Here is the sketch if you need some ideas – Ex 4.1

Next on the agenda today is another form of output – audio. Of course you already knew that, but until now we have not looked at (or should I say, listened to) the audio features of the Arduino system. The easiest way to get some noise is to use a piezo buzzer. An example of this is on the left hand side of the image below:

These are very simple to use and can be very loud and annoying. To get buzzing, just connect their positive lead to a digital output pin, and their negative lead to ground. Then you only have to change the digital pin to HIGH when you need a buzz. For example:

/* Example 4.1

Annoying buzzer!

CC by-sa v3.0

http://tronixstuff.wordpress.com */

void setup()

{

pinMode(12, OUTPUT);

}

void loop()

{

digitalWrite(12, HIGH);

delay(500);

digitalWrite(12, LOW);

delay(2000);

}

You won’t be subjected to a recording of it, as thankfully (!) my camera does not record audio…

However, you will want more than a buzz. Arduino has a tone(); command, which can generate a tone with a particular frequency for a duration. The syntax is:

tone(pin, frequency, duration);

where pin is the digital output pin the speaker is connected to, frequency in Hertz, duration in milliseconds. Easy!

If you omit the duration variable, the tone will be continuous, and can be stopped with notone();. Furthermore, the use of tone(); will interfere with PWM on pins 3 and 11, unless you are using an Arduino Mega.

Now, good choice for a speaker is one of those small 0.25w 8 ohm ones. My example is on the right in the photo above, taken from a musical plush toy. It has a 100 ohm resistor between the digital output pin and the speaker. Anyhow, let’s make some more annoying noise – hmm – a siren!

/* Example 4.2

Annoying siren

CC by-sa v3.0

http://tronixstuff.wordpress.com */

void setup()

{

pinMode(8, OUTPUT); // speker on pin 8

}

int del = 250; // for tone length

int lowrange = 2000; // the lowest frequency value to use

int highrange = 4000; //  the highest…

void loop()

{

// increasing tone

for (int a = lowrange; a<=highrange; a++)

{

tone (8, a, del);

}

// decreasing tone

for (int a = highrange; a>=lowrange; a–)

{

tone (8, a, del);

}

}

Phew! You can only take so much of that.

Array! Hooray? No… Arrays.

What is an array?

Let’s use an analogy from my old comp sci textbook. Firstly, you know what a variable is (you should by now). Think of this as an index card, with a piece of data written on it. For example, the number 8. Let’s get a few more index cards, and write one number on each one. 6, 7, 5, 3, 0, 9. So now you have seven pieces of data, or seven variables. They relate to each other in some way or another, and they could change, so we need a way to keep them together as a group for easier reference. So we put those cards in a small filing box, and we give that box a name, e.g. “Jenny”.

An array is that small filing box. It holds a series of variables of any type possible with arduino. To create an array, you need to define it like any other variable. For example, an array of 10 integers called jenny would be defined as:

int jenny[9];

Nine? Yes. Arrays are “zero-indexed”, which means the first element in the array is zero, and in jenny’s case, the last is 9. Just like those old HP keyboards with function keys f0~f9. Anyway. And like any other variable, you can predefine the values. For example:

int jenny[9] = {0,7,3,8,6,7,5,3,0,9};

Before we get too excited, there is a limit to how much data we can store. With the Arduino Duemilanove, we have 2 kilobytes for variables. See the hardware specifications for more information on memory and so on. To use more we would need to interface with an external RAM IC… that’s for another chapter down the track.

Now to change the contents of an array is also easy, for example

jenny[3] = 12;

will change our array to

int jenny[9] = {0,7,3,12,6,7,5,3,0,9};

You can also use variables when dealing with arrays. For example:

for (int i = 0; i<10;  i++; i<10)

{

jenny[i] = 8;

}

Will change alter our array to become

jenny[] = {8,8,8,8,8,8,8,8,8,8}

A quick way set set a lot of digital pins to output could be

int pinnumbers [] = {2,3,4,5,6,7,8,9,10,11,12,13}

for (int i= 0; i++; i<12)

{

pinMode(pinnumbers[i],OUTPUT);

}

Interesting… very interesting. Imagine if you had a large array, an analogue input sensor, a for loop, and a delay. You could make a data logger. In fact, let’s do that now.

Exercise 4.2

Build a temperature logger. It shall read the temperature once every period of time, for 24 hours. Once it has completed the measurements, it will display the values measured, the minimum, maximum, and average of the temperature data. You can set the time period to be of your own choosing. So let’s have a think about our algorithm. We will need 24 spaces to place our readings (hmm… an array?)

  • Loop around 24 times, feeding the temperature into the array, then waiting a period of time
  • Once the 24 loops have completed, calculate and display the results on an LCD and (if connected) a personal computer using the Arduino IDE serial monitor.

I know you can do it, this project is just the sum of previously-learned knowledge. If you need help, feel free to email me or post a comment at the end of this instalment.

To complete this exercise, you will need the following:

  • Your standard Arduino setup (computer, cable, Duemilanove)
  • Water (you need to stay hydrated)
  • Analog Devices TMP36 temperature sensor (Farnell part number 143-8760)
  • 1 little push button
  • 1 x 10k 0.25 W resistor. For use with the button to the arduino
  • breadboard and some connecting wire
  • one LCD display module

And off you go!

Today I decided to construct it using the Electronic Bricks for a change, and it worked out nicely.

Here is a photo of my setup:

a shot of my serial output on the personal computer:

and of course the ubiquitous video. For the purposes of the demonstration there is a much smaller delay between samples…

(The video clip below may refer to itself as exercise 4.1, this is an error. It is definitely exercise 4.2)

And here is the sketch if you would like to take a peek – Ex 4.2. High resolution photos are available in flickr.

Another week over! I’m already excited about writing the next instalment… Congratulations to all those who took part and built something useful! Please subscribe (see the top right of this page) to receive notifications of new articles.

If you have any questions at all please leave a comment (below). If you would like to showcase your work from this article, email a picture or a link to john at tronixstuff dot com.

You might even win a prize. Don’t forget to check out the range of gear at Little Bird Electronics!

So have fun, stay safe and see you soon for our next instalment!


Apr
27

The Mechatronics Guy has created a wonderful sheet containing everything you will need to know about Arduino. Constants, control structures, libraries, pin layouts – everything!

Click here to download a full-size copy…

If you are interested in all things Arduino, we have a weekly Arduino tutorial which is fun, easy and interesting. The first chapter starts here.


Apr
20

Getting Started with Arduino! – Chapter Three

arduino, Arduino Tutorial, education, learning electronics, microcontrollers, servo Comments Off on Getting Started with Arduino! – Chapter Three 

This is part of a series titled “Getting Started with Arduino!” – A tutorial on the Arduino microcontrollers, to be read with the book “Getting Started with Arduino” (Massimo Banzi).

The first chapter is here.

Welcome back fellow arduidans!
Hello once again to our weekly Arduino instalment. This time we will be looking at relays, becoming more functional, getting interrupted, and finally being served up some servos. So let’s go!

First on the agenda to day are relays. What is a relay? Think of it as two things that are very close together: a coil that sometimes has a current passing through it; and a switch, that defaults in one direction. When a current passes through the coil, it generates an electromagnetic field which causes the switch to change state. The beauty of a relay is this: you can use a small current and voltage to switch on and off a very large current and/or voltage – and the switch and coil current are isolated from each other. Here is an example of a relay:

If you look closely you can see the coil and the internals of the switch. This particular model has a double-pole, double throw switch. That means two inputs can be switched in either of two directions. The coil needs 12 volts to activate; and the switch can handle 250 volts AC at 5 amps; and the coil resistance is 200 ohms. Ohm’s law (voltage = current x resistance) tells us the coil current is 60mA. No way you can get that sort of current out of an arduino – hence the need for a relay. (Though if anyone wants to try, stand back and film it for us!) The only problem with relays is that they contain moving parts (the switch) and hence will wear out over time. So if you design a relay into a project, be sure to document a maintenance schedule for the end-user or maintenance people.

How will we use this with our arduino? Once again – very easily. But we need a partner in our relay quest – a switching transistor. A simple, garden-variety NPN model will do, such as the BC548. However, when selecting your transistor you need to ensure that it can handle the current of the relay coil. The data sheet for your transistor (e.g. our BC548) will mention a value called Ic – collector current. For our BC548 this is 100mA, and greater than the 60mA of our relay coil. Perfect!

Almost there… when a coil switches off, all the electromagnetic radiation in the coil needs to go somewhere, otherwise it could pulse down into the transistor. Therefore a simple 1A power diode (such as a 1N4004) is placed across the coil, allowing current to flow through the coil and the diode as a loop until it dissipates.

The last thing to verify is the relay coil voltage. If you have a 5V relay, with a low coil current, you can use the arduino power. However in most cases your coil voltage will be 12V, so it will require its own power supply.

Here is the schematic for what you should end up with, using a 12V relay and a low current transistor:

So now for a simple test to get a feel for the operation of a relay… here is our sketch:

// example 3.1
// relay test – John Boxall – http://tronixstuff.wordpress.com

void setup()
{
pinMode (2, OUTPUT); // set pin 2 as an output pin
}

void loop()
{
for (int i = 1; i<=20; i++) // loop 20 times
{
digitalWrite (2, HIGH); // turn on pin2 for 1 second, then off for one second
delay (1000);
digitalWrite (2, LOW);
delay (1000);
}
delay (2000);
}
Our hardware is exactly as the schematic above. Here is a photo:

And of course a video. Here you can see in detail the coil causing the switch to change poles.


From here on you understand and can use an arduino to switch a very high current and/or voltage. Please exercise care and consult an expert if you are working with mains voltage. It can KILL you.

So now it is time to get more functional.

There are three main components to an arduino sketch: the variables, the structure and the functions. Functions are the commands that request something to happen, for example analogRead();. You can also define your own functions to improve the structure and flow of your sketch. If you have previous programming experience, you may think of these as sub-procedures, or recall using GOSUB in BASIC all those years ago. An ideal candidate for a custom function would be exercise 2.2 from our last instalment – we could have written functions to organise the min/max display or reset the memory. However, first we must learn to walk before we can run…

Do you remember void loop(); ? I hope so – that is the function that defines your sketch after the setup. What it really does is define the code within into a loop, which runs continuously until you reset the arduino or switch it off. You can simply define your own functions using the same method. For example:

void blinkthree()  // the name of my function is “blinkthree”

{

for (int i = 0; i <=3; i++) // loop three times

{

digitalWrite(8, HIGH); // turn on LED connected to digital pin 8

delay (1000);

digitalWrite(8, LOW); // turn off LED connected to digital pin 8

delay (1000);

}

}

Now that function has been defined, when you want to blink the LED on pin 8 three times, just insert void blinkthree(); into the required point in your sketch. But what if you want to change the number of blinks? You can pass a parameter into your function as well. For example:

void blinkblink(int blinks)  // the name of my function is “blinkblink”, and receives an integer which is stored in the variable blinks

{

for (int i = 0; i <=blinks; i++) // loop “blinks” times

{

digitalWrite(8, HIGH); // turn on LED connected to digital pin 8

delay (1000);

digitalWrite(8, LOW); // turn off LED connected to digital pin 8

delay (1000);

}

}

So to blink that LED 42 times, execute blinkblink(42); Want to specify your own delay? Try this:

void blinkblink(int blinks, int del)  // the name of my function is “blinkblink”, and receives an integer which is stored in the variable blinks, and another del …

{

for (int i = 0; i <=blinks; i++) // loop “blinks” times

{

digitalWrite(8, HIGH); // turn on LED connected to digital pin 8

delay (del);

digitalWrite(8, LOW); // turn off LED connected to digital pin 8

delay (del);

}

}

So to blink that LED 42 times, with an on/off period of 367 milliseconds – execute blinkblink(42,367);. It is quite simple, don’t you think?
Ok, one more. Functions can also function as mathematical functions. :)
For example:
real circlearea (real radius)
{
float result = 0;
result = 3.141592654 * radius * radius;
return result;
}

Do you see what happened there? If our sketch determined the radius of a circle and placed it in a variable radius2, the area of the circle could be calculated by:

area2 = circlearea(radius2);

Easy.

So now you can create your own functions. Not the most colourful of sections, but it is something we need to know.

Time for a stretch break, go for a walk around for five minutes.

OK, time for a quickie. Sometimes you need to use a variable in a situation where it can be changed by forces outside of the regular sketch – for example code triggered by an interrupt. So you declare these types of variables volatile. E.g. “volatile int problemCode = 0″ declares an integer variable by the name of problemCode, that will be used in the regular sketch and

Now it is time to interrupt your break with some interrupts.

An interrupt is an event that occurs when the state of a digital input pin changes, and causes a specific function to be called and its contents to be executed.

For example, you may have a system that reads the temperature of a room, and automatically adjusts an air-conditioner’s thermostat to maintain a precise 23 degrees Celsius. You also have a sensor that monitors the mains voltage, and changes state when there is a blackout. This would be a trigger for an interrupt – so you would know on your display right away that the mains power is off – instead of finding out over a longer span of time due to the room temperature slowly rising. Then you could do something before the room temperature was too much.

Another example may be a robot… while it is happily wandering about a sensor is monitoring a proximity sensor pointing to the ground, which changes state when the robot is lifted off the ground and triggers an interrupt – which could switch off the wheels or sound an alarm (“Help, I’m being stolen!”). I am sure your imagination can think of many other things.

So how do we make an interrupt interrupt? It is relatively easy, with a couple of limitations. You can only monitor two pins (for a normal arduino board) or six with an arduino mega. Furthermore, you cannot use the function delay() in your interrupt function. Now, you need to decide three things: the pin to monitor (digital 2 or 3, referred to as 0 or 1), the function to run when the interrupt occurs, and what sort of behaviour to monitor on the interrupt pin – that is, the change of state of the pin. Your pins also need to be set to output using pinMode();.

There are four changes of state: LOW (when the pin becomes low), CHANGE (when the pin changes state, from high or from low), RISING (when pin goes from low to high) and FALLING (when pin goes from high to LOW). Initially that looks like  a lot to remember, but it is quite simple when you think about it.

Crikey – that was a lot to take in. So instead of theory, it is time for some practice.

Example 3.2 – interrupt demonstration.

In this example, we will have our random number generator from example 2.2, but with two interrupts being monitored. These will be triggered by push buttons for simplicity.

/*

Example 3.2 – interrupts

Created 21/04/2010 —  By John Boxall — http://tronixstuff.wordpress.com —  CC by-sa v3.0

Just send some data to the LCD, whilst monitoring two interrupts

*/

#include <LiquidCrystal.h> // we need this library for the LCD commands

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

float noisy = 0;

void setup()

{

lcd.begin(16, 2);             // need to specify how many columns and rows are in the LCD unit

lcd.setCursor(0,0);

lcd.println(“* example 3.2 * “);

lcd.setCursor(0,1);

lcd.println(“tronixstuff.com “);

lcd.setCursor(0,1);

delay(4000);

lcd.clear();

randomSeed(analogRead(0)); // reseed the random number generator with some noise

attachInterrupt(0, panicone, HIGH); // so when interrupt zero (digital pin 2) changes state, it will trigger the interrupt and go to function ‘panicone’

attachInterrupt(1, panictwo, HIGH); // so when interrupt one (digital pin 3) changes state, it will trigger the interrupt and go to function ‘panicone’

}

void loop()

{

noisy=random(1000);

lcd.setCursor(0,0);

lcd.print(“Random Numbers!”);

lcd.setCursor(0,1);

lcd.print(“Number: “);

lcd.print(noisy,0);

delay(1000);

}

void panicone()

{

lcd.clear();

lcd.println(“Interrupt one   “);

}

void panictwo()

{

lcd.clear();

lcd.println(“Interrupt two   “);

}

Of course it wouldn’t be right without a photo of the board layout – we have just reused the LCD set-up from example 2.2, and added two standard push-buttons and 10k resistors (as per page 42 of the book) for the interrupts. Here you are:

And the video… those switches could really have used a de-bounce circuit, but for the purpose of the demonstration they are not really necessary.

Finally – it’s servo time! I really hope you went through the other sections before heading here – although they may not have been that interesting, they will certainly be useful.

What is a servo?

Think of a little electric motor that is connected to a variable resistor. An electric pulse or command is sent to the motor, and it rotates until it reaches a position that matches a value of the potentiometer. Yes, that sounds a little crazy.

A much simpler explanation is this: a servo is an electric motor that can be commanded to rotate to a specific angular position. For example, they are commonly used to control the steering in a remote-control car. Thankfully once again with arduino and friends, using a servo is very easy, and allows your imagination to go nuts, limited only by the amount of spare time and money you have. :)

When considering the use of a servo, several factors need to be taken into account. These include:

  • rotational range, that is the angular range it can rotate. 180 degrees, 360 degrees (full rotation), etc.
  • the speed at which it can rotate (usually measured in time per degrees)
  • the torque the servo can generate (how strong it is)
  • weight, cost, and so on

One of the first things that came to mind was “Wow – how many can I use at once?” And the answer is … 12 on the duemilanove, and 48 (wow) on the arduino mega. Please note you cannot usedanalogWrite(); on pins 9 and 10 when  using the servo library. For more details, please see the arduino servo library page.

For our examples and exercises today, I am using the Turnigy TG9. It is very cheap (I’m a student!) and light, good for demonstration purposes and often used in remote control aircraft.  It can rotate within a range of almost 180 degrees (well it was cheap).

I hope you noticed that there are three wires to the servo. One is for +5V, one is for GND, and one is the control pin – connect to an arduino digital out. Which colour is which pin may vary, but for this adafruit servo, the darkest is +GND, the lightest is control, and the middle colour is the +5V.

When working with angles, you should have a protractor handy. Such as:

Now how do we control our servo? First of all, we need to use the servo library. In the same manner as we did with the LCD screen in chapter two, place the following line at the start of your sketch:

#include <Servo.h>

So now we have access to a range of servo commands.

Then you need to create the servo object in your sketch, so it can be referred to, such as

Servo myservo;

Then finally, attach the servo to a digital pin for control (within your void(setup); )

myservo.attach(9);  // attaches the servo on pin 9 to the servo object

That is the setting up out of the way. Now all you need to do is this…

myservo.write(pos);

where pos is a value between 0 and 180. (or more or less, depending on the rotational range of your servo).

Now, the proof is in the pudding so to speak, so here once more is an example of it all coming together and rotating. :) The following example moves from left to middle to right and repeats, to give you an idea of what is happening.

/*

Example 3.3 – servo examination

Created 21/04/2010 —  By John Boxall — http://tronixstuff.wordpress.com — CC by-sa v3.0

*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

int pos = 0;    // variable to store the servo position

int del = 100; // delay in micoseconds

void setup()

{

Serial.begin(9600);

myservo.attach(9);  // attaches the servo on pin 9 to the servo object

}

void loop()

{

for (int loopy = 0; loopy<=3; loopy++)

{

for (pos = 180; pos >=0; pos–) // from left to right with Hextronik HXT900

{

myservo.write(pos);

delay(del);

}

delay(1000);

}

for (int loopy = 0; loopy<=3; loopy++)

{

myservo.write(180);

delay (1000);

myservo.write(90);

delay (1000);

myservo.write(0);

delay (3000);

}

}

The board layout is quite simple, just the three servo wires to the arduino board.

And the video. I am sorry that my camera does not record audio, as you cannot hear the cute buzz of the servo.

Ok then – that’s enough reading and watching from your end of the Internet. Now it is time for you to make something; using all the knowledge that we have discussed so far…

Exercise 3.1

We can use our digital world to make something useful and different – an analogue digital thermometer, with the following features:

  • analogue temperature display over a 180-degree scale. The range will vary depending on your home climate. My example will be 0~40 degrees Celsius
  • analogue meter showing whether you can have the heater or air-conditioner on, or off. A rendition of exercise 2.1 in analogue form.
  • minimum and maximum temperature display, displayable on demand, with indicators showing what is being displayed (LEDs would be fine); and a reset button

You will need to combine your own functions, working with temperature sensors; a lot of decision-making, digital and analogue inputs, digital and analogue outputs, and some creativity. To reproduce my example of the exercise, you will need the following:

  • Your standard Arduino setup (computer, cable, Duemilanove)
  • Water (you need to stay hydrated)
  • Analog Devices TMP36 temperature sensor (Farnell part number 143-8760)
  • 2 little push buttons
  • 2 x 10k 0.25 W resistors. They work with the buttons to the arduino
  • a breadboard and some connecting wire
  • two LEDs to indicate minimum/maximum
  • 2 x 390 ohm 0.25 W resistors. They are to reduce the current to protect the LEDs.

Off you go… if you have any questions, leave a comment at the end of the post, or email john at tronixstuff dot com.

And now for the results of the exercise. Here are photos of my board layout:

Here you can see the buttons for displaying minimum/maximum temperature, and the reset button. The LEDs indicate the right servo is display minimum or maximum temperature, or illuminate together to ask if you want to reset the memory. And of course, our video:

And here is the sketch for my example board layout: sketch

Wow. Congratulations to all those who took part and built something useful!

Please subscribe (see the top right of this page) to receive notifications of new articles. If you have any questions at all please leave a comment (below). If you would like to showcase your work from this article, email a picture or a link to john at tronixstuff dot com. You might even win a prize. Don’t forget to check out the range of gear at Little Bird Electronics!

So have fun, stay safe and see you soon for our next instalment! Chapter Four!


Apr
14

This is part of a series titled “Getting Started with Arduino!” – A tutorial on the Arduino microcontrollers, to be read with the book “Getting Started with Arduino” (Massimo Banzi). The first chapter is here.

Welcome back fellow arduidans!

I hope you have been enjoying these posts and learning and creating and making many things. If not, you soon should be! :)

Today’s post has several things: taking temperatures, sending data from the arduino back to your PC, opening a library, using LCD screens, and some exercises that will help to consolidate your previous knowledge and help revise it.

First of all, we shall investigate another analogue sensor – a temperature sensor. As you can imagine, there are many applications for such a thing, from just telling you the current temperature, to an arduino-based thermostat control system. And it is much easier to create than most people would think – so get ready to impress some people!

Let’s say hello to the Analog Devices TMP36 Low-voltage temperature sensor


Tiny, isn’t it? It looks just like a standard transitor (e.g. a BC548) due the use of the same TO-92 case style. The TMP36 is very simple in its use – looking at the flat face, pin 1 is for +5V supply (you can connect this to the 5V socket on your arduino), pin 2 is the output voltage (the reading), and pin three is ground/earth (connect this to the GND socket on your arduino). Furthermore, have a look at the data sheet, it is quite easy to read and informative. TMP36 data sheet

The TMP36 will return a voltage that is proportional to temperature. 10 mV for each degree Celsius, with a range of -40 to 125 degrees.

There isn’t any need for extra resistors or other components – this sensor must be the easiest to use out there. However there is one situation that requires some slight complexity – remote positioning of the sensor. It is all very well to have the sensor on your breadboard, but you might want it out the window, in your basement wine cellar, or in your chicken coop out back… As the voltage output from the sensor is quite low, it is susceptible to outside interference and signal loss. Therefore a small circuit needs to be with the sensor, and shielded cable between that circuit and the home base. For more information on long runs, see page eight of the data sheet.

At this point we’re going to have some mathematics come into the lesson – sorry about that. Looking again at page eight of the data sheet, it describes the output characteristics of the sensor. With our TMP36, the output voltages increases 10 millivolts for every degree Celsius increase; and that the output voltage for 25 degrees Celsius is 750 mV; and that there is an offset voltage of 500 mV. The offset voltage needs to be subtracted from the analogRead() result, however it is not without vain – having the offset voltage allows the sensor to return readings of below freezing without us having to fool about with negative numbers.

Quick note: A new type of variable. Up until now we have been using int for integers (whole numbers)… but now it is time for real numbers! These are floating point decimals, and in your sketches they are defined as float.

Now we already know how to measure an analogue voltage with our arduino using analogRead(), but we need to convert that figure into a meaningful result. Let’s look at that now…

analogRead() returns a value between 0 and 1023 – which relates to a voltage between 0 and 5V (5000 mV). It is easier on the mind to convert that to a voltage first, then manipulate it into temperature. So, our raw analogRead() result from the TMP36 multiplied by (5000/1024) will return the actual voltage [we're working in millivolts, not volts] from the sensor. Now it’s easy – subtract 500 to remove the offset voltage; then divide it by 10 [remember that the output is 10 mV per degree Celsius]. Bingo! Then we have a result in degrees Celsius.

If you live in the Fahrenheit part of the world, you need to multiply the Celsius value by 1.8 and add 32.

Quick note: You may have seen in earlier sketches that we sent a value to the serial output in order for the arduino software to display it in the serial monitor box. Please note that you cannot use digital pins 0 or 1 if using serial commands. We used Serial.begin(9600); in the void setup(); part of the sketch. You can also send text to the serial monitor, using Serial.print(); and Serial.println();. For example, the following commands:

Serial.print(“The temperature is: “);

Serial.print(temperature, 2);

Serial.println(” degrees Celsius”);

would create the following line in the serial monitor (assuming the value of temperature is 23.73):

The temperature is 23.73 degrees Celsius

and send a carriage return to start a new line. That is the difference between the Serial.print(); and Serial.println(); commands, the extra -ln creates a carriage return (that is, sends the cursor to the start of the next line. Did you notice the 2 in the Serial.print(); above? You can specify the number of decimal places for float variables; or if you are using an integer, you can specify the base of the number being displayed, such as DEC, HEX, OCT, BIN, BYTE – decimal, hexadecimal, octal, binary, or byte form. If you don’t use the second paramater of Serial.print();, it defaults to decimal numbers for integers, or two decimal places for floating-point variables.

Now let’s read some temperatures! All you need to do is connect the TMP36 up to the arduino board. pin 1 to 5v, pin 2 to analog 0, pin 3 to GND. Here is a shot of the board setup:


And here is the sketch:

/*
example 2.1 – digital thermometer
Created 14/04/2010 —  By John Boxall — http://tronixstuff.wordpress.com —  CC by-sa v3.0
Uses an Analog Devices TMP36 temperature sensor to measure temperature and output values to the serial connection
Pin 1 of TMP36 to Arduino 5V power socket
Pin 2 of TMP36 to Arduino analog 0 socket
Pin 3 of TMP36 to Arduino GND socket
*/
void setup()
{
Serial.begin(9600);   // activate the serial output connection
}
float voltage = 0; // setup some variables
float sensor = 0;
float celsius = 0;
float fahrenheit = 0;

void loop()
{              // let’s get measurin’
sensor = analogRead(0);
voltage = (sensor*5000)/1024; // convert raw sensor value to millivolts
voltage = voltage-500;        // remove voltage offset
celsius = voltage/10;         // convert millivolts to Celsius
fahrenheit = ((celsius * 1.8)+32); // convert celsius to fahrenheit
Serial.print(“Temperature: “);
Serial.print(celsius,2);
Serial.println(” degrees C”);
Serial.print(“Temperature: “);
Serial.print(fahrenheit,2);
Serial.println(” degrees F”);
Serial.println(“_ _ _ _ _ _ _ _ _ _ _ _ _ _  ”);
delay (1000); // wait a second, otherwise the serial monitor box will be too difficult to read
}

And there’s nothing like a video, so here it is. The measurements start at room temperature, then an ice cube in a plastic bag is pushed against the TMP36 for a moment, them held between two fingers to warm up again…


Quick note: the while() command. Sometimes you want a sketch to wait for user input, or wait for a sensor to reach a certain state without the sketch moving forward. The solution to this problem is the use of the while() command. It can cause a section of a sketch to loop around until the expression in the while command becomes true.
For example:

while (digitalRead(3) == LOW)
{
Serial.writeln(“Button on digital pin 3 has not been pressed”);
}

Anyhow, back to the next exercise – it’s now your turn to make something!

Exercise 2.1

Recently the cost of energy has spiralled, and we need to be more frugal with our heating and cooling devices. Unfortunately some members of the family like to use the air conditioner or central heating when it is not really necessary; many arguments are caused by the need for the heating/cooling to be on or off. So we need an adjudicator that can sit on the lounge room shelf and tell us whether it’s ok to use the heating or cooling.

So, create a device  that tells us when it is ok to use the air conditioner, heater, or everything is fine. Perhaps three LEDs, or a single RGB LED. Red for turn on the heat, blue for turn on the air conditioner, and green or white for “You’re fine, you don’t need anything on”. You will need to define your own temperature levels. Living here in north-east Australia, I’m going to have the air conditioner on above 28 degrees C; and the heat can come on at 15 degrees C.

Hopefully you are thinking about the voltmeter we made in chapter one, that should give you a starting point. If not, go back now and have a look. Otherwise, hop to it…
Anyway, here is my board layout…
You will need:
  • Your standard Arduino setup (computer, cable, Duemilanove)
  • Either three LEDs or an RGB LED
  • 3 x 390 ohm 0.25 W resistors. They are to reduce the current to protect the LEDs.
  • a breadboard and some connecting wire
  • a camera (optional) – to document your success!
And a sketch to solve the exercise:
/*
exercise 2.1 – Climate Control Judge
Created 14/04/2010 —  By John Boxall — http://tronixstuff.wordpress.com —  CC by-sa v3.0 Share the love!
Measures temperature with Analog Devices TMP36 and compares against minimum temperature to use a heater or air conditioner
*/
int redLED = 13; // define which colour LED is in which digital output
int greenLED = 12;
int blueLED = 11;
float voltage = 0; // set up some variables for temperature work
float sensor = 0;
float celsius = 0;
float heaterOn = 15; // it’s ok to turn on the heater if the temperature is below this value
float airconOn = 26; // it’s ok to turn on the air conditioner if the temperature is above this value
void setup()
{
pinMode(redLED, OUTPUT);    // set the digital pins for LEDs to outputs
pinMode(greenLED, OUTPUT);  // not necessary for analogue input pin
pinMode(blueLED, OUTPUT);
}
void loop()
{
digitalWrite(redLED, LOW);    // switch off the LEDs
digitalWrite(greenLED, LOW);
digitalWrite(blueLED, LOW);
// read the temperature sensor and convert the result to degrees Celsius
sensor = analogRead(0);       // TMP36 sensor output pin is connected to Arduino analogue pin 0
voltage = (sensor*5000)/1024; // convert raw sensor value to millivolts
voltage = voltage-500;        // remove voltage offset
celsius = voltage/10;         // convert millivolts to Celsius
// now decide if it is too hot or cold.
if (celsius>=airconOn)
{
digitalWrite(blueLED, HIGH); // ok to turn on the air conditioner
} else if (celsius<=heaterOn)
{
digitalWrite(redLED, HIGH);
} else
{
digitalWrite(greenLED, HIGH); // everything normal
}
delay(1000); // necessary to hold reading, otherwise the sketch runs too quickly and doesn’t give the LEDs enough time to
// power up before shutting them down again
}
And of course a video. For demonstration purposes, I have altered the values by making them very close, so it’s easier to show you the LEDs changing. The plastic bag used in the video is full of ice water.

Well that was interesting, I hope you enjoyed it and have some ideas on how to put temperature sensors to use. But now it is time to look at a library or two…
Quick note: As you know, there are several commands in the processing language to control your arduino and its thoughts. However, as time  goes on, people can write more commands and make them available for other arduino users. They do this by creating the software that allows the actual Atmel microcontroller interpret the author’s new commands. And these commands are contained in libraries. Furthermore, as Arduino is open-source, you can write your own libraries and publish them for the world (or keep ‘em to yourself…) In the arduino IDE software, have a look at the Sketch>>Import Library… menu option. Also, check out here for more libraries! Now to put one to good use…

Now it is time to look at liquid crystal displays! (Finally…)

As you are aware, LCDs are everywhere, in almost anything electronic that requires user-input or information display. You could even be looking at a really large one right now! But in the world of electronics enthusiasts, they have often been somewhat difficult to use. Until now! Once more the arduino makes it simple to use a variety of LCDs in your projects.

However, to keep it simple at this stage, you need to use an LCD that has a parallel interface and a Hitachi HD44780 controller (or 100% compatible) inbuilt. Don’t panic, these are very common, however you may find some shady sellers on eBay who will sell you something else, so keep an eye out (not literally). Identifying such LCDs is easy, as they almost always have the same type of interface. Normally they will have a row of 16 holes, clearly labelled. In the example below, I have soldered in some header pins to make it easier to use with a breadboard. If you are going to solder some pins in, don’t rest the LCD on the pins – they will be crooked. Instead, put the pins into a breadboard, then sit the LCD on top of the pins. Anyway, here’s our LCD:



To help identify the pinouts on your LCD and other useful facts, it is always wise to consult the data sheet. Furthermore, never buy an LCD if you cannot get a data sheet - you might think “Oh, I don’t really need one”, but unless you already have the same one you will need that sheet. One day. For example, like this:


In the examples for this chapter, you will notice that my LCD doesn’t have a back light. Yes, I’m a cheapskate. However many LCDs do, so take note about how to use their back light. In the near future I will update this chapter using an LCD with a back light. Subscribe to the email list (top right) to keep in touch. But now, back to the plan…
Firstly, hardware. Let’s connect our LCD to the arduino, using the following: LCD pin >>> Arduino pin (You may want to use a common ground on the breadboard then connect that to the Arduino)
  • 1 (ground) to GND
  • 2  (supply voltage) to 5V
  • 4 (RS) to digital 7
  • 5 (RW) to GND
  • 6 (E) to digital 8
  • 14 (DB7) to digital 12
  • 13  (DB6) to digital 11
  • 12 (DB5) to digital 10
  • 11 (DB4) to digital 9
  • connect a 10k linear potentiometer – the outer pins to +5V and ground, the centre pin to LCD pin 3. This is the contrast adjustment

We don’t use LCD pins  7~10, not in this case 15 or 16 – the back light pins.

Take note of the pin configuration above, as we need to know which LCD pin connects to which arduino pin. We tell the arduino this using the LiquidCrystal lcd(a, b, c, d, e, f); command. So in out wiring example above, we would use LiquidCrystal lcd(7, 8, 9, 10, 11, 12);. Here is a photo of our example board layout:

The difficult part is the wiring, the easy part is the programming. Once you have setup the pins using the LiquidCrystal lcd(); command, you can happily write to or control the LCD. The rest of the LCD commands are quite simple, so I will leave you to examine them on your own using the example hardware setup with the commands at arduino.cc/en/Reference/LiquidCrystal. But for the meanwhile, here is an example sketch for you:

/*

Example 2.2 – our first LCD sketch

Created 14/04/2010 —  By John Boxall — http://tronixstuff.wordpress.com —  CC by-sa v3.0

Just send some data to the LCD to experiment with it

*/

#include <LiquidCrystal.h> // we need this library for the LCD commands

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

float noisy = 0;

void setup()

{

lcd.begin(16, 2);             // need to specify how many columns and rows are in the LCD unit

lcd.println(“tronixstuff!    ”);

lcd.setCursor(0,1);

delay(2000);

lcd.clear();

randomSeed(analogRead(0)); // reseed the random number generator with some noise

}

void loop()

{

noisy=random(1000);

lcd.setCursor(0,0);

lcd.print(“Random Numbers!”);

lcd.setCursor(0,1);

lcd.print(“Number: “);

lcd.print(noisy,0);

delay(1000);

}

And now of course a video clip of example 2.2:

Now, it’s break time once more. When you return, we have…
Exercise 2.2

This is our most complex project to date, but don’t let that put you off. You have learned and practised all the commands and hardware required for this exercise. You only need a little imagination and some time. Your task is to build a digital thermometer, with LCD readout. As well as displaying the current temperature, it can also remember and display on request the  minimum and maximum temperatures – all of which can be reset. Furthermore, the thermometer works in degrees C or F.
First of all, don’t worry about your hardware or sketch. Have a think about the flow of the operation, that is, what do you want it to do? For a start, it needs to constantly read the temperature from our TMP36 sensor. You can do that. Each reading will need to be compared against a minimum and maximum value. That’s just some decision-making and basic maths. You can do that. The user will need to press some buttons to display and reset stored data. You can do that – it’s just taking action if a digital input is high. I will leave the rest up to you.
So off you go!

You will need (this may vary depending on your design, but this is what we used):

  • Your standard Arduino setup (computer, cable, Duemilanove)
  • Water (you need to stay hydrated)
  • 2 x 10k 0.25 W resistors. They work with the buttons to the arduino
  • Analog Devices TMP36 temperature sensor (Farnell part number 143-8760)
  • 2 little push buttons
  • breadboard and some connecting wire
  • 16×2 character LCD module and a 10k linear potentiometer or trimpot (For LCD contrast)
  • a camera (optional) – to document your success!

For inspiration, here is a photo of my board layout:




and a video clip of the digital thermometer in action.

And here is the sketch for my example – Exercise 2.2 sketch example
Wow. Congratulations to all those who took part and built something useful!

Please subscribe (see the top right of this page) to receive notifications of new articles. If you have any questions at all please leave a comment (below). If you would like to showcase your work from this article, email a picture or a link to john at tronixstuff dot com. You might even win a prize.

Don’t forget to check out the interesting and cool Arduino gear from Little Bird Electronics.


So have fun, stay safe and see you soon for our next instalment!


Lil Herbert - Beginner Robot

Lil Herbert - Beginner Robot

Contest entry by Annie (note: was submitted within the deadline, I wasn’t able to add to the blog until today)

In September of 2009 I found myself in a learning mood.  Throughout my life I have been fascinated by everything: science, math, history…you name it, I love to know about it.  In September I decided I was going to brush up on my electronics knowledge and see where it would take me.  I had studied electronics at a tech school during the 90s and I’d grown up in Silicon Valley so I wasn’t completely new to the endeavor.  But upon graduation from the tech program I immediately began working on computer network support and Key System/PBX telephone system programming rather than the nitty gritty world of capacitors, resistors and ICs and found my understanding of it all both fading and lacking.

As I practiced building little 555 timer and 386 audio amplifier circuits, I soaked in as much information as I could from forums and online electronics articles.  It was then that I began hearing   about something called Arduino.  Arduino?  What, pray tell, is an Arduino?

A pizza, perhaps?  As in “I’ll have a large pepperoni and Arduino with extra cheese!”  No, that wasn’t it.  Arduino…hmmmm.

A new Italian sports car?  “The new 2010 Arduino Coupe, 0 to 60 in 200 microseconds” (Of course with a little disclaimer at the bottom explaining that the Arduino driver is a pro, so kiddies, don’t try this at home!).  Well, that wasn’t it either.

A quick search of Wikipedia and then Amazon was my road to Damascus. I had found a microcontroller that was cheap, extremely easy to learn, a massive open-source community to hold my hand as I dipped my pinky toe into the microcontroller waters, and a seemingly unending variety of applications and add-ons.  By October 9th I had my first Arduino.  A Duemilanove.  It was (and still is) a thing of beauty in my eyes.

After a week of the usual “Hello World” blinking LED type projects, I decided I needed a long term project to build upon and to hone my skills.  Thus, Herbert was born.

Herbert started out with a discussion I had with my mom.  I was thinking of  some goals to set to help me learn all of the different aspects of micro-controller use.  I wanted to learn to write code.  I wanted to continue my work designing and building circuits.  I wanted to practice my soldering skills.  A robot project was the answer!

The goals for Herbert were these:

  • Start from scratch.  To really understand the workings of Herbert I needed to build him from the ground up, no ready-made kits.
  • Have the Arduino control his movement; he must start out with simple forward, backward and turning motions autonomously.
  • Add sensors to let Herbert see the world.  His first sensor is a Parallax Ping ultrasonic sensor, but eventually he will have many different types.
  • Through code of my own creation, have Herbert avoid collisions by turning, stopping or reversing.  I felt it was important for my educational development to create my own code rather than borrow someone else’s.  I have seen some fancy avoidance programming out there that I admire greatly.  But I knew if I didn’t start from scratch I would miss out on the joys of failure.

Have Herbert be a long range project.  I decided that he could be open ended.  As I solve one set of obstacles, I can move on and add new features.  Someday Herbert will talk, tell me the weather, read me my email and play songs off my computer for me.  It’s all just one step at a time.

The Basics

Robot Chassis

Robot Chassis

I started building in late October.  I received an early Christmas present in the form of 4 motors, 4 wheels and a chassis.  I decided to focus on a pulse width modulation circuit design to control the  independent speed of each motor.  After much studying on the web,   I built a circuit with 4 Darlington transistors to control the current   through the motors with the Arduino pins controlling the current  through each motor.  In addition, I added 4 reversed biased diodes to      protect the Arduino pins from kick-back voltage.

Schematic

Schematic

This circuit worked great for my first foray across the living room floor.  I could change the motor speed by changing the PWM in the Arduino sketch and soon I had Herbert zipping around scaring the dogs.  I decided it was time to give him some ‘eyes’.  While shopping for parts at Radio Shack one day I stumbled upon the Parallax Ping))) Sensor.  It is an ultrasonic sensor that was perfect for what I was doing.  With only a 5v, Gnd and Signal pin, I knew I could get it up and running with the Arduino!

I modified my code and put the signal for the Ping sensor on pin 9 of the Arduino.  I attached the 5v and Gnd of the sensor to the respective spots on the Duemilanove.  At this point I broke from my stated goal of always writing my own code.  The truth is, I had not the slightest idea how to write my own functions at this point, let alone libraries.  Luckily, the Arduino IDE saved the day!  In Files-Examples-Sensors there is a sketch for the Parallax Ping))) sensor.

After testing the sensor on a breadboard, I wired it up on Herbert.  I then took the important parts of the Ping))) sketch and added them to my current working sketch.  Herbert saw the light and was on the move!  I had him driving forward, detecting objects in front of him and turning to avoid them.  Granted, my code needed polishing but it was a start!

At this point my goal was to have Herbert move forward.  If he detected an obstacle he would stop and sweep his ping sensor to the left and take a measurement.  Then he would swing the sensor to the right and take another measurement.  He would then compare the two to decide which was a clearer path.  I wrote the sketch and it worked….once.  Somehow I had run into my first major bug and I was at a loss to figure it out.  Herbert was acting strange, not responding correctly and dancing around like a madman.

With little time before the contest deadline and wanting Herbert to make an appearance, I decided the strange problem must’ve been something to do with the cheap wheel motors I had (they had been giving me problems now and again already) and so I quickly ordered  4 Solarbotics GM13a 150:1 mini metal gear motors and tires to match.  They are much smaller than the no-name motors I had been using, but they are quiet and nice!  Herbert became Lil’ Herbert.

I rebuilt Herbert with the new motors and wheels and ran into the same strange behavior.  Obviously the motors weren’t the problem.  I’m sure I now know what it is, and I will experiment after the contest deadline to see if I am right.  I’ve been using an Adafruit Minty Boost to power the Arduino.  It’s a little circuit that converts the 3 volts from 2 AA batteries to 5 volts and sits in an Altoids tin on Herbert’s chassis.  I now believe that having the Arduino power the ping sensor, a sweeping servo and itself is just too much for the Minty Boost, causing strange things to happen.  But, as I was running out of time, I chose to forego the sweeping of the servo until after the deadline.

So, this is where we stand.  Or where Herbert rolls as it were.  I was still using my transistor circuit to power the motors and pinging to avoid collisions.  The main problem with this setup is that the motors’ current could only go one way.  I was able to drive Herbert forward and turn him, but he couldn’t reverse or turn on a dime.  At this time I decided that I knew enough about my transistor circuit/motor setup that I could investigate motor controller boards.  I knew I could build H-Bridge circuits to allow the motors to drive either direction, but I felt the compact nature of some of the control boards I had been looking at would help me keep Herbert compact.

So into the picture came 2 Pololu Qik 2s9v1 Dual Serial Motor Controllers.  They are little, efficient and allowed me to have Herbert go forward or backwards.  I once again sacrificed my vow to write my own code and used a library specifically for these boards.  My only trouble was the code was written for one board only, and I had two.  I fumbled my way through making 2 instances of the library and all was well.

As I write this it is 3:30 PM on December 31, 2009.  I have reached the contest deadline and can do no more.  Herbert can currently sense obstacles in front of him and turn to avoid them.  He can move forward and backward.  Sadly, there was no time to resolve his neck sweep issues in time.  But as Herbert travels around the house in the coming months he will be doing more and doing it more efficiently.  I will keep adding new videos to my You Tube page and Herbert will continue to annoy my dogs.

I have included two versions of Herbert’s sketches in the zipped folder.  One is from the early days of the transistor circuit, and the other is from this very day with the motor controllers.

Herbert’s videos can be seen on my You Tube channel.  The first one, Herbert is Born, was from November.  The most recent is Lil Herbert.

Videos: http://www.youtube.com/profile?user=AnnieNakki#g/u

Share/Bookmark

Contest Entry by Joe Cochran
In another project, I created a way to control a 8×8 RGB Matrix using an Atari Joystick. While waiting for one of the components to arrive, I had an idea that a maze could be constructed on the RGB Matrix and a user could go through the maze with a joystick.

Most maze algorithms assume that the maze can have “paper-thin” walls. That is, that the occupiable spaces don’t occupy the same amount of space as the walls. However, with the RGB Matrix the walls have to be represented by a whole LED being turned on. So in essence each LED is marked as a “wall” or as an “occupiable space”
Joe has created a page that contains the detailed instructions on how to create your own JoyLite Maze. I am posting the link to it, rather than recreating it all again.

JoyLite Maze “How To”.

Joe Says:Arduino has been a fantastic opportunity to for me rediscover the creative process. I became a software developer because I get a lot of satisfaction from turning an idea into reality. When you get down to it though, professional software development ends up being little more than manipulating some bits in databases and RAM. Nothing tangible. Arduino has allowed me to move beyond the “cyberspace” and into the “real world”, opening the door to physical computing with motors, switches, lights and dials. And while I may be short on knowledge in regards to the electrical and mechanical engineering aspects of these projects, the Arduino community is so healthy, friendly and capable that they help make learning this stuff a real treat too.
Share/Bookmark


  • Newsletter

    Sign up for the PlanetArduino Newsletter, which delivers the most popular articles via e-mail to your inbox every week. Just fill in the information below and submit.

  • Like Us on Facebook