element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
CodeBug
  • Learn
  • Learning Center
  • STEM Academy
  • CodeBug
  • More
  • Cancel
CodeBug
Blog Better Fuel Economy with CodeBug
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join CodeBug to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: aaroNiGHTS
  • Date Created: 6 Nov 2015 7:20 AM Date Created
  • Views 1575 views
  • Likes 12 likes
  • Comments 4 comments
  • codebug_beginner
Related
Recommended

Better Fuel Economy with CodeBug

aaroNiGHTS
aaroNiGHTS
6 Nov 2015

The CodeBug is a cute, bug shaped board that is pushing to be a key tool for educational purposes, offering an introduction into coding and basic electronics.

The front of a CodeBug has a five by five grid of super bright red LEDs, used as the primary form of visual output. The two 'ears' of the CodeBug both have programmable tact switch buttons. The six 'legs' have super sensitive terminals for I/O and power interfacing. The bottom of the bug has a set of standard jumper sockets for more advanced serial interface and for attaching expansion boards, affectionately called 'tails'. Conveniently, this can be mated directly to the GPIO connector grid on a Raspberry Pi .

image

It's designed to be super easy, using a web browser based programming suite that functions without the need to install any software to get coding. Rather than typing by hand, code is assembled by dragging and dropping pieces of a colour coded jigsaw puzzle. You just select what kind of command you want to use; a loop, an if statement, a command light up the LEDs or respond to a button press, then drop it into your program. The coding environment also has a fully emulated and interactive CodeBug to run and test out programs without having to upload it to actual hardware.

A great and unique thing about programming the CodeBug is that it doesn't require installing any special drivers or software on your PC. Just hold down the left button on the CodeBug while plugging in the USB port to the PC and it will enter programming mode. The CodeBug will show up as a small USB flash drive, around 45 kilobytes in size. It might sound extremely small, but for holding the programmed code files needed it's more than enough space.

CodeBug programs are files with a .cfg extension. Loading the program is just a matter of putting the code file on the USB storage drive of the CodeBug, then hitting the button on the right to run it. Because no special drivers are needed, nearly any computer can be used to load a program - even a simple Raspberry Pi works flawlessly.

Coding and programming the CodeBug with a Raspberry Pi.image

There are two methods to power the CodeBug. If you connect the micro USB to a power source without holding down a button, the CodeBug will just run like normal and draw its power over the USB connection. Alternatively, you can keep the unit portable and use a 3 volt CR2032 coin cell battery slotted into the back of the unit. The CodeBug uses a very small amount of power so should be able to run off battery power for a long time before draining it completely.

Connecting things to the input/output connections is uses big sockets ideal for croc clips or banana plug connectors. It's very simple and they don't bend or snap like traditional jumper pins can with constant use. Alternatively, as the CodeBug is designed to be used as a wearable, conductive thread can be used to both interface with the connectors and to mount the unit onto something like a shirt lapel or the front of a hat. Because the power requirements of the CodeBug are so low there isn't any concern of getting an electric shock or be a fire risk from the electricity flow.

Common sense might make you think that getting the best economy out of driving a car involves being easy on the accelerator, but often being too hard on the brakes can be the most expensive way to drive. If you regularly brake hard it not only leads to much lower fuel economy but also makes the cars brake pads wear out faster - and from personal experience they are very expensive things to replace.

To keep track of the heavy braking in a car I used a CodeBug wired up to the brake pedal. The CodeBug lights up with a number displaying how many times the brakes are used very hard. Having this right in the dashboard of the car gives a reminder of how often the brakes are heavily used.

To be clear: sometimes braking hard is the best possible thing you can do, but by paying attention and braking smartly you can make driving that little bit cheaper.

To connect the CodeBug to the car I used thin wires, aluminium foil and strong duct tape. I mounted foil to the back of the brake pedal then connected it with a wire to the ground terminal on the CodeBug, being careful not to impede the travel of the pedal. Originally I intended to use a micro switch to trigger the alert, but it was near impossible to mount it without it impeding the brake pedals full travel distance in any way. To ensure safety I used a small block of very light foam mounted to the floor of the car, right behind the shaft of the brake pedal. I connected leg 1 of the CodeBug to another small piece of foil attached to the top of the foam. When the brake gets pressed it makes the foil on the back of the brake pedal shaft and on top of the foam to come into contact, grounding leg 1 of the CodeBug and activating the alert.

