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
IoT on Wheels Design Challenge
  • Challenges & Projects
  • Design Challenges
  • IoT on Wheels Design Challenge
  • More
  • Cancel
IoT on Wheels Design Challenge
Blog Traffic Predictor #13 - Mission accomplished :)
  • 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: dixonselvan
  • Date Created: 12 Nov 2017 3:35 PM Date Created
  • Views 989 views
  • Likes 3 likes
  • Comments 4 comments
  • iot on wheels design challenge
  • iot on wheels
  • arduino_projects
  • trafficpredictor
Related
Recommended

Traffic Predictor #13 - Mission accomplished :)

dixonselvan
dixonselvan
12 Nov 2017

Week 10 - Nov 6 - 12

 

     This will be last week in the design phase of the IoT on Wheels Design Challenge and for my trafficpredictor project. This blog will be a walkthrough of the entire project. The blogs posted over the two months time is at the end of this blog in a categorized format. Check it out if you have missed out any or to better understand the project.

 

     I ventured out on a trip today (rainy at times) with the trafficpredictor alongside and captured it in a video. Check it out in the video below.

image

               Today's Weather from Google

 

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

 

Code to program Nucleo-L476RG board(Arduino compatible

I have posted an updated code used for programming the Nucleo-L476RG board below You can also find the below code in my GitHub repository Click Here. The input to the mobile app will be like (A, T, N) improved from (Location of Servo, Location of Obstacle).

  • A - Alert (Object is near Vehicle - Have to stop)
  • T - Traffic (Object is near Vehicle - traffic)
  • N - Normal (No Object, free to Move)

 

/*This is the code for element14 IoT on wheels design contest traffic predictor project
 * https://www.element14.com/community/community/design-challenges/iot-on-wheels/
 * 
 * Author : Dixon Selvan
 * Date   : November 08, 2017
 * Project: Traffic Predictor and Auto Pilot
 * Website: https://traffic-predictor.000webhostapp.com/
 * 
 * Hardware components
 * -----------------------------------
 1 Nucleo-L476RG microcontroller board 
 * 2. HC-05 Bluetooth module
 * 3. HC-SR04 Ultrasonic Sensor
 * 4. Servo motor
 * 
 Nucleo-L476RG Bluetooth module 
 * ------------------------------------
 *      5V        |         5V
 *      Gnd       |         Gnd
 *      TX        |         CN3 RX
 *      RX        |         CN3 TX
 *      
 * Servo
 * -----
 * Left = 45 degree
 * Mid = 90 degree
 * Right = 135 degree
 * 
 * A (Alert) <= 60
 * T (Traffic) <=75
 * N (Normal) >=90
 */     
#include 


//Servo variables and constants
Servo myservo;
int pos = 0;
int value = 0;
int servoPin = 3;//Nucleo pin D3


//Ultrasonic sensor variables and constants
int trigPin = 5;//Nucleo pin D5
int echoPin = 2;//Nucleo pin D2


//General variables and constants
long duration;
int distance;


void setup() {
  // put your setup code here, to run once:
  pinMode(trigPin, OUTPUT); 
  pinMode(echoPin, INPUT);  


  Serial.begin(38400);//Serial Connection begin
  
  myservo.attach(servoPin);//Attaching servo pin
}


void loop() {
  // put your main code here, to run repeatedly:
  //servoRotate();
  delay(250);
  serialPrint(45);
  delay(250);
  serialPrint(90);
  delay(250);
  serialPrint(135);
  Serial.println();
}


void serialPrint(int pos){
  myservo.write(pos);
  delay(10);
  value = calculateDistance();
  if(pos==45){
    Serial.print(classifiedData(value));
    Serial.print(",");
  }
  else if(pos==90){
    Serial.print(classifiedData(value));
    Serial.print(",");
  }
  else if(pos==135){
    Serial.print(classifiedData(value));
  }
  else{Serial.print('N');Serial.print(",");}
}


char classifiedData(int value){
  char out=' ';
  if((value<=60)&&(value!=0)){out = 'A';}
  else if((value<=90)&&(value>=75)&&(value!=0))
  {
    out = 'T';
  }
  else{out='N';}
  return out;
}


int calculateDistance()
{
  //Code to calculate Distance from Duration
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(1);
  digitalWrite(trigPin, HIGH); 
  delayMicroseconds(1);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance= duration*0.034/2;
  return distance;
}

 

Conclusion

     I am happy to reach the final stage. This trafficpredictor idea sprung when I was stuck in the middle of traffic, thinking what if someone shares me their shortcut(best route to avoid traffic). I have discovered three ways to reach my workplace and wondered which one is the quickest and at what time of the day. These thoughts have now come life!

 

     This is my first Android app project and I am hoping to release this application soon in the Google Play Store after purchasing a web domain and tidying the code a bit more and adding beauty to the look and feel. This is to collect more data which is the heart of machine learning.

 

     Thank you all for your love and support. I once again would like to thank Element14 community, ST Microelectronics and Duratool for providing me a wonderful platform and Nucleo-L476 RG board along with the other expansion boards to learn about Mbed OS and programming the Nucleo boards. I had absolute fun playing with Nucleo board along with the expansion boards. My favorite I would say is the MEMS expansion board IKS01A2 [User Manual] and the below tool Unicleo-GUI for testing it.

 

image

 

 

Links to all blogs posted for my trafficpredictor project are given below,

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||   100%

{tabbedtable} Tab LabelTab Content
Entry & Introduction

IoT on Wheels Design Challenge - Traffic predictor and auto pilot mode

Traffic Predictor #1 - The Official Announcement

PlanTraffic Predictor #3 - The Plan
Initial Setup

Traffic Predictor #2 - Quest for the Code Editor

Traffic Predictor #4 - Finally, the kit arrives

Module 1

Traffic Predictor #5 - Machine Learning and Building a case for the kit

Traffic Predictor #6 - Into the traffic [Part 1 of 2]

Traffic Predictor #7 - Into the traffic [Part 2 of 2]

Traffic Predictor #8 - Predicting the best route to avoid traffic [Part 1 of 2]

Traffic Predictor #12 - Predicting the best route to avoid traffic [Part 2 of 2]

Module 2 & 3

Traffic Predictor #10 - Evading traffic like a Bat

Traffic Predictor #11 - Module 2 and 3 [Completed]

IntegrationThis blog
Revisions and Hardware, Software ListTraffic Predictor #9 - Revisions and Hardware, Software list

image

  • Sign in to reply

Top Comments

  • shantimohan
    shantimohan over 7 years ago +1
    Congratulations! Dixon. Lucky you...All the best...
  • DAB
    DAB over 7 years ago +1
    Very good finish to the project. You did a very good job of planning and execution. Now you need to collect more data and show it working during heavy traffic mode to see if it can find a better route…
  • dixonselvan
    dixonselvan over 7 years ago in reply to DAB

    Thank you DAB

     

    Data collection will take time and more users. Taking the prototype to the next level would be it. Will find an opportunity to post back in element14 once my app is available to everyone online.

     

    You were with me commenting on my blogs all the way through my journey. Thank you once again.

     

    Dixon Selvan

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 7 years ago

    Very good finish to the project.

     

    You did a very good job of planning and execution.

     

    Now you need to collect more data and show it working during heavy traffic mode to see if it can find a better route when things are bad.

     

    Well done.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dixonselvan
    dixonselvan over 7 years ago in reply to shantimohan

    Thank you shantimohan

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shantimohan
    shantimohan over 7 years ago

    Congratulations! Dixon. Lucky you...All the best...

    • 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