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
In the Air Design Challenge
  • Challenges & Projects
  • Design Challenges
  • In the Air Design Challenge
  • More
  • Cancel
In the Air Design Challenge
Blog Carbon Footprint Monitoring - Mobile Application
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: xever
  • Date Created: 24 Feb 2015 10:19 AM Date Created
  • Views 740 views
  • Likes 5 likes
  • Comments 2 comments
  • iot_footprint
  • in_the_air_design_challenge_2014
  • in_the_air
Related
Recommended

Carbon Footprint Monitoring - Mobile Application

xever
xever
24 Feb 2015

Continuing from the last post, I created a (Windows Phone) mobile application that is largely based from this article and modified for use with the proposed system.  The UI will be very simple and will display the core metrics as defined in AirVantage application model.

 

image

The key metrics that I wanted to capture are :

  • Current Speed
  • Distance traveled
  • Travel Time
  • Idle Time
  • CO2 footprint

 

The code logic for the application is pretty straightforward as outlined below.

image

And translated as code below:

private void UpdateMetrics(Geocoordinate geocoordinate)
{
    int thisTick = Environment.TickCount;
         
    /* Update travel time */
    int tickLapsed = thisTick - _timeLastPositionChanged;
    _travelTime = _travelTime.Add(TimeSpan.FromMilliseconds(tickLapsed));


    double speed = geocoordinate.Speed.HasValue ? geocoordinate.Speed.Value : 0;


    /* Speed is reported in meters/sec */
    if(geocoordinate.Speed.Value < MIN_SPEED || geocoordinate.Speed.HasValue == false)
    {
        /* speed is below minimum speed or has not been reported, this could indicate we are at idle */
        _idleTime = _idleTime.Add(TimeSpan.FromMilliseconds(tickLapsed));
    }


    double travel = Haversine.Distance(
                        new Position() { Latitude = geocoordinate.Point.Position.Latitude, Longitude = geocoordinate.Point.Position.Longitude },
                        new Position() { Latitude = _lastGeocoordinate.Point.Position.Latitude, Longitude = _lastGeocoordinate.Point.Position.Longitude },
                        DistanceType.Kilometers);


    _distanceTravelled += travel;


    double co2 = ((_distanceTravelled / KM_PER_LITER) * CO2_KG_PER_LITER);
    _co2 = co2;
         
    /* Update UI components */
    Map.Center = geocoordinate.Point;
    Speed.Text = "Speed: " + (speed * 3.6).ToString("0.0") + " kph";


    TravelTime.Text = "Travel Time: " + _travelTime.ToString(@"hh\:mm\:ss");
    IdleTime.Text = "Idle Time: " + _idleTime.ToString(@"hh\:mm\:ss");
    Distance.Text = "Distance: " + _distanceTravelled.ToString("0.0") + " km";


    if (co2 < 1)
        Co2Level.Text = "CO2: " + (co2 * 1000).ToString("0") + " gms";
    else
        Co2Level.Text = "CO2: " + (co2).ToString("0.000") + " kg";         


    double distanceSinceLastRender = Haversine.Distance(
                new Position() { Latitude = _lastGeoPoint.Latitude, Longitude = _lastGeoPoint.Longitude },
                new Position() { Latitude = geocoordinate.Point.Position.Latitude, Longitude = geocoordinate.Point.Position.Longitude },
                DistanceType.Kilometers);


    /* add data point to map line */
    if (distanceSinceLastRender > 0.010)
    {
        _geoPositions.Add(geocoordinate.Point.Position);
        _mapLine.Path = new Geopath(_geoPositions);   
        _lastGeoPoint = geocoordinate.Point.Position;             
    }


    _timeLastPositionChanged = Environment.TickCount;
    _lastGeocoordinate = geocoordinate;
}

 

As you may have observed, idle time starts ticking when the speed is below the minimum value of 10kph.  The distance traveled is calculated at each geographical position changed using Haversine formula.  CO2 level is calculated as described in previous post where KM_PER_LITER and CO2_KG_PER_LITER are set as 12.5 and 2.22 respectively.

 

When the Stop button has been tapped, the monitoring flag is reset and the data is sent to AirVantage.  Immediately after writing the code, I tested it by driving around the block, and verified the data has been successfully saved in AirVantage.



image


image



 

 

 

 

 

 

 

 

 

Fascinated by the data, I started using the app today and monitored how much my footprint is when dropping the kids to school.

image

Looking at this data, I spent almost 44% travelling in idle (10kph or less) most of it is due to traffic.  My average speed is 16.85kph on a 50kph road, seems like its better to cycle (if possible) during this time than travelling on car.  Also, 1.35kg of CO2 was produced for that particular trip, given 5 days of school x 2 trips per day x 10 weeks (ave) per term x 4 terms a year ends up 540 kg of CO2 annually!

 

Update:

As I was not able to track a couple trips to work using this app, I thought of automating the process such that the app will auto-launch when the phone is placed in the cradle.  This ensures that the application starts immediately at the beginning of each trip.  This was done by programming an NFC sticker that will launch the app and pass an argument.  The app has to be slightly modified as well to handle the argument.  A short clip has been added in this post to see how it works.

 

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

  • Sign in to reply

Top Comments

  • xever
    xever over 10 years ago in reply to fvan +1
    Thanks for the remark. The unit is next to the value. For time metrics, it is in the hh:mm:ss format. One reason why I kept the map in the UI is that I am planning to draw a different line colour to the…
Parents
  • fvan
    fvan over 10 years ago

    Impressive work! Just a tiny remark: it would be useful to add units to the screen without the map image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • fvan
    fvan over 10 years ago

    Impressive work! Just a tiny remark: it would be useful to add units to the screen without the map image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • xever
    xever over 10 years ago in reply to fvan

    Thanks for the remark.  The unit is next to the value.  For time metrics, it is in the hh:mm:ss format.  One reason why I kept the map in the UI is that I am planning to draw a different line colour to the path where I was at low speed or idling.  Unfortunately, this might not be done in time, as there are still a few more important items to do.  i.e., I want to automate the launching of the app when I put my phone on its holder, this way, I can be sure that I am monitoring my trip each time.  Will give an update about this "feature creep" tomorrow as I am working on it atm.  image

    • 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