image

The two foil pads that make contact when the brakes are applied.

Getting the position of the foil pads right can be challenging. Its a matter of trial and error to space it out so the sensor is only activated when the brake is near fully depressed. I started with a thick slab of foam and gradually cut it back until it fitted just right. The terminals on the CodeBug are extremely sensitive, so only the smallest of contact between the two pads is enough to trigger it.

Different cars have wildly different dashboard configurations. Just for simplicity I used solid double sided mounting tape fixed to the back of the CodeBug, on top of its battery slot. My 1983 Toyota has a big, bulky dashboard with plenty of flat surfaces so finding a suitable place to mount it was easy. I was able to run the wires from the sensors under the dashboard and have them come out from an unused slot right next to the steering wheel.

image

The CodeBug mounted on the dashboard

The code I assembled can be downloaded from the CodeBug space here. There you can see the Blocky view of the assembled jigsaw puzzle, but also switch over to the Code Viewer to see the corresponding traditional lines of code.

The description of the assembled code, piece by piece, is as follows:

  • The first purple block starts the code then sets up leg 1 to receive the input from the brake. It also tells to CodeBug to stay awake indefinitely once powered on.
  • Next the variable named 'count', used to keep count of how many times the sensor is activated, is set to the base value of 0.
  • The number 0 is drawn to the LED grid on the CodeBug, the default state of having no recorded sensor activations.
  • The main loop of the program is inside a while loop. This is continuously run while the CodeBug is powered on.
  • The first if statement checks if the b button is pressed. If it is the CodeBug will sleep, essentially shutting down until another button press is detected.
  • Now an if statement checks to see if the leg the sensor is on has been grounded, meaning the brake sensor has been tripped.
  • The variable 'count' is incremented by 1, recording the number of times the brake sensor has been tripped.
  • Then it draws to the LEDs the sprite of a number that corresponds to the number that our variable 'count' is at.
  • It then pauses for 10 seconds, or 10,000 milliseconds, to wait for the brake pedal to be depressed.
  • Following this a second nested loop starts, checking to see if the variable count is greater or equal to 10
  • If the sensor has been triggered more than the10 times, a custom 'X' sprite is drawn to the LEDs. This is a warning to show that you've been braking hard too many times.
  • Finally it checks if the A button on the CodeBug is pressed. If it is the count variable is changed back to its base value and the LEDs are reset to 0, restarting the count from the beginning.

The Jigsaw-like programming language used by the CodeBugimage

After setting everything up I was surprised just how often I was abusing the brakes in my old car, even in low traffic areas. Keeping the counter from ticking up can turn into a bit of a game! I just have to remember to be careful not to disrupt traffic.

With the brake sensor attached only one of the four I/O plugs on the CodeBug are used. You could wire up something similar to other things in a car, like detecting how many times the hand brake is used or when the accelerator hits the floor. The super bright LEDs on the CodeBug are very clear, even while driving on a bright summers day. It's also not as imposing or distracting as an LCD screen or other display might be. Plus, having bright red LEDs on the dashboard can make your dashboard look like the one on KITT from the 80's TV show Knight Rider!

Have any questions about this CodeBug project? Leave them in the comments below or ask me on Twitter - @aaronightsimage

  • Sign in to reply

Top Comments

  • aaroNiGHTS
    aaroNiGHTS over 9 years ago in reply to gadget.iom +2
    It's the best way I came up with. I tried using a microswitch and a roller microswitch, but it never felt right and I was paranoid it would impede the break pedal.
  • DAB
    DAB over 9 years ago +1
    Nice simple engineering fix to test the idea. Duct tape and sponges, it doesn't get simpler than that. DAB
  • aaroNiGHTS
    aaroNiGHTS over 9 years ago in reply to DAB +1
    Simple is often best! Getting the right position on the pad took multiple tries, but it works well.
Parents
  • DAB
    DAB over 9 years ago

    Nice simple engineering fix to test the idea.

     

    Duct tape and sponges, it doesn't get simpler than that.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • DAB
    DAB over 9 years ago

    Nice simple engineering fix to test the idea.

     

    Duct tape and sponges, it doesn't get simpler than that.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • aaroNiGHTS
    aaroNiGHTS over 9 years ago in reply to DAB

    Simple is often best! Getting the right position on the pad took multiple tries, but it works well.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube