Prerequisites for Smart Streetlight
Simuli Virtual Lab
First, we need to create a new instance on the Simuli Virtual Lab platform which has an Arduino Uno, a W5500 Ethernet Module and an APDS 9301 Ambient Light Sensor.
Log in to your Simuli account and navigate to the Simuli Virtual Lab. Here we will create a new emulated instance of the Arduino Uno
. Click on the Launch
button under the Arduino to get started.
This will open the configuration menu. First, provide a name for the project. Then, we will add the APDS 9301
Ambient Light Sensor and the W5500
Ethernet Module by selecting it from the list of available components. Finally, review that the name for the project and the selected sensors are correct and click on the Launch
button.
Once we have clicked on the Launch button, a new instance of the Arduino Uno will be created. It can take a few minutes for this process to be completed.
While our new instance is being created, let's move forward to creating an Adafruit IO account and configure it.
Adafruit IO
Go to the Adafruit IO website, if you already have an account, you can directly log in and skip to the configuration part. If this is your first time at Adafruit IO, click on the Get Started for Free
button at the top. This will take you to a signup page, fill all the details and click on the CREATE ACCOUNT
button.
Once the account has been created, go back to the Adafruit IO website. Let's start by creating our feeds. Feeds act as our MQTT topics, where we can either publish our data or subscribe to receive the data. In this case, we will create 2 feeds, one for publishing ambient light data and another for publishing bulb on/off status.
Click on Feeds
, and then click on view all
. This will open up a list of all the feeds currently set up for our account. Let's create our feeds for luminosity and bulb status.
Click on the New Feed
button, this opens up a pop-up, let's name the first feed light. Finally, click on Create to create
this new feed. Repeat the same process to create another feed called bulb.
Once we have our feeds set up, we will move onto creating a dashboard for visualization. Click on Dashboards
and then click on view all
. This opens up a list of all the dashboards linked to our account. Let's create our new dashboard. Click on the New Dashboard
button, a pop-up opens, give the dashboard a name, let's call this dashboard Smart Light. Click on the Create
button and a new dashboard will be created and we can see it in the list. Click on the Smart Light in the list of dashboards to access it.
Now we are inside the dashboard, here we will add different blocks to make the dashboard useful. Click on the Gear icon
in the top left corner, this will open a new menu, select Create New Block
.
A new pop-up will open with different types of blocks we can create. For this example, we'll use the Line Chart
block. Select the Line Chart block, now we need to connect this block with a feed. Let's use the light feed that we had created earlier to plot the lux value on a graph. Click on the tick mark next to light
and click on Next step
.
Now we can change a few settings for our Line Chart block, let's give it a Block Title
of Light. We don't need to change anything else in this menu. Scroll down and click on Create Block
. Now our Line Chart is ready to receive the luminosity data from the feed and plot it on the graph. The dashboard should currently look like this.
Let's add another block but this time let's create a switch which will be toggled on or off automatically depending on the ambient light. Again, click on the Gear icon
in the top left corner and select Create New Block
. This time select the type as Toggle.
Now connect this block to the bulb
feed and click on Next Step
. Now give it a Block Title of Smart Light and Create Block
. Now we have both our blocks ready and connected to their respective feeds.
You can move the blocks using the Edit Layout
option under the gear icon to change the layout or the block size.
Once both blocks have been created, our Adafruit IO setup is complete. We will finally set up our Arduino IDE.
Arduino IDE
If you have not set up your Arduino IDE, follow the guide linked below.
Prerequisites for Arduino DevelopmentBefore using MQTT to publish our data to Adafruit IO, we need to install the relevant library. For this, open your Arduino IDE and go to Tools
and then to Manage Libraries...
. This will open up the library manager, here we can search for Adafruit MQTT, select the library and install it. Then, search for SparkFun APDS-9301 Lux Sensor library select and install it. Now we are ready to communicate with Adafruit IO via MQTT.
Now we are ready to program our Arduino Uno.
Last updated