File Exchange

image thumbnail

Analyzing Traffic Using a Webcam, a Raspberry Pi and ThingSpeak

Develop a traffic monitoring algorithm and analyze traffic data sent to ThingSpeak

5 Ratings



View License

In this IoT project, we use a Raspberry Pi, a web cam and ThingSpeak to analyze traffic on a busy highway. With Simulink we design and deploy a traffic monitoring algorithm to the Raspberry Pi, and we analyze and visualize the traffic patterns using ThingSpeak, an IoT analytics platform, and MATLAB. This article features channel 38629 on ThingSpeak.
For more information about ThingSpeak, see

Comments and Ratings (16)

When I run the m file getting following error but graph appears for Traffic Density for the week starting at a particular day.

Error using reshape
Product of known dimensions, 5655, not divisible into total number of elements, 39586.

Error in traffic_analysis_final_updated_old (line 176)
dailymeaneast = mean(reshape(eastTraffic, floor(length(alltrafficData)/7),[]));

Thanks a lot M.Khan.Its working.


M.Khan (view profile)

SDL Video Display and FinalOutput are for debugging purpose only. To view these two displays, you need to enable the subsystem 'raspberrypi_viptrafficfd3_Density/Car Density/Enabled Subsystem'. To enable this subsystem, double click on the block 'raspberrypi_viptrafficfd3_Density/Car Density/Debug Flag' and set the Constant Value to 1. Redeploy the generated code and it should display the outputs.

Thanks for including model. when I run the model on Raspberrypi I am not getting the SDL video display output and the final output..but get the camera output.Please help.

Hans Scharler

Thanks for including the model!

has anyone re-created this model or received the original to run the experiment??

hello sir, can you ad simulink model please?

how to get the total no of vehicles

Neven Lazarov

You forgot to include the model



Where is the simulink model?


Omar Madrigal

please add the model


+1 on looking for the missing model

saeed amindin

the model missing. please add a new file with model for downloading.

where can I find this model ,I'm very intereted in this project!


Mikhail (view profile)

It seems that you've forgotten to share the Simulink model used for car detection.



Updated traffic monitoring algorithm and added Simulink model to the submission.

Updated description.

Updated license


Initial release.

MATLAB Release
MATLAB 8.5 (R2015a)

More Files in the  Maker Community

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video