% ****** Start of file aipsamp.tex ****** % % This file is part of the AIP files in the AIP distribution for REVTeX 4. % Version 4.1 of REVTeX, October 2009 % % Copyright (c) 2009 American Institute of Physics. % % See the AIP README file for restrictions and more information. % % TeX'ing this file requires that you have AMS-LaTeX 2.0 installed % as well as the rest of the prerequisites for REVTeX 4.1 % % It also requires running BibTeX. The commands are as follows: % % 1) latex aipsamp % 2) bibtex aipsamp % 3) latex aipsamp % 4) latex aipsamp % % Use this file as a source of example code for your aip document. % Use the file aiptemplate.tex as a template for your document. \documentclass[% aip, %jmp,% %bmf,% sd,% %rsi,% amsmath,amssymb, %preprint,% reprint,% %author-year,% author-numerical,% twoside ]{revtex4-1} \usepackage{graphicx}% Include figure files \usepackage{subfig} \usepackage{subcaption} \usepackage{dcolumn}% Align table columns on decimal point \usepackage{bm}% bold math \usepackage[mathlines]{lineno}% Enable numbering of text and display math %\linenumbers\relax % Commence numbering lines \usepackage{hyperref} \usepackage{fancyhdr} \usepackage{appendix} \usepackage{ifthen} \pagestyle{fancy} \fancyhf{} \lhead{\textit{{Smartphone ambient light sensor as a revolution counter}} \fancyfoot[RO]{\textit{\small{McMaster Journal of Engineering Physics}, 2017, \bf{[vol]}, \thepage}} \fancyfoot[LE]{\textit{\small{McMaster Journal of Engineering Physics}, 2017, \bf{[vol]}, \thepage}} \renewcommand{\footrulewidth}{0.4pt} %\fancyfoot{\ifthenelse{\value{page}=1}{\small{\textit{McMaster Journal of Engineering Physics}, 2016, \bf{[vol]}, \thepage}}} \begin{document} \preprint{AIP/123-QED} \title[{Ambient light sensor revolution counter}]{Feasibility of a smartphone ambient light sensor as a revolution counter} \author{K. Van Vliet} %only include a), b) etc if there are footnotes on the authors (see section III.3 Footnotes, and Notes and References at end \affiliation{ McMaster University, 1280 Main Street West, Hamilton, Canada. %\\This line break forced with \textbackslash\textbackslash } \date{\textbf{\today}}% It is always \today, today, % but any date may be explicitly specified \begin{abstract} This paper explores the use of the ambient light sensor on an LG G3 smartphone as a tachometer. A method of detemining the RPM of a rotating chopper using variation in light intensity is presented and the accuracy of the results are examined under different lighting conditions and different distances between chopper blade and the sensor. The response time of the ambient light sensor is determined to be between 0.03 and 0.04s. The response time is used to determine the width of the chopper required to accurately determine the RPM of a bicycle wheel travelling 20km/h using the smartphone ambient light sensor system. \end{abstract} \pacs{Valid PACS appear here}% PACS, the Physics and Astronomy % Classification Scheme. \keywords{Suggested keywords}%Use showkeys class option if keyword %display desired \maketitle \thispagestyle{fancy} \section{\label{sec:level1}INTRODUCTION} In this paper the feasibility of using the ambient light sensor on an LG G3 smartphone as tachometer is examined. The method for determining revolution speed from the light intensity data is presented and the accuracy of the ambient light sensor method is compared to an existing laser photo tachometer. The range of revolution speeds that can be measured is analysed to determine if the smartphone ambient light sensor could be used in common applications such as a kilometer counting or spedometer for a bicycle. Due to advances in photoconductor technology, ambient light sensors are becoming increasingly popular in smartphones and other consumer electronics.\cite{1} The most common application of the ambient light sensors is auto-brightness control on LCD screens which uses the intensity of ambient light that is measured to adjust screen brightness to an ideal level for the user.\cite{2} In addition to this in-phone application, it has been demonstrated that the information from the ambient light sensors on smartphones can be easily extracted for use in other applications outside of the smartphone functionality as well. Educators are recognizing the value of smartphone ambient light sensors as tools to engage students. \cite{3} \cite{4} In his paper, Fu describes a design of a device that uses the smartphone ambient light sensor to determine the concentration of biomarker analytes in a nanosubstrate. \cite{5} The availability of smartphones and the easily extractable data from smartphone sensors has led to innovation that broadens the scope of their applications to extend as far as medical diagnostic testing. One application of the ambient light sensors on smartphones that seems undeveloped, is an optical rotary encoder or RPM counter. If RPM information could be determined using a smart phone ambient light sensor, more applications such as kilometer counters and spedometers become feasible as well. Unfortunately, very little information is available to smartphone users about the characteristics of the onboard ambient light sensor. For measuring RPM, the most critical characteristic of the sensor is the response time of the photodetector as it will determine the maximum RPM count that can be accurately measured. \section{\label{sec:level1} Experimental} A chopper attached to a DC motor was used to block light infront of the ambient light sensor on an LG G3 smartphone. The motor was controlled using a Raspberry Pi and a LS293D motor driver. By pulse width modulating the power from a 9V battery, the speed of the chopper was varied. The intensity of light entering the ambient light sensor was measured and recorded using the Physics Toolbox Light Sensor app available for free on Android smartphones. First, a 6cm wide chopper was positioned 0.5 centimeters away from the smartphone sensor in a dark room. A lamp was placed 60 cm infront of the phone and directed at the sensor, light intensity data was collected at varied chopper speeds. Further testing with the 6cm chopper blade was performed by changing the lighting conditions in the room to a bright room (room light intensity = 75lux) with a lamp 60 cm away from the sensor, followed by a bright room without the direct light source. The distance between the chopper and the sensor was also varied to 1cm and 5cm. The width of the chopper was then reduced to 2.5cm to investigate the response time of the sensor. The 2.5cm wide chopper was again placed 0.5cm from the sensor in a dark room with a single light source directed toward the sensor. All of the results from the smartphone ambient light sensor were compared to a Cybertek Laser Photo Tachometer. \section{\label{sec:theor} Basic Theory} The relationship between the speed of the chopper in RPM and the light intensity data measured by the ambient light sensor on the LG G3 cell phone can be determined by counting the light intensity peaks in a specified time interval. The relationship is shown in Equation \ref{eq:eq1} where $n_{peaks}$ is the number of light intensity peaks, $t_f$ is the time at which the final peak occurred and $t_i$ is the time at which the first light intensity peak occurred in seconds. \begin{equation} \\Chopper~ Speed~ in~ RPM = \frac{n_{peaks} -1}{t_f-t_i} \times 60 s\label{eq:eq1} \end{equation} The chopper speed in RPM can be related to the angular velocity of the chopper, $\omega$ and the linear velocity, $v$, by the Equations \ref{eq:eq2} and \ref{eq:eq3} where $r$ is the radius of the chopper at the point which it passes the ambient light sensor. \begin{eqnarray} \omega = \frac{Chopper~ Speed~ in~ RPM}{60seconds} \times 2\pi \frac{rads}{rev} ~~~ (\frac{rads}{s} )\label{eq:eq2} \\ v = \omega \times r ~~~ (\frac{cm}{s})\label{eq:eq3} \end{eqnarray} From the linear velocity and the width of chopper blade, the length of time that light is blocked from entering the sensor is found using the relation in Equation \ref{eq:eq4}. \begin{eqnarray} t_{c} = \frac{width_{chopper}}{v}\label{eq:eq4} \end{eqnarray} Ambient light sensors are made from either photodiodes (or phototransistors, which are photodiodes with internal gain) that have high responsivity under ambient light. \cite{7} A characteristics of all of these light detecting technologies is the response time (or rise time) of the sensor which is the time it takes the sensor to change from 10$\%$ to 90$\%$ of its maximum value. \cite{8} Abrupt changes in light intesity which occur quicker than the response time will be unnoticed by the sensor and cannot be measured. The response time of a sensor is determined by the mobility of charge carriers within the semiconductor materials of the detector and the RC (resisive-capacitive) effects of the detector and its associated circuit.\cite{9} \section{\label{sec:res} Results and Discussion} Table \ref{tab:tab1} shows the speed of the 6cm chopper determined using the LG G3 ambient light sensor method and then compared to the laser tachometer. The value tabulated is the mean value of three trials performed using the LG G3 ambient light sensor and is accompanied by the standard deviation. The percentage error between the chopper speed determined using the LG G3 and the chopper speed measured with the laser tachometer is less than one percent for all cases indicating that the results agree well. The results are plotted in Figure\ref{fig:fig1} where we can easily see that the laser tachometer RPM and the LG G3 RPM agree within the standard deviation (shown as error bars on the graph in Figure\ref{fig:fig1}) of the measured at all chopper speeds. The light intensity data measured using the 6cm chopper blade can be seen in Figure \ref{sub:sub1} and \ref{sub:sub2} with the motor at 20\% PWM and 80\% PWM. Because of the rotation chopper which blocks the ambient light sensor, it is expected that a near zero light intensity will be measured once per rotation. However, at the faster motor speed, in Figure \ref{sub:sub2}, some of the light intensity minima are not near zero. Fortunately, this does not affect the RPM results extracted from the data unless there is no light intensity decrease detected in a rotation, because then the number of light intensity peaks will be less than expected. \begin{figure}% \includegraphics{Fig1} \caption{ Chopper speed measured by LG G3 ambient light sensor method and by the laser tachometer for the 6cm chopper width} \label{fig:fig1} \end{figure} \begin{table} \caption{\label{tab:tab1}Chopper speed measured with smartphone ambient light sensor and optical laser tachometer for 6cm chopper width positioned 0.5cm from the ALS} \begin{tabular}{c|cc|c|c} \hline &\multicolumn{3}{c|}{$Measured ~ Chopper ~Speed~ (RPM)$}&\\ PWM&~~~~LG G3~~~~&StDev&Optical Tachometer&Percent Error\\ \hline \hline 20&89.17&0.51&89.3&0.15\\ 30&113.89&0.53&114.3&0.36\\ 40&135.51&0.60&136.6&0.80\\ 50&146.70&0.40&148.1&0.94\\ 60&156.77&1.07&156.0&0.50\\ 70&158.32&1.00&158.1&0.14\\ 80&161.89&1.02&161.7&0.12\\ \hline \end{tabular} \end{table} % Table generated by Excel2LaTeX from sheet 'Sheet1' \begin{table*} \centering \caption{RPM results for different lighting conditions and distances between the chopper blade and the sensor} \label{tab:tab2} \begin{tabular}{c|c|c|c|c} \hline Lighting Condition & \multicolumn{1}{c|}{Chopper Distance (cm)} & \multicolumn{1}{c|}{Measured Chopper Speed (RPM)} & \multicolumn{1}{c|}{StDev (RPM)} & \multicolumn{1}{c}{Percent Error} \\ \hline \hline \multirow{Lamp Light} & \multicolumn{1}{c|}{0.5} & 161.89 & 1.02 & 0.12 \\ & \multicolumn{1}{c|}{1} & 161.95 & 1.12 & 0.15 \\ & \multicolumn{1}{c|}{5} & 162.17 & 1.67 & 0.29 \\ & Laser Tachometer & 161.7 & - & - \\ \hline \multirow{Bright Room with Lamp} & \multicolumn{1}{c|}{0.5} & 158.38 & 2.67 & 1.75 \\ & \multicolumn{1}{c|}{1} & 157.20 & 1.98 & 2.48 \\ & \multicolumn{1}{c|}{5} & 154.52 & 3.73 & 4.14 \\ & Laser Tachometer & 161.20 & - &- \\ \hline \multirow{Bright Room} & \multicolumn{1}{c|}{0.5} & 159.54 & 1.66 & 1.52 \\ & \multicolumn{1}{c|}{1} & 157.99 & 2.12 & 2.47 \\ & \multicolumn{1}{c|}{5} & 155.34 & 3.60 & 4.11 \\ & Laser Tachometer & 162.0 & - &- \\ \hline \end{tabular}% \label{tab:addlabel}% \end{table}% \begin{figure} \subfloat[PWM=20]{\includegraphics[width=.22\textwidth]{Fig2}\label{sub:sub1}}\quad \subfloat[PWM=80]{\includegraphics[width=.22\textwidth]{Fig3}\label{sub:sub2}}\\ \subfloat[PWM=20]{\includegraphics[width=.22\textwidth]{Fig4}\label{sub:sub3}}\quad \subfloat[PWM=80]{\includegraphics[width=.22\textwidth]{Fig5}\label{sub:sub4}} \captionsetup{labelfont=bf,textfont=normalfont,singlelinecheck=off,justification=raggedright} \caption{Light intensity data collected using the 6cm chopper blade 0.5cm away from the sensor with (a) (b) dark room and lamp light, (c)(d)bright room} \label{fig:fig2} \end{figure} Less direct lighting conditions and a larger distance between the sensor and the chopper blade further test the robustness of the ambient light sensor tachometer system. The results for these conditions are shown in Table \ref{tab:tab2} and are plotted in Figure\ref{fig:fig3}. It is obvious from the graphs shown in Figure\ref{fig:fig3} that only the direct lamp light condition (a dark room with light from one lamp directed at the sensor) agrees with the speed measured by the tachometer within the errorbars. However, the percent error between the LG G3 determined RPM values and the laser tachometer measured values is below 5 percent for all the measurements measurements made regardless of the lighing conditions or distance between the chopper and the sensor. When the experiment was run with the more diffused lighting conditions, the presence of a direct light source (the lamp) did not show a significant influence on the results. The two sets of results which were obtained in a bright room (with and without the lamp) show very similar percent errors which increase to just under five percent as the distance between the chopper blade and the sensor increases. This trend is not observed when only the direct lamp light is present; the percent error remains under one percent for all of the chopper blade distances. \begin{figure} \includegraphics{Fig6} \caption{Chopper speed measurements at different lighting conditions and distances between the chopper blade and the sensor} \label{fig:fig3} \end{figure} When the blade width of the chopper was reduced to 2.5cm the range of speeds that could be determined using the LG G3 smartphone became very limited. In Table \ref{tab:tab3} it becomes obvious that the ambient light sensor could not accurately recorded the changes in light intensity with speeds higher than ~80RPM because the percent error compared to the laser tachometer became greater than fifty percent. From this we can see that the length of time that the chopper blade is blocking light into the sensor has been reduced to below the response time of the ambient light sensor system within the smartphone. This becomes even more obvious from the lack of periodicity in the light intensity measured by the LG G3 shown in Figure \ref{fig:fig4}. \begin{table} \caption{\label{tab:tab3}Chopper speed measured with smartphone ambient light sensor and optical laser tachometer for 2.5cm chopper width positioned 0.5cm from the ALS} \begin{tabular}{c|c|c|c} \hline &\multicolumn{2}{c|}{$Measured ~ Chopper ~ Speed ~ (RPM)$}&\\ PWM&~~~~LG G3~~~~&Optical Tachometer&Percent Error\\ \hline \hline 20&82.09&83.21&1.33 \\ 30&43.70&112.34&61.08 \\ 40&53.77&130.12&58.64 \\ 50&69.22&146.20&52.65 \\ \hline \end{tabular} \end{table} Since 82.09 RPM was the highest chopper speed measured using the LG G3 ambient light sensor that agreed with the reading from the laser tachometer, this speed can be used to determine the upper limit of the response time of the ambient light sensor. \begin{eqnarray} v = \frac{83.21 rev}{60s} \times 2\pi \frac{rad}{rev}} \times 7cm = 60.18 \frac{cm}{s} & \\t_{c~83RPM} = \frac{2.5 cm}{60.18\frac{cm}{s}} = 0.04s & \end{eqnarray} \begin{figure} \includegraphics{Fig7} \caption{Light intensity data collected with 2.5cm chopper blade running at 112RPM (PWM=30\%)} \label{fig:fig4} \end{figure} It is obvious from Table \ref{tab:tab3} that the time in which the chopper blade was blocking the light into the sensor was reduced below the response time of the sensor somewhere between the 20 percent and 30 percent PWM (83 and 112 RPM) of the motor. The amount of time the sensor was blocked for in the when the motor was running at 30 percent PWM is calculated in Equations 4 and 5 and can be used as the lower limit of the response time of the ambient light sensor in the LG G3 smartphone. \begin{eqnarray} v = \frac{112.34 rev}{60s} \times 2\pi \frac{rad}{rev}} \times 7cm = 82.34 \frac{cm}{s} & \\t_{c~112RPM} = \frac{2.5 cm}{82.34\frac{cm}{s}} = 0.03s & \end{eqnarray} Thus we can state that the response time of the ambient light sensor falls within the range \begin{equation} 0.03s