File Exchange

image thumbnail

Creating a Motion Detector using an Arduino, a Photoresistor and MATLAB

version (233 KB) by MathWorks MATLAB Hardware Team
Acquire photoresistor measurements and explore motion detection algorithms


Updated 01 Sep 2016

View Version History

View License

This example illustrates how to measure the light sensitive analog voltage from a photoresistor circuit connected to Pin 0 of an Arduino Uno.
The example then applies three types of calculations in real-time to determine if the current voltage reading signifies motion.
Using a pre-recorded dataset, the data is further processed in MATLAB to categorize the motion.

This example requires the user to first install the MATLAB Support Pacakge for Arduino Hardware which is available here:

For more information on MATLAB support for Arduino, see the following resource page:

Cite As

MathWorks MATLAB Hardware Team (2021). Creating a Motion Detector using an Arduino, a Photoresistor and MATLAB (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (3)


Hi, I might just be reading the code wrong but it looks like you've used a function 'getSlope' on line 93 of the 'Run_Motion_Detector' function. When I try to use this code it throws up an error saying it is an undefined function or variable. Am I missing this function in an update or has it been replaced by a recent update? I'm using 2019b.

Qusay Jalil


volkan aygül

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!