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 #11 - Module 2 and 3 [Completed]
  • 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: 8 Nov 2017 4:26 AM Date Created
  • Views 895 views
  • Likes 2 likes
  • Comments 2 comments
  • iot on wheels design challenge
  • iot on wheels
  • arduino_projects
  • ard_expert
  • trafficpredictor
Related
Recommended

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

dixonselvan
dixonselvan
8 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 completed modules 2 & 3. Please have a glance at my previous blog Traffic Predictor #10 - Evading traffic like a Bat for a better understanding of the progress.

Module 2 - Auto-pilot mode with predefined speed

 

Module 3 - Speed adjustment with correspondence to current vehicular movement and real-time traffic

Video - Device in action

     Below is the video where I will be explaining the entire setup shortly [Hardware explained video - Click Here] and the working of the kit in detail. The output/ outcome of these modules is the location of the obstacle(traffic) in front of the driver. This will be fed to the mobile app which will handle the rest of the processing. The final output will be posted during the integration part which will be the final blog for my trafficpredictor project. The mobile app will display the below data

  • Module 2 - Static speed output from predicted route [From ML Data]
  • Module 3 - Dynamic speed output from real-time traffic [From Hardware]

 

     The output of this current working hardware will be a serial output through Bluetooth to the mobile device. Where the app will capture it to display to the user in a formatted way. The communication data will be like

     (Location of Servo, Location of Obstacle)

 

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

 

Circuit Diagram

     Below is the circuit diagram of the entire hardware in my trafficpredictor project[designed using Fritzing I have also mentioned the pin in the different modules adjacent to their connection in Nucleo-L476RG board in the table below the circuit diagram

image

Part NamePart PinNucleo L476RG board Pin
Bluetooth moduleVcc5V
GndGnd
TXCN3 TX
RXCN3 RX
Servo MotorPulseD3 (PWM)
Vcc5V - Arduino Uno
GndGnd - Arduino Uno
Ultrasonic SensorVcc5V
GndGnd
TRIGD5
ECHOD2

 

Code to program Nucleo-L476RG board(Arduino compatible  Updated

I have pasted the entire code used for programming the Nucleo-L476RG board below You can also find the below code in my GitHub repository Click Here.

 

/*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
 */     
#include 


//Servo variables and constants
Servo myservo;
int pos = 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();
}


void servoRotate()
{
  //Servo rotate from 0 to 180
  for(pos = 0; pos <= 180; pos += 2){
    myservo.write(pos);
    delay(10);
    
    distance = calculateDistance();
    
    //Send Data in the format -> (position, distance)
    Serial.print(pos);
    Serial.print(",");
    Serial.print(distance);
    Serial.println();
  }


  //Servo rotate from 180 to 0
  for(pos = 180; pos >= 0; pos -= 2){
    myservo.write(pos);
    delay(10);
    distance = calculateDistance();
    Serial.print(pos);
    Serial.print(",");
    Serial.print(distance);
    Serial.println();
  }
}


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;
}

 

Hurdle

I faced trouble making the Bluetooth module communicate serially by obtaining data from D0 and D1 Serial pins in the Nucleo-L476RG board Luckily I found these articles https://os.mbed.com/teams/ST/wiki/Use-of-D0D1-Arduino-pins and known limitations - https://os.mbed.com/platforms/ST-Nucleo-L476RG/ which explained why D0 and D1 have been disabled for serial communication and gave the alternative which was CN3 TX and RX.

 

 

Progress made so far,

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||   80%

{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]

Module 2 & 3

Traffic Predictor #10 - Evading traffic like a Bat

IntegrationYet to Begin
Revisions and Hardware, Software ListTraffic Predictor #9 - Revisions and Hardware, Software list

image

  • Sign in to reply

Top Comments

  • DAB
    DAB over 7 years ago +1
    Very nice update and video. DAB
Parents
  • DAB
    DAB over 7 years ago

    Very nice update and video.

     

    DAB

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

    Very nice update and video.

     

    DAB

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

    Thanks DAB image

    • Cancel
    • Vote Up 0 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