An Arduino Based Moped Display


Introduction: An Arduino Based Moped Display

About: I'm me! What more do I need to say ? Do I emphasize myself?

I brought a rundown old moped from my auntie a while ago, although it was a little beaten up she ran just fine, so i gave her a breath of life and now shes once again road worthy ( MOT guy was happy with the moped ;) )

Anyway, i'm sure your all thinking thats all good and well but this is a micro-controller contest dude...

So Lets Begin.....

The Atmega328p-pu needs no introduction >> heres a data sheet

My bike instrument panel had only the battery voltage monitor and the speedometer working, the bendy circuit behind the panel was toast due to the water ingress from p**ggios pants seals..ehm and the good news is the wiring was "OK" ...

suddenly i morphed into multimeter man!!

So with my meter in hand i probed...

Step 1: The BRAINS

Probing done, some math...yawn...basic function has returned! woohoo

indicators, oil lights, headlights etc...

looking good except

Alas, no fuel gauge...

no fuel gauge? no fuel gauge......

the original temp/time display had also kicked the bucket.


Already mentioned is the AMAZING atmega328p-pu (2nd image is the pin out)

Unfortunately, there isn't much room under that panel for a uno and the like, i didn't want to use a mini or nano.

I like to make things myself...

You will need >>

1 x Atmega328p-pu

1 x 16mhz crystal oscillator

2 x 22pf ceramic capacitor

1 x 10k ohm resistor (brown, black, orange) 1/4w

2 x 4.7k ohm resistor (yellow, purple, brown) 1/4w - will explain later why these are needed.

1 x kia7805a or similar voltage regulator

1 x 100uf 35v electrolytic capacitor

1 x 10uf 16v electrolytic capacitor

1 x 220 ohm resistor (red, red, brown)

1 x green led

