Before we start Day 1: The first steps

advertisement
Before we start
… a few important announcements and notes on successful and stress-free work with the calendar.
Using this manual is only one of two possible approaches to the calendar. The second option is to use the website
www.conrad.de/iot-adventskalender
as a source of information. The two instructions are almost identical in text, but the medium Internet permits an even larger offer of information
that may ease the way to success.
One example for the higher information content is the fact that some additional images could be integrated on the website. A website is not
bound to limitations such as print costs for page number limits and permits multi-layered and colourful design. Some additional articles may
also be helpful for the development and design of own projects.
Another important help is the comment function. Internet of Things is a complex and exciting, as well as multi-dimensional subject. There are
many tripwires on the way to a successful project. It can only be helpful when a problem can be presented to a larger community. Therefore,
the comment function is activated under each article, in which questions can be asked, improvements suggested or other project participants
can be helped with their projects. I hope that this will minimise the irritation of every individual and to keep the fun in the project high even
when things get skewed.
A third benefit of the website can be the surprise factor. The Advent calendar's excitement is that you do not know what is behind the next door.
In a handbook, you usually already see the experiment on the next page, and are "spoiled". The website only shows the current day's chapter
every day. Therefore, here is my advice: Just put this manual away after this chapter and don't get it out again. Instead, go to
www.conrad.de/iot-adventskalender and set a bookmark on your PC, Smartphone or tablet. Then you can read the current day's chapter every
day, wherever you are, e.g. on the train on the way to work, and experiment with the practical part of the day's project later when you have
come home.
All of those who still love a classic manual, will of course stick with this book. It can be quite comfortable not to have to hold a digital device
while you are trying to get a first overview of your current experiment. However, visiting the website is still necessary. You need to download the
current program, after all. You can find it in the respective article under "The Program".
No matter which way you go when working through the calendar: I hope that you will have fun and wish you a happy and exciting preChristmas period.
Yours, Fabian Kainka
Day 1: The first steps
It is the first day of December and thus time to open the first door. Behind the door, you will find the most important part of this calendar: the
Arduino™-compatible NanoESP-board with integrated WLAN module that this calendar is about.
As you can see quite well on the PCB, the board is made up of two components. The left half is an Arduino™-compatible micro controller
system that can be compared to the Arduino™ Nano. The right part is the WLAN module with the designation ESP8266. These two components
communicate via a serial interface generated by software. The Arduino™-side rather acts as the boss, forwarding the commands to the WLAN
module. Some of these commands will already be tried out today on the first day.
The programme
The program of the respective day can be downloaded by going to
www.conrad.de/iot-adventskalender
selecting your language and calling the article for the current project. You will find the download under the headline "The Program". The
Arduino™-software is used as the developing environment. The current version can be found on the website:
arduino.cc
I have worked with Arduino™-versions 1.6.4 – 1.6.5. Older versions may cause problems. For some Linux versions, there is currently only a very
old version. Advice on how to solve this and other problems can be found on the website. In the Arduino™ software, you need to select
Arduino™ Nano as a board and the serial port. Then you can upload the program.
Today's download is a very simple program that does nothing but pass on all data received through the serial hardware interface of the
microcontroller to the ESP controller via a self-defined software interface. The entire thing works in the opposite direction as well. As you can
see in the source text, the two connections of the software interface are pins 11 and 12. They should not be used as GPIO-pins in your own
projects. You also need the SoftwareSerial library. The library is pre-installed in most Arduino™ versions, but if not, you should download it via
the Manager.
After the program has been uploaded, you can start the serial monitor of the Arduino™ interface. Before you can start, two important settings
must be made to the Serial Monitor, i.e. the baud rate must be set to "19200" in the lower right corner and the setting "CR and NL" must be
made in the box to its left.
After setting, you can see a message, i.e. an AT and a few lines, followed by OK. The command AT was sent to the ESP module by the
microcontroller and the module answered OK. You can see by this that the module works and is ready for use.
You can test this again by sending the command
AT
by serial monitor. The uploaded program again passes on the command to the ESP module, which in turn answers OK. The next command that
you can test is:
AT+GMR
This command outputs the current firmware and version number. The command
AT+RST
resets the module. You will see a few illegible characters on the terminal first, followed by ready, which says that the module is now ready. Use
AT+CWMODE
to specify the WLAN mode. There are three options: Mode 1 is the station mode. This means that you can log into a present WLAN in the
module. Mode 2 is the AccessPoint mode. This means that you can log on to a WLAN provided by the module with a WLAN-capable device.
Mode 3 is dual mode. You can both log on to a present WLAN with the module and make a direct connection to another device. Test the
AccessPoint mode by specifying mode 2 with the command
AT+CWMODE = 2
and then using the command
AT+CWSAP=”MyNanoESP”,”MyPassword”,5,3
to set the parameters for the access point. You can then find the network MyNanoESP e.g. with a WLAN-capable computer, and connect with the
password MyPasswort. When the connection has been successfully established, you can use
AT+CWLIF
to display the connected device with IP and MAC address.
The AT commands in the serial monitor
You can now also test station mode by first switching modes with
AT+CWMODE=1
. You can have all available WLAN networks in range with the command
AT+CWLAP
. You can use
AT+CWJAP=“MySSID“,“MyPassword“
to connect to your network, with MySSID and MyPassword being replaced by your network name and your password. It may take quite a while
until the connection is established, but the end will be confirmed with OK. The first connection has now been established.
Day 2: Google Ping
With today's project, you test whether you can reach the Google server. This is used as a test of whether there generally is a connection to the
Internet or, e.g., a firewall is blocking the NanoESP-board.
You will find a plug board behind today's door. The plug board is used as an experimenting platform later, to connect sensors and other
elements. It is best if you plug the controller onto the plug board as shown in the following figure. This leaves you the most space for
experiments, while the WLAN module protrudes over the plug board at the rear. The micro USB cable is then suspended between the contact
sides and will only interfere minimally.
The NanoESP on the plug board
The programme
The example program from the website has mostly automated the processes that you entered manually in the first example. The controller
sends commands to the ESP module in sequence, thus connecting to the WLAN, among others. The differently long time-out times give the
module enough time to answer.
Before the programme can work properly, you need to enter your WLAN data behind the two #defines SSID and PASSWORT right at the
beginning of the programme source code. The module needs access to the Internet to execute its last command. The command
AT+PING
pings other devices in the network. Pinging means a request of whether an address can generally be reached. Here, the Google server is pinged
with AT+PING=“www.google.de“. When a response returns, a success message appears in the serial monitor and the LED labelled D3 that is
connected to Pin D13 at the board is activated. The first communication with the Internet is successful.
Day 3: UDP-Send
In today's project, data are exchanged between the board and the PC through the WLAN for the first time. The prerequisite for this is that your
computer has a WLAN adapter. The UDP (User Datagram Protocol) is used. Another program on the PC-side ensures successful receipt of the
messages.
Behind the third door of the calendar, you can find an insulated cable that you will need to build circuits. To prepare for later experiments, you
can place the supply lines ground and VCC on the outer tracks.
The programme
When you load the program onto the controller, the controller is configured as an access point and you should see an open network called
NanoESP. Before connecting to the network, first download another program from the Internet. In my experiments, I used the programme Packet Sender by Dan Nagle which you can download from the following link:
https://packetsender.com/
After loading and installing the program, you can connect your PC to the open network of the NanoESP. Ensure that the firewall recognises the
network as a home network, to avoid blocking data. Your computer should now have the IP 192.168.4.2. You can check this by sending the
command
AT+CWLIF
to the module via the serial monitor. This command shows all computers connected to the access point with IP and MAC addresses.
Start the program Packet Sender; set the UDP server port to 90 in Settings->Network and click the check box "Enable UDP Server". Usually, the
lower left should say UDP:90. If it does not, you need to restart the software once.
The program on the computer is now used as UDP server, while the controller is set as UDP client. The differentiation between client and server
is not clear in the UDP protocol, but in this case it means that you will send data from your controller to the computer.
To send data, use the command:
AT+CIPSEND=7.
The 7 means the number of characters to be sent. The character > is returned. This means that you can now send your message. Enter Hello and
confirm with Enter again. The module returns SEND OK, although you have only entered five characters. This is because after your input
Carriage Return and New Line are sent as well, i.e. two characters more that you need to include in your message length calculation.
When you switch back to the Packet Sender and look at Log Traffic there, you can see the receipt of the message. In the ASCII view, you will
even see the two enclosed characters, represented by \r and \n. Therefore the first communication between board and PC via the WLAN has
been successful.
Day 4: UDP bidirectional
In yesterday's project, the UDP communication was tested in one direction, i.e. from the board to the PC. In this program, the module is set so
that communication in the other direction is possible as well, almost like in a chat.
Behind the fourth door of the Advent calendar, there is a resistor with 1 kΩ (brown, black, red). The component is not used in today's test yet,
but should be kept for later.
The programme
Today's program generally only contains a very small change that has a great effect on the communication with the UDP protocol. When you
upload the program, another access point with which you can connect to a PC is generated. Again, you will need Packet Sender or a comparable
program. Start the program and make the same settings as yesterday (File-> Settings->Network: Enable UDP Server, Port 90). Then you need to
enter the address of the module (192.168.4.1) in the main window in the IP address field, set the port to 91 and select the item UDP in the
dropdown menu farther to the right. When these settings have been made and the serial monitor has been opened, you can send the first
message to the module by entering, e.g., Hi in the field labelled with ASCII.
If you click Send now, the Serial Monitor will show
+IPD,2:Hi
OK
The message has been received. You can now also answer, by using the CIPSEND command again, e.g.
AT+CIPSEND=7.
>Hello
Chatting with two devices is possible, though very impractical.
Day 5: Switching an LED
Today's programme is finally about controlling hardware via the UDP protocol. In this case, an LED is switched on and off with simple
commands.
You will find an LED board behind the fifth door. The right dropping resistor already was in yesterday's door. Build the circuit as the picture
shows.
The programme
While the previous example programs needed many user inputs, today's program is to work autonomously. Nevertheless, the serial monitor will
continue to output information for debugging purposes.
The controller will now wait for data received from the module that are announced by the +IPD message. Legitimate commands that you can
send through the Packet Sender are led1 and led0. The controller interprets them and switches the LED on and off accordingly. Feedback to the
transmitter is transmitted as well. If another command is sent, the serial monitor reports "Wrong UDP Command". The same message is also
submitted to the transmitter via the network.
Day 6: UDP-Button
In yesterday's program, the first commands were evaluated by the controller. Today's program maintains this function but can also additionally
send a command into the network independently.
You will find a button behind today's door. It is used as a simple sensor here. Connect it to the controller as shown in the setup image.
The programme
The program continues to evaluate the incoming signals. Additionally, the button is continually queried. When the user actuates it, the controller
sends the text
Button=1
to the network. All devices connected to the module with a UDP server on port 90 can receive the command. For a building automation project,
a server would receive the status message, e.g. of a motion sensor, and then reset the command led=1 to activate the light.
Day 7: Analogous sensor
In the last project, a button was used to deal with the simplest form of a sensor. This time, a potentiometer should be used as an analogue
sensor to permanently send measured values into the network.
Behind the 7th door of the advent calendar, there is a potentiometer with 10 kΩ. The setup is shown in the lower figure.
The programme
In addition to the analogue sensor, there is another change to the programme. This time, the controller is not to be operated in access point
mode as before, but to connect to your home network. You can enter your station data simply at the top of the program this time.
After the upload, it may be a while before the connection to the network is established. If this has been successful, the LED D3, which is firmly
equipped on the board, lights up. This is the sign that the controller is now ready. While the serial monitor is active, you will see the
corresponding message, but you may want to use the board autonomously for later experiments. In this case, the feedback can be very helpful.
The serial monitor will also give you the information of which IP has had the board assigned by the router. This IP is important if you want to
connect to the board later.
The connection to the board works similarly as before. Only the IP of the module and your computer will have changed. The program initially
does not receive any measured results. You need to send a message, e.g. the command led=1, first. New measured data will then come in
approx. once per second.
Day 8: A browser
In the last days, we mostly dealt with the UDP protocol with which data can be sent out simply and directly. In the next few days, we will deal
with the TCP (Transmission Control Protocol). TCP only permits one connection at a time between precisely two computers. It is mostly used
online for browsing on websites.
Behind today's door, there is another resistor with 1 kΩ (brown, black, red). As with all other parts: keep it safe, even though you are not using
this part today yet.
The programme
The program's function is similar to the SoftwareSerial program of the first day, but among others, it connects to the WLAN independently at
start-up. This saves you a lot of typing and you can start more quickly. Do not forgot that you need to enter your home network’s data into the
program. Then enter the following command line in the serial monitor:
AT+CIPSTART=“TCP“,“www.example.com“,80
This command establishes a TCP connection to the website www.example.com. Port 80 is the standard port for HTTP-queries. After
confirmation of the connection with OK, you can enter the next command, which you already know:
AT+CIPSEND=40.
You want to send a message through the connection you have just established, after all. When you are asked to enter a text with >, first enter
GET / HTTP/1.1
and then push Enter. Enter does not appear in the Serial Monitor, but the module has received it. Then the message continues with
Host:www.example.com
followed by two times Enter. A long text is returned. The first part is the response of the server, containing some information for the browser.
The text after <!document html> is the website that you can also see when you call the page www.example.com directly - but purely textbased. A browser would now interpret this text and present it in a form that we understand.
Excerpt from the answer of the web server
Day 9: TCP time
Today's project uses the functions of the prior test to independently collect information from a website. The program specifically loads the current time from a dedicated website and thus sets the internal clock of the controller that is implemented by library.
Behind today's door, there is another resistor with 1 kΩ. All three resistors will be needed for tomorrow's experiment.
The programme
While yesterday's program still required mostly manual operation, today's program works mostly autonomously. The controller connects to the
website entirely independently:
http://chronic.herokuapp.com/
The URL can be used to call various time systems and conversions. The current time valid in Germany in winter is queried by the URL
http://chronic.herokuapp.com/utc/in-one-hour
. Therefore, the call of the function getTime has the second parameter »utc/in-one-hour«. Based on the UTC (coordinated world time), you need
to change the call to »utc/in-two-hours« in summer. You can treat all other time zones according to the same system.
The determined time is now handed over to the Time-Library of Michael Margolis (source: http://www.pjrc.com/teensy/td_libs_Time.html).
For practical reasons, a copy of the Time-Library version that I use is enclosed in the sketch folder. It must be copied into the libraries folder of
your sketchbook folder. In the background, the new time is continually calculated and output in the terminal every second. You can now simply
program an alarm clock or another time-controlled application.
Day 10: Temperature display
Today's project is an intuitive display of the current temperature. With a single look, you can guess at whether it is sensible to take along a
warm jacket.
Behind today's door, there is another LED. This is a special one. It is an RGB-LED. RGB means Red, Green, Blue, the LED actually is made up of
several LEDs with a shared cathode connection. A combination of the different colours with different brightnesses permits presenting almost any
colour. The LED can be connected to the PWM outputs D3, D5, D6 of the controller with dropping resistors.
The programme
Today's sketch is about querying a website again, but this time a weather site. In particular, this is:
www.openweathermap.org
On this page, you can get information on the weather in your town by varying the URL. The example is limited to live data in the XML format in
the metric system. Just enter the city you want to query in the source text behind CITY. As an example, I am using my home town Essen:
http://api.openweathermap.org/data/2.5/weather?q=Essen&units=metric&mode=xml
The programme now reads the temperature from this page and shows the result in colour via the RGB-LED. At the same time, the value is output
via the serial monitor. The temperature range used in the example program for display on the LED is -20°C to +40°C.
Day 11: TCP-Webserver
In the previous experiments, we dealt with the subject of TCP and access to web servers a lot. Today, the module is to act as a web server of its
own for the first time.
Behind the door of the 11th day, there is a special cable that will be very useful soon. A special setup is not necessary today, since the program
works similarly to the serial monitor programme of day one.
The programme
Change the WLAN data as before and load the program onto your board. Then start the monitor. It may take a few seconds before the message
that the board is connected appears. When the success message has appeared and the IP of the module is displayed, you can start with the first
command in the Serial Monitor:
AT+CIPMUX=1
This command permits multiple connections to the module. You can then access the web server from several computers. Use the next command
to start the web server:
AT+CIPSERVER=1,80
The parameter 1 means that the server is being started. 0 terminates a server again. The number 80 represents the port under which the server
can be reached. HTTP requests sent by the browser are generally sent through port 80.
You can now open a browser of your choice and enter the IP of your module into the address bar and call it. The browser initially shows a
loading message, but the Serial Monitor will show a change. You can see a request query similar to the one you have sent out manually before.
The browser query
The browser now waits for a response, and will show a loading sign until then, or until the connection is interrupted due to time-out. You can
send a message to the browser with a version of a familiar command:
AT+CIPSEND=0.7
The parameter 0 indicates the client to which the message is to be sent here. This is necessary because multiple connections are permitted and
several clients may therefore also be connected. The second parameter, here 7, again indicates the characters to be sent. > appears, and you can
enter a simple
Hello
and send it out with Enter. Nothing will change in your browser at first. You need to close the connection before this can happen. For this, use
the command:
AT+CIPCLOSE=0
Now you can see a Hello in the browser. You have implemented the first webserver application.
Day 12: Autonomous webserver
The results of yesterday's experiment are now to be used in an autonomous program. Today's program not only sends a simple website to the
browser, but also permits control of an LED.
Behind today's door, you will find a 9-V battery clip that can make your board mobile. As an alternative, you may also use a Power Bank (a
battery pack usually used for mobile phones). If you want to use the 9-V-battery, observe that the red wire must be connected to Vin, and the
black one to GND. The figure shows the setup of today's experiment with external power supply.
The programme
Today's program sends a slightly more complex page than the previous experiment. You can also switch the LED at pin D9 by entering /LED
behind the IP? of the module. The current condition of the LED is then inverted, i.e. toggled each time.
Enter the WLAN data and upload the program. The board's IP is displayed in serial mode. Then you can open the browser and call the board's
IP. The website now has a headline and a little more text. The text indicates how to control the LED. It is a first, fully autonomous web server.
Day 13: Website with buttons
In today's experiment, the illustration of the website is even more sophisticated. There are now also control elements that permit much more
comfortable control of the LED.
The structure of today's experiment is no different from yesterday's: An LED at pin D9, which can be controlled via the module. As an additional
component, today's door once again holds a resistor with 1 kΩ. If necessary, you can now reduce the brightness of an LED by switching two
resistors in series.
The programme
Today's program saves the website a little differently from the preceding one. While the simple website was contained in the source text
yesterday, the page is saved in a Progmem variable this time. This relieves the board's SRAM and permits more complex display of websites.
However, you are losing some overview of the page.
You can, however, view the HTML file in the Sketch folder and change it as required. By having the website converted to bytes on the website
tools.thebuzzmedia.com/bytechar
and entering these into the program variable, you can generate a new website for your web server.
Day 14: Webserver for the RGB-LED
Today's project is about controlling the RGB-LED by web server. A well-structured interface can be used to change the colour of the LED. The
website has also been adjusted and should be easy to display even on Smartphones.
Behind today's advent calendar door, there is another resistor, but this one is of 10 kΩ (brown, black, orange). You will need it for tomorrow's
experiment.
The structure of today's experiment is like the one from day ten. The RGB-LED is connected to the PWM-capable pins D3, D5 and D6 with
dropping resistors.
The programme
The transmitted website is again concealed in the Progmem variables site in binary form. Again, you can view the HTML page in the Sketch
folder. After setting the WLAN data and uploading the programme, the website of the web server can be reached via the IP of the module. The
page is designed similarly to the previous one in background colour and headline. However, there is a new element on the page, i.e. the HTML5element Colour Picker. It can be used to select a colour for the LED. Once you have confirmed the colour, the LED will display it. The display of
the Colour-Picker element may differ strongly depending on the chosen browser.
Day 15: Light sensor
Today's project does not use the web server's website as a control interface, but as an output element. The brightness measured via a brightness
sensor is displayed well-structuredly as a relative value.
Behind today's door, there is another photo transistor that serves as a light sensor. The photo transistor looks like an LED, but should not be
mistaken for one. The structure of today's experiment is shown in the figure. The collector of the photo transistor is the shorter connection. It is
applied to +5 V.
The programme
Until now, the websites of the webserver were always made up of an unchangeable page that sent data to the controller. Today, the website is
to be changed before being transmitted to the browser, to display the appropriate brightness of the photo transistor. This works because the
source code of the website holds a kind of placeholder. The program now replaces the placeholder *bright* when loading the data from the
Progmem variable by the current brightness value. Thus, the output text and the deflection of the slider are changed. Another line in the HTML
file ensures that the page will reload automatically every few seconds. The current brightness is already displayed well-structuredly in the
browser.
The website of the brightness sensor
Day 16: GPIO Control
Today's project permits simple control of the digital pins D2-D7 per website. The status of the respective pin is also presented on the website, so
that you will never lose the overview.
To review the condition of the pin well, a setup as in the following figure is recommended. Both the RGB-LED and the regular LED are used. The
cathodes of the LEDs are now not connected to the long ground line on the outside of the board, but are also at a digital output. Only when
these pins are switched low can the LEDs light up.
Today's calendar component is another cable. This permits keeping the LED off the board. You can now install the board in a housing, for
example, and put the LED outside.
Attention! LEDs must not be connected without dropping resistors. In this case it is permitted due to the On resistors of the internal port FETs of
approx. 30 Ohm. Because the LEDs are placed between two ports, they actually work with a dropping resistor of 60 Ohm. Depending on LED
type and colour, an LED current between 15 mA and 30 mA at most occurs. This is still permitted.
The programme
The website of today's program uses check boxes as an HTML element. When you upload the program and call the page of the board, you can
see a number of boxes that can be clicked. A check mark in a box means that the pin is high. No check mark means low. You can now try out
which pins need to be high and which ones need to be low for all LEDs to be lit.
Day 17: IR module
Today's project permits controlling the controller by remote control. You can change the colour of the RGB-LED with buttons you can choose on
an infra-red remote control, and change the background colour of the website right along with it.
Behind today's door, you will find the important part of today's project, i.e. the infra-red receiver module. You can connect the module without a
cable as shown in the figure below. The program sets the corresponding pins so that the module is supplied with power.
The programme
Today's program once again uses an external library: the IRremote-Library by Ken Shiriff. A copy of the version used by me is again enclosed in
the Sketch folder and only needs to be copied into the library folder of your Sketchbook.
After uploading the program, you should start the Serial Monitor. Find a remote control and point it at the module. When you push a button, you
should have the value of the signal output as a HEX code and the type of the protocol as a number in the monitor. When the type is displayed as -1,
the protocol has not been recognised. There may be several failed attempts before a command is properly decoded. Just try out a bit or try another
remote control. Once you have found a working one, select six buttons (best take Power, Volume up, Volume down, Channel up, Channel down and
Mute). Now copy the codes for the six commands in the program behind the six #define irComX (do not forget the 0x before the hex code). The
commands of an LG-TV remote control are pre-defined there. If you have entered the codes correctly, you can upload the program again. You can
use the buttons defined by you to change the colour of the RGB-LED now. When updating the board page, you will also see that the colour has
changed.
Day 18: Universal remote control
Yesterday, you built a receiver for infra-red remote controls. Today, you are building the remote control itself. More precisely, you will build a
universal remote control that you can operate by computer or Smartphone and with which you can operate your TV or other devices whenever
you misplace the original remote control.
For this project, you need the component behind today's door: the IR diode. It looks like a simple LED, but it sends light in the invisible infra-red
range. The IR-signals are visible to a digital camera, however. The structure of today's experiment is shown in the figure. Don't be surprised that
the IR-LED is not given a dropping resistor. The effective dropping resistor is the On-resistor of the port, at approx. 30 Ohm. Because of this, the
current through the diode is quite high, but the impulses sent are so short that the diode will not take damage.
The programme
Before the program can work, you need to make some adjustments again. If you read out and used the codes for Power, Volume up, Volume
down, Channel up, Channel down and Mute yesterday, you can simply enter these codes into the irCommand array in sequence. Otherwise,
install yesterday's programme again and read out the matching codes. Of course, you may use entirely different codes as well. The labels on the
website will not match then. In addition to the codes, you also need to enter the protocol used in the variable irProtokoll if your remote control
is supported. Last, you need to enter the length of the signal to be sent. Determine it by multiplying the digits of the hex code by four. Example:
My code for Power was 0x20DF10EF. 0x is simply the sign for a hex code, which leaves 20DF10EF and thus an eight-digit hex code. 8•4 = 32, i.e.
in the example program, the variable irLen means 32. A similar calculation is needed for a code with another length.
Once you have entered all codes and parameters, and of course also your WLAN data, you can upload the program. The website of the board
now contains six buttons that are labelled accordingly. When you push one of the buttons, a message should appear on the Serial Monitor and
your TV or other device should react to the signal correctly. If not, you may need to get closer or check if the IR diode sends anything at all. An
LED connected with the wrong polarity would be one possible reason why a project is not working as desired.
Day 19: ThingSpeak
In the last days of the advent time, we will deal with an entirely new subject: the website ThingSpeak. This website has been specifically
developed for the subject of Internet of Things and contains various practical functions for you.
Before you tackle the setup and programme as usual, you need to set up an account on the website
www.ThingSpeak.com
. Log in with your user data under the item Sign In. You can see a website that shows your channels. Since you have no channels yet, this site
will look rather empty. Click New Channel and assign a name, e.g. Light. In this project, you will measure brightness. In the item Field1, you can
now assign a name to the field, e.g. Brightness. All other fields can be left empty for now.
Click Save Channel to save your settings. You will be forwarded to the page of your channel, on which you will only see an empty chart. Click
API Keys in the tab above. The sequence of numbers and letters that you will find in the item Write API Key will be needed in a moment.
You will find another cable behind today's door. You can now also place three-legged parts such as the IR reception module, outside of the plug
board. Today's experiment is structured identically as the one from the 15th day. A voltage divider with 10-kΩ-resistor and photo transistor
permits measuring the current brightness.
The setup with photo transistor at A0
The programme
Today's program measures the brightness, similar to the programme from day 15 . In contrast to the past experiment, however, the data will be
sent directly to the ThingSpeak page. This page will not only save the data, but also present them well-structuredly in a chart. It is a very
practical function for a measuring station with long-term monitoring.
For the program to be able to send to the website, you need to enter the above API key in the program first under the item ThingSpeakKEY in
addition to your WLAN data. It is recommended to open the Serial Monitor after uploading. Usually, an update-send message should accompany
successful transmission. On the ThingSpeak page, you can now click the tab Private View of your channel again. There, you can see the chart of
your channel, which receives new data every 15 seconds.
Day 20: Twitch
The website ThingSpeak offers a lot more than just long-time monitoring of sensors. Today's project is similar to the projects from days 9 and 10
in its basic idea. Information is collected from a website on the internet. In this case, it is whether a specific stream is currently online or not.
There are two decisive advantages of the ThingSpeak version over the first attempts. First, the ThingSpeak page can also call websites via HTTPS
(HyperText Transfer Protocol Secure), while the module only supports the unsafe HTTP-protocol. Second, the website can pre-filter important
information and thus clearly reduce the data volume to be processed by the controller.
In today's project, you will implement a twitch streaming display as an example of different options. Twitch is a website on which live games or
information around the subject of computer games are streamed. One of the best-known streaming channels is RocketBeansTV from the former
GameOne producers, which sends around the clock and therefore is well suitable for the first test. Later, you can, of course, use a channel of
your choice.
The programme
In addition to the hardware setup, some steps on the ThingSpeak page are necessary. When you click APPs in the top-most menu of the website,
you will be shown a number of different application options. Today, we will deal with the ThingHTTP-App. If you click the corresponding
button, you will first be shown a rather empty interface. Click New ThingHTTP. Enter the following into the form that comes up:
Name:
Twitch
URL:
https://api.twitch.tv/kraken/streams?channel=rocketbeanstv
Method:
GET
HTTP Version:
1.1
Parse String:
_total
If you prefer another streamer, you can enter another channel in the URL behind "channel". Click Save ThingHTTP and then copy the API key
that appears in the overview into your clipboard. You now need to copy the key into the program, after #define ThingHTTP. Do not forget the
WLAN data. You can now upload the program. Once per minute, it will be checked if a stream can be found. If this is the case, the LED will light
up.
Day 21: Alarm system
Today's project is an alarm system with which you can, for example, check whether someone opens a drawer without permission. There is a
continuous check for whether the connected light sensor is exposed to too much light. If this is the case, an alarm signal will sound and a
message will be sent via Twitter.
Behind today's door, there is a Piezo speaker that is used as alarm signal encoder. The structure of today's experiment is shown in the figure.
The programme
Today's subject is, among others, the Twitter App of the ThingSpeak page. Click Apps and then ThingTweet. By clicking the link TwitterAccount
and entering your access data, you will connect the two services. If you have no Twitter account yet, it will pay off to create a test account for
processing the advent calendar. After Twitter has been successfully linked to ThingSpeak, you can enter the API key under Apps-ThingTweet
after the item #define TwitterKEY in today's program. The program now continually reviews whether the measured brightness increases over
500. If this is the case, a Twitter message is sent and the alarm is sounded until the brightness drops below 500 again. The currently measured
brightness values can be tracked via the serial monitor. For the first attempts, I recommend covering the light sensor to keep the alarm from
being triggered early.
Day 22: TalkBack
Today's project is about another app of the ThingSpeak page, i.e. the TalkBack-App. This function permits creating a command that is read and
executed by the controller. What appears nonsensical with a single controller does make sense when using two or an entire network of
controllers. Some boards can act as sensors then, e.g. with motion detectors, and send a TalkBack command. Another module reads the
command from the ThingSpeak page and then opens the door or reports an alarm.
You will find another button behind today's door. The setup of today's experiment consists of an LED with a dropping resistor and two buttons
as the figure shows.
The programme
First, you need to create a new TalkBack channel under APPS – TalkBack. If you like, you can also have the commands entered in a channel.
This can be the already-created light channel of the 19th day, or a dedicated channel. All commands are then logged. Particularly the API key,
which you will enter in #define TalkBackKEY, is important. In addition to the API-KEY, you now also need an ID, which you will find in the
overview under TalkBackID, after you have clicked Save-TalkBack. Enter #define TalkBackID into the program here.
If you upload the program now and call the serial monitor, you will first see the message No Command. Push one of the two buttons now. After
a brief time, the message OpenDoor or CloseDoor will appear, depending on which button you pushed. For the OpenDoor command, the LED
will also light up.
Day 23: Cheerlights
Today's experiment is based on a project by Hans Scharler that is called Cheerlights. The idea is globally linked lights that can be
simultaneously controlled via Twitter commands. It is a good example of the world growing closer and closer together with the Internet.
Behind today's door, you will find a fourth extension cable with which the RGB-LED can also be placed aside. This can be particularly practical
if, for example, you want to hide the board in the Christmas tree while the RGB-LED decorates the top of the tree.
The programme
For today's program, you do not need to make any dedicated ThingSpeak changes. This project has a public channel that you can find under
the link
https://thingspeak.com/channels/1417
. On that page, you will also always find the current colour and further information on the project.
The programme also needs the Crossfade-Library by Radek Wierzbicki (source:
https://github.com/radekw/Arduino/tree/5f24ce7c8db9dfbb5252b59824c3217d851b3a3c). For practical reasons, a copy of the Library version
used is enclosed in the sketch folder. It must be copied into the libraries folder of your sketchbook folder. The library permits quick and easy
definition of colours and also ensures that the LEDs will slowly change to another colour (this is called fade).
If you upload the program now, the current colour of the LED is displayed after a few seconds. You can now write a Twitter message and thus
change your and also the colour of all other Cheerlights users. The message must contain a #Cheerlights, @Cheerlights or just the keyword
Cheerlights and also have one of the pre-defined colours behind the keyword. The pre-defined colours include:
red, green, blue, cyan, white, warm white, purple, magenta, yellow, orange, pink
A possible tweet is:
Testing my #cheerlights project on my #NanoESP with the colour blue #ThingSpeak #IoT
or a similar message. This way, you can recolour the world.
Day 24: Fire alarm for the Christmas tree
The final project consists of several elements you have been introduced to in the course of the advent time. One function is the Cheerlights
function presented the day before. You can also receive the current colour of the Cheerlights project and display it with the RGB-LED. The board
is also used for long-term monitoring of the temperature. At the same time, the board is used to emit an alarm sound when the temperature
exceeds a specific value, e.g. because there is a fire. As a last function, the board can be used as a Christmas bell, by making it play the song
Jingle Bells with a time-controlled TalkBack command. All in all, today's project is an all-rounder for the Christmas tree.
Behind today's door, there is another rather exciting sensor: an NTC (negative temperature coefficient). It changes its resistance depending on
the temperature. It is a good idea to revisit some of the older experiments while using the temperature sensor. Today's setup consists of quite a
few elements. The potentiometer is also used again, to permit fine reconciliation of the NTC. Alternatively, you can also use the 10-kΩ-resistor,
but will then be unable to perform fine tuning.
The programme
The final program must combine the many different elements. The ThingSpeak page is very important again. Among others, the threshold
monitoring of the NTC is assumed by a ThingSpeak app. From there, the alarm action is performed, i.e. sending a Twitter message and inserting
a TalkBack command that trips the alarm on the controller. The Time-Control app of the ThingSpeak page can also be used to specify a time at
which the Jingle-Bells song will call the family to the tree, or at which the music is to wake you up the next morning.
In the first step, you need to set a new channel on the ThingSpeak page. You can name it FireAlarm, for example. Field1 is then given the name
Temp. Under API keys, you will find the first key that you need to enter for the ThingSpeakKEY. This ensures transmission of the current
temperature.
As a second step, you should generate a new TalkBack element. You can name it, e.g. Alarms. You can also have the commands logged in the
channel FireAlarm. You need to enter the API key after TalkBackKEY and the ID after TalkBackID. Now you can also send commands to the
board. You can also enter commands manually by clicking the Add a new Command in the TalkBack overview of the Alarm channel and then
enter either Alarm or Jingle under Command String. You do not need to enter the position, since the command is automatically saved in the first
location. You can now upload the program and test whether the transfer of the current temperature value works and whether the board
executes the commands. In this place, it will also help to calibrate the NTC via the potentiometer with a room thermometer.
Generally, this would be a full project already. However, the bonus functions are still missing. They no longer need to be performed in the
programme, however, but only on the ThingSpeak page. For this, go to Apps and then select React. React can be used to react to specific events.
Click New React to create a new React function and enter the following values:
Name: FireDetect1
Condition Type: Numeric
Test Frequency: On Data Insertion
Condition: If Channel
FireAlarm
field 1 (Temp)
is great than
40
Action: ThingTweet
then tweet:
Fire Alarm on the #NanoESP! Temp: %%trigger%%C #ThingSpeak #IoT
Using Twitter Account
[Twitter Account]
Options: Run action only the first time the condition is met
Save React saves the settings. Thus, the first step of monitoring is already made. If the value is exceeded, ThingSpeak will send a Twitter message via your account. For the second step, insertion of the alarm command, you need to reach a bit more deeply into your sleeve. The function
is not supported automatically. ThingHTTP is, however, supported. Therefore, click Apps and then ThingHTTP. Create a new element there and
set the following:
Name:
Alarm
URL:
https://api.thingspeak.com/talkbacks/[YOUR TALKBACK ID]/commands
Method:
POST
HTTP Version:
Host:
Headers:
Body:
1.1
api.thingspeak.com
api_key=[YOUR TALKBACK KEY]&command_string=Alarm&position=1
Ensure that you replace [YOUR TALKBACK ID] and [YOUR TALKBACK KEY] in the URL and the body part by your TalkBack-ID and your TalkBackKEY. Now you can create another React element which contains the same parameters as the first one, but with the change that you will now
select ThingHTTP under Action and there the item Alarm. Thus, you have ensured that an alarm sounds when the critical value is exceeded.
As a last function, you can set up a time-controlled Jingle Bells. For this, click TimeControl under Apps and create a new element, e.g. with the
name Bell. Make the following settings there:
Name:
Frequency:
Time Zone:
Run At:
Fuzzy Time:
TalkBack:
Presents
One Time
Berlin
2015-24-12 7:00 pm
± 0 minutes
Alarms, add command: Jingle
For a first test, it is recommended to select a time in a few minutes. If this has worked, you can set the proper time.
You can also turn the project mobile with the 9-V battery clip or a rechargeable battery bank. When hiding the board in the tree, so that only the
RGB-LED points out of the branches in a fitting location, the ambience is not unnecessarily impaired either. Right on time at 7 PM, all family
members will be called to the tree by the sounds of Jingle Bells. I wish you a Merry Christmas!
Download