Michael BrucatoDarrell W.
Published

Sensory Intervention Project: The Mystery Box

A Box to test your intuition and engage you to complete various tasks by figuring out what sensors have been installed

BeginnerFull instructions provided4 hours32
Sensory Intervention Project: The Mystery Box

Things used in this project

Hardware components

Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Circuit Playground Express
Adafruit Circuit Playground Express
×3
Alligator Clips
Alligator Clips
×4
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
Resistor 10k ohm
Resistor 10k ohm
×2

Software apps and online services

MakeCode
Microsoft MakeCode

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Box, General Purpose
Box, General Purpose

Story

Read more

Code

Remote.uf2

Arduino
This code is responsible for sensing when a task is complete or when a sensor has been activated. Once all the sensors have been interacted with or activated, the "remote" will turn all its neo-pixels blue
network.onInfraredReceivedNumber(function (found_id) {
    if (found_id == Source_1) {
        light.setPixelColor(Source_1, 0x00ff00)
        found_1 = true
    }
    if (found_id == Source_2) {
        light.setPixelColor(Source_2, 0x00ff00)
        found_2 = true
    }
    if (found_id == Source_3) {
        light.setPixelColor(Source_2, 0x00ff00)
        found_3 = true
    }
    if (found_id == Source_4) {
        light.setPixelColor(Source_4, 0x00ff00)
        found_4 = true
    }
})
let found_4 = false
let found_3 = false
let found_2 = false
let found_1 = false
let Source_4 = 0
let Source_3 = 0
let Source_2 = 0
let Source_1 = 0
Source_1 = 1
Source_2 = 2
Source_3 = 3
Source_4 = 4
found_1 = false
found_2 = false
found_3 = false
found_4 = false
light.clear()
forever(function () {
    if (found_1 && found_2 && (found_3 && found_4)) {
        music.playSound(music.sounds(Sounds.BaDing))
        while (true) {
            light.showRing(
            `blue blue blue blue blue blue blue blue blue blue`
            )
            pause(200)
        }
    }
})

Module 1.uf2

Arduino
Responsible for sending out various infrared signals after interacting with the various sensors installed in the Circuit playground express
let shake_v = 0
let sound_v = 0
let light_v = 0
input.onGesture(Gesture.Shake, function () {
    shake_v += 1
})
input.onLoudSound(function () {
    sound_v += 1
})
input.onLightConditionChanged(LightCondition.Bright, function () {
    light_v += 1
})
forever(function () {
    pause(500)
    light.setAll(0xff0000)
    if (shake_v >= 1) {
        network.infraredSendNumber(1)
        light.setPixelColor(0, 0x00ff00)
    }
    if (sound_v >= 1) {
        network.infraredSendNumber(2)
        light.setPixelColor(4, 0x00ff00)
    }
    if (light_v >= 1) {
        network.infraredSendNumber(3)
        light.setPixelColor(7, 0x00ff00)
    }
    pause(200)
    light.clear()
})

Module 2.uf2

Arduino
Responsible for managing the Ultrasound sensor and sending out a signal once the sensor has been activated
let distance = 0
let ultra_v = 0
forever(function () {
    pins.A2.digitalWrite(false)
    control.waitMicros(2)
    pins.A2.digitalWrite(true)
    control.waitMicros(10)
    pins.A2.digitalWrite(false)
    distance = pins.A1.pulseIn(PulseValue.High) / 58
    if (distance >= 0.25 && distance <= 50) {
        ultra_v += 1
        light.setPixelColor(0, 0x00ff00)
    } else {
        light.clear()
    }
    console.logValue("distancecm", distance)
    pause(100)
    if (ultra_v >= 1) {
        network.infraredSendNumber(4)
        light.setPixelColor(9, 0x00ff00)
    }
    pause(1000)
})

Credits

Michael Brucato
4 projects • 0 followers
Contact
Darrell W.
4 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.