Controlling things around us wirelessly is a common thing that Arduino geeks do all the time like Arduino Light Control projects using IR remote, Bluetooth, wifi or even RF modules. Certainly, this kind of projects is categorized under the home automation projects.
But what if we have taken this to a whole different level where you can make this automated light controlled over the internet.
Yes, we will connect the lamp to the internet and upgrade its controllability level to be an IoT light!
Internet of Things
IoT is the recent cutting-edge technology that allows devices around us to connect to the internet. Hence, these devices can share their sensors’ data and any device can control another device as long as both of them is connected to the same network .. the broker.
So, in this IoT Arduino Light Control tutorial, we are going to connect 2 devices to the CloudMqtt broker, the lamp and the smartphone. Then we will control the lamp from the phone by using the publishing/subscribing MQTT protocol.
First of all, if this is your first time reading about IoT, then I recommend you go through the first blog of this IoT Blog Series which is IoT concepts before continuing in this Arduino Light Control tutorial. You will get all what you need to know about IoT and how it works.
Furthermore, I recommend you check this MQTT blog where you will know more about MQTT in details and try the cloudMqtt broker with the mobile App we are going to use in this blog.
The idea behind the IoT Arduino Light Control is that we will connect both the lamp and the phone to the CloudMqtt broker which is, of course, an online broker.
That means we need to connect the phone and the Arduino to the internet.
But Arduino alone can’t connect to the internet, so we will use 1Sheeld+ board that will be plugged into the Arduino and connect to the 1Sheeld App.
Therefore, the 1Sheeld will enable the Arduino to connect to the internet through the phone wifi/data.
Furthermore, 1Sheeld+ not only connect the Arduino to the internet but also it has IoT shield from within 40+ shields. This IoT shield allows the Arduino to connect to a certain broker to be able to publish and subscribe to the IoT network (the CloudMqtt broker).
Then we need another smartphone that will act as the other device that’s connected to the broker. You have to download an IoT App on that second phone.
You will find all software and App required for this tutorial are linked in the software components section.
How IoT Arduino Light Control will work
Once the phone – the first device – is connected to the broker and the Arduino – the second device – is connected to the broker too, we can start publishing messages from the phone like “on” and “off” on the topic that the Arduino is subscribing on.
In Arduino code, we will compare these received messages and then we can easily turn the connected lamp on/off according to the received message.
If this is your first time to deal with 1Sheeld or you want to learn more about it, then I recommend checking this quick and easy getting started tutorial.
Now, after you’ve become a little bit familiar with 1Sheeld, let’s start!
Step 1: Hardware components:
Arduino USB cable or 9-12v battery.
Relay 1 channel.
Male-to-Female jumper wires.
Android/iOS phone with 1Sheeld App installed on it.
Connect the lamp with the relay as illustrated below:
Switch the 1Sheeld power to operate on 5v (Not the 3.3v):
1Sheeld have 2 modes: Uploading mode and Operating mode. You can switch between them using the switch close to the Digital pins and is called “UART SWITCH” on 1Sheeld and “SERIAL SWITCH” on 1Sheeld+.
Firstly, you slide the switch towards the “SWITCH” notation which turns the 1Sheeld board into the Uploading mode to let you upload the Arduino code.
Then, after you finish uploading the code, slide the switch towards the “UART” notation (or “SERIAL” at 1Sheeld+ board) which turns the 1Sheeld board into the Operating mode to communicate with your smartphone 1Sheeld App.
Finally, connect the Arduino via your PC using Arduino USB cable.
I would recommend checking the Arduino IoT Shield documentation to know more about the Arduino IoT Shield functionalities and how to use them.
to your own broker instance data you got after you have created it on CloudMqtt website.
Check our MQTT blog to know almost all the steps for creating a broker instance on CloudMqtt website.
Then, Switch the 1Sheeld board to the Operating mode then open the 1Sheeld app and connect it to the 1Sheeld board via Bluetooth.
Step 5: Configure it:
Firstly, let’s configure the phone and connect it to the broker.
Open the IoT MQTT Panel App and create a connection to the broker to make your phone connected to the broker. We have explained this in the previous MQTT blog in details. Check it from here.
After that, you will add a panel with a type “switch”. So, select the switch type.
Then write any name for the panel, like “Light”. Then make its topic as “home/light/operate”. That’s the topic which this switch will publish on.
Hence, we need to publish only 2 messages, “on” and “off”. So, write them on the Payload on and Payload off sections.
A payload is just another name for the message.
The Final step in the App is to mark on the “Use icon switch” option and choose whatever switch shape and color you prefer for both the on and off icons.
When finished, press “CREATE”.
Step 6: Run the IoT Arduino Light Control:
First of all, we will open the CloudMqtt website from here and navigate to the Websocket UI to monitor what’s going on on the broker.
Then on the App, press on the upper right cloud-shaped button to connect the phone to the broker.
Once connected, the cloud-shaped button will change its color to be orange.
Finally, press on the RESET button on the Arduino and monitor the CloudMqtt WebSocket UI panel.
You saw something on the WebSocket UI, right? Cooool!
That’s because once the Arduino connects to the broker, it publishes on the topic “home/light/state” a message “ready”. Just an indication that the Arduino is now connected to the IoT network.
And once you press on the switch on the App, the lamp will respond by turning on and off. In other words, the lamp “actually the Arduino in a technical respect” is subscribing on the topic “home/light/operate”. This is the same topic that we configured the switch in the App to publish “on” and “off” messages on it.
You can easily monitor all the publishing and subscribing operations on the broker from the Websocket UI console. It will be something like that:
And here is the project working:
That’s it for the IoT Arduino Light Control, guys.
If you are interested in this IoT Blog Series, you can check the next IoT tutorial which demonstrates how to control a fan using IoT via your phone also.
An Arduino Temperature Humidity System is one of the most popular projects that most of us have tried or even saw before. It’s because of the ease of use of this DHT sensors those which give pretty accurate temperature and the humidity readings with a bit code. But as another tutorial of this continuous IoT …
Here we are again with another IoT tutorial using Arduino with 1Sheeld and just a smartphone. In previous tutorials, I have gone through controlling a lamp and fan using a phone and MQTT protocol. Today, I am going to get through another but more interesting IoT real-world project, controlling the Arduino Door Lock from …
Today, I have come with a new and quick IoT tutorial, IoT Fan Control! In a previous tutorial, I have gone through controlling a lamp using a phone and MQTT protocol. That was the first IoT tutorial using 1Sheel. Now, I am going to get through my second IoT real-world project. So, in this tutorial, …
MQTT is one of the most common used in IoT projects. It stands for Message Queuing Telemetry Transport. It’s a lightweight messaging protocol that uses publish/subscribe operations to exchange data between clients and the server very fast and with low internet packets. And here in our second blog in the IoT Blog Series, we …
Connected (IoT) Machines have conquered the world in a way humanity has never undertaken before. That ’s not a phrase from the Terminator movies, it’s just the reality of nowadays. Statistics show that the number of connected devices in 2018 is 23+ billions. This is almost 3 times the number of humans which is 7.6 …
Welcome to our home automation hacks series #3, for so many times I had problems with watering my plants while traveling abroad and I have always needed a way to control it remotely, then I decided to do it with one of the fanciest ways you may ever hear off, cause I’m gonna water my …