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
Part Name | Part Pin | Nucleo L476RG board Pin |
---|---|---|
Bluetooth module | Vcc | 5V |
Gnd | Gnd | |
TX | CN3 TX | |
RX | CN3 RX | |
Servo Motor | Pulse | D3 (PWM) |
Vcc | 5V - Arduino Uno | |
Gnd | Gnd - Arduino Uno | |
Ultrasonic Sensor | Vcc | 5V |
Gnd | Gnd | |
TRIG | D5 | |
ECHO | D2 |
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 Label | Tab Content |
---|---|
Entry & Introduction | IoT on Wheels Design Challenge - Traffic predictor and auto pilot mode |
Plan | Traffic Predictor #3 - The Plan |
Initial Setup | |
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 | |
Integration | Yet to Begin |
Revisions and Hardware, Software List | Traffic Predictor #9 - Revisions and Hardware, Software list |
Top Comments