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)

 

 

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

Circuit Connection

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

Logo