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.
Today's Weather from Google
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.
Links to all blogs posted for my trafficpredictor project are given below,
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 100%
{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] Traffic Predictor #12 - Predicting the best route to avoid traffic [Part 2 of 2] |
Module 2 & 3 | |
Integration | This blog |
Revisions and Hardware, Software List | Traffic Predictor #9 - Revisions and Hardware, Software list |
Top Comments