C.05 Light Sensor

Goal: To incorporate the light sensor into the circuit so that the motor turns one way when the light is detected and another way when no light is detected.

Wiring

I wired the light sensor to the Analog port using this diagram to help me. One side of the LED connects to live and the other side connects, to analogue but through a resistor that is grounded.

fritzing1

This is the main loop of code. It makes use of two functions fwd() and rev() that I wrote in an earlier session. The variable ‘sensor’ takes a reading from the analog port.

Untitled

The last line of this loop prints the value of sensor to the serial monitor, I added this in because I wanted to see the values that shining a torch on the light sensor would throw out. What I found here was unusual…

Untitled2

The serial monitor displayed lines of 1’s regardless of whether I exposed the light sensor to any light and, as a result the motor only rotated forward.

motormoving

I looked online for other examples of serial monitor prints from light sensor. They were returning numbers up to 3 digits long, often in the 700 – 900 range. Something is going wrong somewhere.

screen-shot-2017-02-24-at-11-39-10

Advertisements

Author: Pip Williamson

Pip // Animator & Motion Designer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s