Day 24: Gift box
With the last test in this Advent, we get really Christmasy. We’re building a reusable gift box with which you can delight your relatives. Every time someone opens the present, the contents are lit up in an individual colour, and a Christmas sound plays.
Behind today’s door is a retro-reflective sensor. This is actually two components, an IR transmitter diode and a phototransistor. It’s not very easy to see which way the elements have to be connected in terms of polarity. For this reason, it’s best if you connect the photoelectric sensor with the connection cables according to the example shown. Then you won’t be able to switch the polarity as easily.
Today’s layout contains many components, so it all looks a bit confusing at first glance. In addition to the retro-reflective sensor, which serves as a sensor to detect the opening of the package, the RGB LED and the piezo sound transducer are used.
After you have loaded today’s programme on the controller, go once more to the http://www.hivemq.com/try-out/ site and connect to the broker broker.fkainka.de. Once you’re there, you can now begin to dedicate one topic each to the persons to whom you want to give gifts according to the following model:
where you replace "MyMQTTiD" with your personal ID and "person" with the person to whom you want to give the present. In the topic "color," publish a colour according to the pattern you already know, rgb(X,X,X), and in the topic "song" publish a number between 0 and 5, which stands for a predefined song. Both messages must be equipped with the Retain flag. For three persons, for example, it would look like this:
Now you can switch between these persons by publishing the person in the topic
If you enter "sister" there, for example (pay attention to exact spelling), the settings for your sister are loaded and are used when the box is opened. After the gift has been removed, put the next one in, close the box again and load the next setting by publishing the next person. For test purposes, you can hold the sensor in front of a white sheet of paper, which simulates the closing of the box. The sensor must thereby be shielded from the residual daylight. When you take the paper away, the box is recognised as opened. See the website for instructions on precisely how to build the box.