O'Reilly logo

Mastering Internet of Things by Peter Waher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Calculating control output

For this example, we will use a very simple formula to compute the expected control output: we will turn the relay on, if motion is detected when it's dark, which we interpret as when the (ambient) light sensor reports a light of less than 25%. The relay is turned off when there's no motion, or when it's not dark anymore:

if (RecalcOutput && this.motion.HasValue && this.light.HasValue) 
{ 
   bool Output = this.motion.Value && this.light.Value < 25; 
Care must be taken when installing the light sensor, so that it is not affected by, say, a lamp, connected to the relay. The expected output should also have a time component, to avoid intermittent blinking states.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required