Computing stuff tied to the physical world

Hardware design choices

With the basic specs and component choices out of the way, the next step is to come up with an initial design for the circuit to connect all the pieces together. Equally important, are some back-of-the-envelope calculations to make sure we’re not exceeding some physical limitation or spec of any of the components, and to get an idea how well it’ll work.

Gotcha’s

If we stick to the LPC810 µC, then the first issue is that the IR sensor produces an analog voltage, i.e. varying with detected distance, and that the LPC810 has no ADC input.

Luckily, the LPC810 does have a very crude analog input capability, in the form of a ladder network + comparator. Inside the µC are 31 resistors in series, connected between ground and the supply voltage. Along with two independent comparator inputs, this means that we can compare an input with any of these 32 “taps” and thus get a rough 5-bit estimate of the voltage. For a simple far/closer/close/near indication of distance, this should be fine.

The next problem is that the IR sensor operates on 5V, whereas the supply voltage of the µC is limited to max 3.6V. In the Getting Started setup, this was overcome with a red LED as “voltage-dropper”, but that wouldn’t give us a reliable supply voltage for the comparator.

The standard solution is to use 5V as supply voltage and then insert a 3.3V “voltage regulator” to turn the 5V into 3.3V (which it does by turning the surplus energy into heat).

Yet another problem comes from the LPC810’s limited pins: the comparator input pins are also needed for uploading. This means we can’t simply connect the IR sensor and the FTDI interface to the same pin – neither of them would work properly.

Again, there’s a way out: we could pre-load the software into the LPC810 before inserting it into this circuit. Then we won’t need to support uploads. And as you will see later on, there is actually a “trick” to make shared use of these pins without creating problems.

Resources

The next step is to figure out if that tiny 8-DIP µC is going to be up to this task. Does it have enough I/O pins, and can we attach everything we need? Let’s see:

  • 2 pins for power and ground (i.e. 3.3V)
  • 1 analog pin to attach the IR sensor’s output
  • 1 digital output for the blinking LED

Hey, not bad – we don’t need much (yet!). But all is not quite as easy as it seems. You’ll see.

Let’s keep the option open to connect a 7-segment display. Maybe we have enough pins.

Power

We’ve already established that we need 5V for the IR sensor, and that we can use a 3.3V regulator for the µC. What about current use? Hmmm…

The LPC810 is no problem at all, it draws a few mA while running and it could go to sleep to draw virtually nothing the rest of the time. But wait, this parking aid needs to be ready to go at any time – it wouldn’t be very convenient to come to the garage and have to step out of the car to turn this device on. And to not forget turning it off afterwards.

We’re going to need a way to jump to life when needed, and get back to sleep when not.

At first thought, that’s easy: we have the IR sensor to tell how far away the car is. It could also detect “not present at all”, right?

Well yes, but there’s a catch: the Sharp IR sensors require quite a bit of current to operate – around 40..50 mA according to the datasheet. They’d last just two days on a 4 AA batteries!

Two solutions: 1) don’t look for the car all the time, and 2) use another less power-consuming sensor to decide when to turn on. We’ll look into both approaches later.

Lastly, the power source itself: the Sharp IR sensor is not too picky about the exact voltage it is powered by. This means we can feed it with 4x AA batteries, and it should be fine:

  • with disposable alkaline batteries, the voltage will be 6V
  • with EneLoop’s or other NiMh’s, the voltage will be 4.8 .. 5.2V

As for the LPC810: it’ll be fine either way. The regulator always delivers a precise 3.3V out.

Parts needed

So a first list of the parts needed so far includes:

  • LPC810, pre-configured with the proper software
  • Sharp IR sensor (range 10..80 cm)
  • 3mm red LED
  • 4x AA battery pack
  • 3.3V voltage regulator
  • a few resistors and a few capacitors
  • breadboard and some jumper wires

The example below will use sturdy and very colourful wire connections, to help you see exactly what goes where. But longer flexible jumper wires are in fact a bit easier to use.

Let’s just start

Instead of planning and designing this whole project from start to finish, let’s just start building and see where it leads us. This is the main benefit of a breadboard after all: it’s trivial to build things piece by piece, and to make changes at any point later on as needed.

For reasons which will soon become clear, we’re going to use a USB BUB / FTDI interface instead of the battery pack while constructing and testing the GPA. It also has two pins with a supply of 5V, and we can easily replace it with a battery later, once everything works.

Step 1 – power supply

A good first step is to set up the 3.3V voltage regulator, needed to power the LPC810 in this circuit. Here is the minimum setup (remember: holes are inter-connected in groups of 5):

DSC 4836

The red wire is a temporary connection, which makes the LED turn on when this circuit is powered up (when inserting the BUB, that is – not shown here).

Make sure you get this working first, it’s an essential step before moving on!

The voltage regulator is marked “1702” + “3302L”. It has three pins, and it must be inserted the right way around. In most cases, making errors in a circuit is harmless, but especially on the power supply side of things you really want to be careful. Everything else gets connected to it, so it better deliver 3.3V and not something else to the µC, etc.

If you have a multimeter: see if you can measure 3.3V between the top left rows 1 and 3.

At this point, you have a 5V supply from the FTDI interface board, and you’ve constructed a 3.3V supply coming out of the 3-pin regulator, making the LED light up. Congrats!

Step 2 – adding the LPC810

If you don’t have a pre-configured LPC810 chip, you’ll need to first upload this code into it.

With an LPC810 chip containing the proper software, the next step is very easy to test:

DSC 4837

Note the changes in the circuit. The red wire has been moved around, there’s an extra purple wire, there’s also a tiny 0.1 µF orange capacitor, and the µC has been inserted into the breadboard. The dot on the LPC810 marks its pin 1, the rest of the pins are numbered in counter-clockwise order: pins 1..4 on the left, pins 5..8 on the right. Power on pins 6 + 7.

Now re-insert the BUB to connect power. If all is well, you should see the LED blink at least 10 times – very briefly, but regularly. After that, it may start blinking at a different rate.

We’re ready to add the IR distance sensor and start reading out its values.

[Back to article index]