1 x breadboard or PCB (i haven't included pcb files!)

heres a link for breadboarding a barebone >

construct the arduino...

Step 2: I2C

Hopefully you have a arduino running with either a boot loader installed or a means to upload sketches to your breadboardino?! i built my own programmer which ill be happy to talk about...but not now!
Remember those 4.7k resistors i told you to get. there for the i2c 20x4 lcd you will also be needing..

plop them in your board PULLUP style, one leg to vcc the other into the pins on the 328p

pin 28 and pin 27.

ill put a BOM at the end don't worry :-D

I'm using a blue backlit 20x4 I2C LCD.

if you don't know, i2c allows you to communicate with up to 120something differernt address's on the i2c bus! through "only" two wires...well four if you include supply.

heres a link for learning more about i2c >

while were on the subject, let me introduce you to another awesome little chip..

the MCP23017 from microchip. DATASHEET!! >

This little guy allows you too have 16 extra, thats right! 16 EXTRA GPIO pins.

Take note - pin One on the mcp23017 is considered as GPA0 and pin 16 is GPB7...physical pin one on the chip correspondence is to GPB0 - LOL

McpPin 13(SCL) to pin 28 on the 328p

McpPin 14(SDA) to pin 27 on the 328p

the idea of the 4.7k is to pull up the bus line for stability in case the chain is looooong.

the 2nd pic shows connections thru the analog pins A4 & A5 these are linked to the chip pins mentioned on the arduino circuit board. So, if your just using a normal arduino or if it doesn't have dedicated serial pins then use those.

Next..Some code.

Step 3: LEDS, No Code Means No Colzilla..

So. We have a breadboard based arduino with no sketch hooked up to a Lcd and this port expanding chip, now what.. L E D S ! !

everyone loves these little guys! there bright and colorful best of all simple & cheap!

ill be quick you code monster!

parts needed :

11 x leds colors ranging to your taste.

12 x ?? ohm resistors (?, ?, ?)

I just used 1k ohm because im, its what i had laying around! but you can work out what resistor value to use for your specific led if you like.

three red, two orange, two yellow, three green that make the leds plus one other color for the low fuel warning light, probably best to use something like yellow or red? i chose red...this also needs a current limiting resistor.

i attempted to set these out in a nice half circle with mild success..

pause and scratch your head time..

connect the anode (+) of the first led to pin 21 on the mcp

continue this pattern with the rest of the leds and there pins.

+ to 22, + to 23, + to etc

once you reach pin28, on the opposite side resides the lonesome pin 1..the first always...what?

pin one is GPB0 which is led 9

led1 > 22, led2 > 23, led3 > 24 and so on

led9 > 1, led10 > 2. hopefully that makes sense. it gets a whole lot more confusing from here...

wahahahaha < evil laugh!

Should really have named this bit the joys of leds......

Step 4: Some Code Talk..

More then likely read the code in the next step, if not then i don't know what to say.

this guy has a awesome blog and he explains this far better then i could >

#define portOfPin(P)\ (((P)>=0&&(P)<8)?&PORTD:(((P)>7&&(P)<14)?&PORTB:&PORTC))

#define ddrOfPin(P)\ (((P)>=0&&(P)<8)?&DDRD:(((P)>7&&(P)<14)?&DDRB:&DDRC))

#define pinOfPin(P)\ (((P)>=0&&(P)<8)?&PIND:(((P)>7&&(P)<14)?&PINB:&PINC))

#define pinIndex(P)((uint8_t)(P>13?P-14:P&7))

#define pinMask(P)((uint8_t)(1< 0)

#define isLow(P)((*(pinOfPin(P))& pinMask(P))==0)

#define digitalState(P)((uint8_t)isHigh(P))

Again. awesome!

I never figured out how to use this with the mcp library..yet.. but it works for the rest.

thats a point.


these are the libraries i'm using for this sketch, your own one's may work also.

this is where i was inspired and helped for the sparkplug coil >

the first two schematics are relevant.

i modified the circuit to use a tl431 shunt regulator in place of the 5v zenear diode.

The fuel sender and 10k resistor act as a variable voltage divider. 5x10000/20000=2.5

5v to 10k to sender to 0v and the junction between the two goes to a 1n4148 diode to analog 0.

Sender Must be on 0v side (emitter follower).

Take a reading from where the senders at full, write it down. do the same for when its empty.

mine was 9.5 high and 0.5 low.

edit the relevant part of the map function in fuel()

average = map(average, 9.5, 0.5, 0, ledCount); //very important to get values correct for it to work right.


im really sorry but i hold no responsibilty if you blow up the earth.. Unfortunately you controll your hands and mind, not me, him or her or them. just you.

i used the original fuel sender with original supply and wires, i just formed a voltage divider with a 3w resistor and a diode to take a ohm reading, yes i had it out of the petrol tank, dry as a bone..whilst measuring it and working out the map values.

Any questions~?

Up next.. the fiddly bits.

Step 5: CODE You LOVE

Heres a link to my sketch >

Edit>> i added a graph for the rpm, improved the intro with a led show, made it easier to edit required bits for your specific application.

in case that link fails i've also attached the .ino below!

where const int Circ = ??; put YOUR TYRE circumference in inches.


char enter[] = "put your title here";

char make[] = "Put make here";

char model[] = "put model here";

char reg[] = "put registration here";

its taken a while but it works, the idea is this..

stick a magnet to the front wheel with a hall sensor sending pulses to 328p pin 5 do some more math..yuk..and fathom mph from the input.

Have a rising edge pulse trigger a interrupt on pin 4 from a coil on the spark plug and calculate the firing of the spark plug REV counter!

Using a 10k thermistor connected to analog pin1 to read the temperature coming from the cylinder head.

Take the ohm reading from the original fuel sender in the bikes fuel tank and send this signal to analog pin 0

map the average of the reading to the leds thru the mcp23017.

A cool custom intro...why not.

some features im still working on/planning are

a menu system, external eeprom for storing the odometer data, a odometer, trip distance. eventually start my bike with my phone but im sceptical of the security of that...if i do end upo adding gsm i could then form some sort of anti theft tracker thing..i dont know..


As i promised this is the full list of bits and bobs >>

1x atmega328p-pu

1x mcp23017

1x sn74hc14n schmit trigger

1x 7805 voltage regulator

1x tl431 shunt regulator

1x bc547

1x 20x4 I2C LCD

11x 1k 1/4w resistor or the resistors you used mate

11x leds colors may vary. again math

2x 22pf ceramic capacitor

3x 100uf 35v electrolytic capacitor

1x 10uf 16v electrolytic capacitor

1x 16mhz crystal

8x 10k resistor 1/4w

3x 4.7k 1/4w resistor

1x linear hall effect sensor

2x 1n4148 switching diode

2x 1n4007 diode

2x 10nf polyester capacitor

fair bit but not to much.

the above list doesnt include the parts for the regulator circuit. that list is in the photos, i added it when i drew the circuit out..

Recently became the loving owner of a Anet A8 which ive already modified, and can now use as a plotter.

Ive always created rats nests of a circuit boards and have been a avid maker for a number of years and its high time i started printing boards. so plotter ready, etchent and board in the post, now learn to create schematics in gcode to plot and etch.

ill scan and upload a hand drawn schematic asap.

im more then happy to help anyone with any questions and i hope you enjoyed & learnt something form my first instructable!

this websites number one!


EXTRA! I've drawn a cave man circuit includes everything except to USB UART serial adaptor, gonna make a new instructable for that.

you may need to zoom in....sorry! Also, I included a short circuit protection 5v regulator circuit in the schematic for the PSU side. ;)

Microcontroller Contest

This is an entry in the
Microcontroller Contest



    • Casting Contest

      Casting Contest
    • Woodworking Contest

      Woodworking Contest
    • Microcontroller Contest

      Microcontroller Contest

    We have a be nice policy.
    Please be positive and constructive.




    Really sorry to anyone whom has followed the schematic, pin 18 on the mcp20317 should be pulled up to vcc.