In this episode of the Gentleman Maker, we'll use a Raspberry Pi and an Arduino to create the Sun Informer, a device that alerts us when the sun finally comes out and when we've been in it too long.

The U.K. is known for many things, including our tea, our apologies, and even our weather.

In actuality, the chances that someone would drink a cup of tea while interrupting a conversation about weather for an apology are not only probable—but highly likely. Just this morning, I had a cup of tea with my mum while I apologized for things I was not even responsible for, all while we had a big discussion about the appalling weather. I mean, the weather could be great, and it would STILL be the topic of discussion. Weather is a big thing over here!

As soon as the sun comes out, a lot of Brits like to run into the outdoors and make as much vitamin D as they can before the clouds come back over (it’s amazing that people over here don’t have rickets). Despite enjoying the sun, a lot of us also crisp up like bacon after a mere 15 minutes, so it's crucial that we don’t spend too long in the sun!

In this project, we will create the Sun Informer, a device that will alert us when the sun comes out and then alert us again when we've been out for too long.

 


What You Need to Build Your Sun Informer

In order to construct your Sun Informer, you will need the following:

 

The Schematic

 

You can check out the full Scheme-It schematic here.

 

How It Works: The Hardware

The hardware for this project is very simple and it takes advantage of easy-to-use dev systems such as the Raspberry Pi and the Arduino.

The Arduino will make voltage readings from the potential divider (R1 and R2) and then send a message to the Raspberry Pi if the reading goes beyond a specified value. The Raspberry Pi, upon receiving the detection message from the Arduino, will then perform two tasks:

  • Play an alert message over a speaker to inform nearby users that the sun is out
  • Send a message via Telegram to a mobile phone as a precaution

The Raspberry Pi and Arduino communicate using their inbuilt serial ports, which makes message transactions much easier!

 

Configuring Your Raspberry Pi

Raspbian (the OS that we will be using), does include an installation of Python 3, but in its default configuration, it cannot be used to play audio, read from the serial port (in fact, neither can the Pi itself), or send a message using Telegram. Therefore, we need to install PySerial, PyAudio, and Python Telegram bot via PIP before running our Python script. We will also need to enable the serial port on the Pi, which can be done by using the raspi-config command in a terminal window.

 

How It Works: The Software

The code for the Raspberry Pi is written in Python, while the code for the Arduino is written in C using the Arduino IDE. You can download the code at the end of this article. When the Arduino starts, it configures its hardware serial port to run at a baud rate of 115200.

With the serial port configured, the Arduino then executes the main loop, which takes analog readings from the potential divider and then compares this to a predefined value. This value needs to be obtained experimentally, as sunlight intensity can vary around the world and depending on the season. If the reading goes beyond the predefined value, a serial message is sent to the Raspberry Pi, informing the user that sunlight has been detected.

The Python script running on the Pi starts by configuring variables and initializing the Telegram bot library. Then the main program loop is executed, which constantly looks for data over the serial port. If data is available, the script sounds the alarm over the speaker using PyAudio and sends a Telegram message to the user, specified by the user_id variable. At this point, the script starts a countdown.

Upon completion of the countdown, it alerts the user via Telegram that it is time to come inside.

 


 

With that, you should have everything you need to create your own Sun Informer.

Be sure to check out the rest of the Gentleman Maker series for more proper English electronics projects.

 

  Sun Informer Code  


Comments

1 Comment


  • Aman bharti 2018-06-15

    I like your work and this provide very detail information and tutorial that is very essential for nowdays