Now that the Components are set up, it's time to make them do stuff using Actions.
Each Action will tell the QT Py to perform one function. There is a lot you can do with actions, mostly things like:
- Turn your relay onÂ
- Turn your relay off
- Read data from the PIR sensor
- Turn your NeoPixel strip on in a specific color
To plan out actions, break down exactly what you want the setup to do.
Action Plan
- When the PIR sensor gets triggered, turn on Relay (start button)
- When the PIR sensor gets triggered, turn on the NeoPixels in red
- When the PIR sensor resets, turn off Relay and turn on Relay 2 (stop button)
- When the PIR sensor resets, turn off the NeoPixels
- After 10 seconds, turn off Relay 2
This covers my basic actions. Adafruit IO has 3 different kind of actions we can pick from: Reactive, Scheduled, or Timer.Â
Reactive:
- if (component) is in a certain state, then do (x).Â
Timed:Â
- if (component) is in a certain state, then do (x) after a set amount of time
You can also use Scheduled actions, where something happens at a specific time of day, so you can turn your project off when it's time for trick-or-treaters to go to bed.Â
Action Setup
Click "Create Action" next to the component you want to activate. Adafruit IO will ask if you want to use dropdowns or Blockly. Play around with both! For this guide I'll show the process using the dropdowns.
Choose your component in the first dropdown. The second line checks the state: enter 1 for on, or 0 for off for the relays and sensors.Â
Choose "publish a message to:" in the next dropdown and select your target component under "feed". The "with" box will change the state of whatever is in the "feed" box.
For the NeoPixel strip things work mostly the same, only instead of giving a 1 or a 0 in the "with" box, put a hex code indicating the color you'd like to see. I wanted red, so I entered #FF0000.Â
To turn the pixels back off, use a hex code of black: #000000
Tweaking the User Experience
These relays and switches are also not 100% reliable -- they sometimes get a little confused and don't turn off. After some testing and playing around, I ended up adding a few more actions as a failsafe, turning the relays and lights to "off" after a set amount of time with no triggers, so that the smoke or lights never get stuck in an "on" state.Â
Adafruit IO is still in beta at the time of writing, and doesn't have a lot of options for timing. We can choose to schedule our actions after 10 seconds or a minute, or much longer. I want smoke for just 3-4 seconds.Â
Our PIR sensor can help us out here. It has two screws on the side. One of them controls the sensor's sensitivity, and the other controls the amount of time that elapses before the sensor resets after it's been triggered. By creating Reactive actions based on the reset time of the PIR sensor (i.e. When the PIR sensor's state resets to 0, do "x") we get a little more control over the trigger time. Just turn your screw to adjust.
Here is my final setup, with fail-safe actions included.Â
Page last edited October 02, 2024
Text editor powered by tinymce.