# Watch Out!

## Made by Macarena Tabilo

Found in Home Hack

In the past it was believed that watching tv from close could potentially damage your vision or cause health issues due to excessive radiation emissions. Even that has been proved wrong, it is still recommended to teach kids to keep some distance off screens to prevent them from developing eye strain and fatigue in adulthood, once the habit has been formed. Watch out! aims to help educate early TV watchers by indicating when the recommended distance has been reached.

0

This project was initially intended to connect the TV remote control to the distance sensor, so as a kid would get too close to the TV, this would automatically turn off. As a first exercise, I decided to simplify the prototype and create a lighting indicator of proximity, using an IR sensor of short reach (10-80cm). As a person gets closer, the amount of LEDs diminishes.

If having difficulties to watch the video below, go to https://vimeo.com/202300463

0
0
``````// the pin we're reading from
int distance_sensor = A0;
// store the distance value / reading from the sensor
int distance_measure = 0;

const int sampleWindow = 10;

int numPins = 6;
int ledPins[ 6 ] = { D0, D1, D2, D3, D4, D5};

void setup(){

// start serial connection
Serial.begin(9600);

for( int i = 0 ; i < numPins; i++ ){
pinMode(ledPins[ i ], OUTPUT);
}

// Share the value as a distance level
// reading through the cloud
Particle.variable( "distance", &distance_measure, INT );

}

void loop()
{
distance_measure = analogRead( distance_sensor );
//distance_measure = sampleDistance( );
Serial.println( distance_measure );

displayDistanceOnLEDs();

delay( 100 );
}

void displayDistanceOnLEDs(){

int level = 10;

for( int i = 0 ; i < numPins; i++ ){
int led = ledPins[ i ];
int desiredDistance = level * (i+1);
if( distance_measure > desiredDistance ){
digitalWrite( led, HIGH);
}else{
digitalWrite( led, LOW);
}

}

int sampleDistance( )
{
unsigned long startMillis = millis(); // Start of sample window
int highest_sample = 0;
int lowest_sample = 80;
// collect data for 100 mS
while (millis() - startMillis < sampleWindow)
{
int sample = analogRead( distance_sensor );
// invert the range, and convert it to a percent
sample = map( sample, 0, 4095, 1000, 0, );
// now see if the sample is the lowest;

if ( sample > highest_sample ){
highest_sample = sample ;
}
if ( sample < lowest_sample ){
lowest_sample = sample;
}
}
int peakToPeak = highest_sample - lowest_sample;
return peakToPeak;
}``````
Click to Expand