With Yousef Abdo

What is this weeks challenge???🤔

So this week we want to have an interactive animal. We want to use a light sensor and have it respond to different amount of lights to account for someone approaching and moving away from it. But…. it has to be trainable.

What do we mean by trainable?

Well different rooms will have different brightness levels so we need a way to take in what the range will be in the user’s scenario

Let’s get started

<aside> 💡 We had to figure out how to get reading from Light Sensor

</aside>

We were able to get the circuit right and used the light sensor and resistor to set it to one of our input pins and run this code to get values

import machine
import time

adc_pin = machine.Pin(28) # we need to set it to the pin itsplugged in
adc = machine.ADC(adc_pin)

while True:
    reading = adc.read_u16()     
    print("ADC: ",reading)
    time.sleep_ms(500)

IMG_0927.jpeg

Next… How do we convert Light Values to positions for motor?

When we get a reading we can simply take its position from our range:

$$ (input - minimum)/ range $$

We essentially turned the question into a simple math problem and we get numbers ranging from 0-180

Here is the GitHub to our full code:

Motor-Dance/Hunt Hoot Smarts at e22054b14ee1a7050ba6429eb74f6f03ddf71f28 · marcjm/Motor-Dance

IMG_0932.jpeg

Now for the Fun Part Meshing Software and Hardware