CuCumber Creative: Projects

14-Sep-14 Arduino System Controller

Posted by David, 14-Sep-14

Another Arduino controller, this time for an educational project for our friends over a SupaLec EduConsoles. It a simple mathmatical tool designed to count pulses and to display the results on an LCD.

The controller consists of little more than an Arduino Uno, the LCD display and two switches so it was a pretty minimal project. The rest of the box was given over to the NiCAD charger and a USB interface for programming/debugging.

We realised that the unit would almost certainly spend most of its time outdoors being handled by school children, and kids, being kids, tend to be a bit rough Hence, the design had to be rigorous enough to withstand sustained abuse.

We selected a white-on-black LCD to give us the best possible contract in daylight conditions and a big, chucky industrial switch for the main trigger just to give the unit a fighting chance in the field. Two equally chunky devices were selected for the reset and On/Off switches.

The LCD code is almost exactly the same as the example provided with the Arduino IDE so I won't reproduce it here, and the NiCAD charger was a circuit we copied from the net and modified slightly to suit our purposes - we added an LED to indicate when the unit was charging/charged and an LED to indicate when it was switched on.

The unit worked pretty much first time and represented our first successful commercial collaboration with SupaLec. Therefore, quite pleased frankly.

07-Sep-14 Arduino-controlled DC motor drive

Posted by David, 07-Sep-14

Years ago, I bought into a magazine-based project called Real Robots. It was published by Eaglemoss Publications and the scheme was to build a largely autonomous robot called Cybot.

On paper, Cybot was a cute little gizmo that promised lots but, ultimately, delivered very little for the budding roboteer to really get their teeth into. Limited software, no circuit diagrams, no expansion capability. So, sad to say, once complete poor Cybot never really went anywhere... except our loft.

Recently, I rediscovered Cybot lurking behind a stack of boxes, neglected and unwanted, at the back of the aforementioned loft and, well, I still thought he looked pretty damned cool .. and maybe now was a good time to kick the little fella back into life.

Back in 2002/2003, I didn't really have the hardware skills to do anything clever with Cybot. These days, I can at least wire a mains plug without blowing myself up so I thought I'd have a go at resurrecting Cybot, except only this time with a half decent microprocessor and a good development environment.

The first goal in resurrecting Cybot was to see if I could get an Arduino to drive a DC electric motor. Not just any DC motor. I also found a second Cybot kit in the loft and used one of the motors from that as the basis for the experiment.

Fifteen minutes with a soldering iron and I had a basic motor circuit ready to test. The rest of the components were:

  • TIP120 power transistor
  • 1k resistor
  • 1n4002 diode

Here's the schematic. There's not much to it.

Operation: The Arduino can't source enough power to drive the motor on its own so we use the transistor to do the job for us.

We connect one end of the motor to the collector input of the transistor and connect the other to the positive rail, Vcc. We then connect the transistor's emitter to the ground rail.

The base of the transistor is connected to the Arduino's data line via a 1k resistor. The resistor is there to stop the Arduino dumping too much current into the transistor (yes, that's bad...)

Note: the use of the diode across the motor's inputs. This is to protect the transistor from the Back EMF generated by the motor - motors are inductive components and tend to kick back when you switch them on and off. Don't know what this means? Check out our forthcoming Introduction to Arduino courses.

Which Arduino output do we use? I picked one of the so-called PWM outputs, pin 9, for reasons which will become apparent very shortly.

To switch the motor on and off, we just take to one of the outputs on the Arduino high or low. How you do this is up to you. I just used a switch input with a pull-up resistor. Don't know what that is? We'll be posting an Introduction to Arduino page very shortly.

However, just switching the motor on and off is rather limited, and I wanted greater control over the speed of the motor. Hence, I decided to use something a little more fancy.

I connected a simple 10k variable resistor to one of the Arduino's analogue inputs and then converted the incoming 10-bit signal into an 8-bit value. This operation serves two purposes. Firstly, the analogWrite() functions accepts a value in the range 0..255 and secondly, it removes some of the unwanted noise from the input voltage.

You can download the Controller software here.

Note: Before you switch the power on, always go through the normal engineer's check list, inspecting for obvious short circuits in the form of solder bridges or, if you're using Veroboard, uncut tracks. If you have a meter, check that the overall resistance of the circuit as measured across the supply rails is more than say 200 ohms. In other words, make sure you don't short out your computer's USB bus. Don't just connect the thing up and hope for the best. Only do that if you like paying to have your blown USB ports fixed or if you like watching small whisps of blue smoke floating around in the workshop. Just sayin'...

I connected up the output of the transistor drive to an oscilloscope so that I could see the waveforms properly and then plugged the Arduino into the Mac's USB port. The Mac didn't complain - it flags up a warning if the USB port tries to draw too much power - and downloaded the test application. Within a couple of seconds, the motor burst into life and began rattling around on the desktop. It worked. The photograph shows the variable resistor controlling the speed by altering the mark/space ratio of the signal applied to the motor.

The motor doesn't really do anything with a mark/space ratio less than 20%. That's when it starts to do something. It starts with a dull rumble but increase the mark/space ratio to around 50% and the motor does go at a very healthy lick. Over 75% and it starts to sound a little stressed and at 90% it started to sound more than a little unhappy.

So, where next?

The Arduino can control just one of Cybots's motors. The next step is to control the other. I can either build another transistor switcher or start hacking around inside Cybot's own motor driver circuits. I found ths schematic on the web last week but it comes with a dire warning - try to drive both motors at the same time and there's a risk you'll blown the driver board.

I think I'll stick with my own circuits.

Check back shortly for more in this series of tutorials.