Hey Guys, today I’m gonna show you 11 different ways to turn on light using 1Sheeld.
Among all the +45 virtual shields supported in 1Sheeld, I have picked up 11 shields for controlling lights. In this tutorial I will walk you through each shield and show how to use them, and by the end of this tutorial I will merge all the codes together so you will be having all 11 controllers in 1 project 🙂 .
Lets start gathering components and connecting the hardware.
Components:
1- Arduino board
2- 1Sheeld+ board
3- Android or iOS device
4- Tiny Breadboard
5- LED
6- 330 ohm Resistance
7- Two Jumpers
8- 9V battery
Hardware connections:
Now after setting up the connections, lets start coding each shield to control the led…
1- Accelerometer Shield
Accelerometer Shield measures the acceleration of your phone on 3-axis (X, Y and Z), so I have made a condition on the accelerometer x-axis if the acceleration of the smartphone crossed 15 m/s2 then turn on the LED else just turn it off.
Arduino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#define CUSTOM_SETTINGS
#define INCLUDE_ACCELEROMETER_SENSOR_SHIELD
/* Include 1Sheeld library. */
#include <OneSheeld.h>
/* A name for the LED on pin 13. */
intledPin=13;
voidsetup()
{
/* Start communication. */
OneSheeld.begin();
/* Set the LED pin as output. */
pinMode(ledPin,OUTPUT);
}
voidloop()
{
/* Check X-axis acceleration. */
if(AccelerometerSensor.getX()>15)
{
digitalWrite(ledPin,HIGH);
}
else
{
digitalWrite(ledPin,LOW);
}
}
Actually using Gesture control in an application is making it more exciting and more fun just like here in the Orientation shield video tutorial:
2- Clock Shield:
Using the Clock Shield gives the ability to turn the light on and off on certain times,making it easy to turn on home lights when it’s near 6PM or turn it off when it’s 6AM.
Arduino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#define CUSTOM_SETTINGS
#define INCLUDE_CLOCK_SHIELD
/* Include 1Sheeld library. */
#include <OneSheeld.h>
/* A name for the LED on pin 13. */
intledPin=13;
/* Define some variables for the date and time. */
inthour,minute,second,day,month,year;
voidsetup()
{
/* Start communication. */
OneSheeld.begin();
/* Start the clock shield. */
Clock.queryDateAndTime();
}
voidloop()
{
/* Always get the date and time. */
hour=Clock.getHours();
minute=Clock.getMinutes();
second=Clock.getSeconds();
day=Clock.getDay();
month=Clock.getMonth();
year=Clock.getYear();
/* If the time is 6 pm turn on the LED and if it's 6 am turn it off. */
Adding the time factor is important in many projects specifically these which affects our daily usage, like controlling a coffee maker here in the clock shield video tutorial:
3- Color Shield:
Color Shield used to indicate the red color detected by the Smartphone camera on an LED, so this time the hardware connections will be slightly different, placing the LED on pin 11 instead of pin 13 making use of the PWM controlling the ambient light.
Arduino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#define CUSTOM_SETTINGS
#define INCLUDE_COLOR_DETECTOR_SHIELD
/* Include 1Sheeld library. */
#include <OneSheeld.h>
/* Reserve PWM pins for the RGB LED. */
intredPin=11;
voidsetup(){
/* Start communication. */
OneSheeld.begin();
/* Set the RGB LED pins as output. */
pinMode(redPin,OUTPUT);
/* Set the color detection palette to get only 8 different colors instead of the default 16 million. */
ColorDetector.setPalette(_3_BIT_RGB_PALETTE);
}
voidloop(){
/* Check if there's a new color received. */
if(ColorDetector.isNewColorReceived())
{
/* Read the last received color and save it locally. */
ColorreadColor=ColorDetector.getLastColor();
/* Get red value. */
byteredValue=readColor.getRed();
/* Output the values on the RGB LED pins. */
analogWrite(redPin,redValue);
}
}
Note: in this code I am using the 3-bit RGB palette with a red LED connected to arduino,but you can replace the red LED with an RGB LED to represent all the available colors from the RGB just like this project.
4- Face Detection Shield:
And now it’s the time for the Face Detection shield which is one of the latest shields and it’s a little bit weird to control an LED with detecting faces but what if we control it with a wink 😉
In this code, we are checking for a face and after we find it we check again if this face is winking so if the face is winking using the left eye we turn the light on and if it’s winking with the right eye we turn it back off. Cool, isn’t it?
The fifth shield is the Light Sensor shield which is detecting the light intensity in your environment and like most of the home automation projects or even like Lampposts in the street you want to turn on the light when it’s dark and turn it off when light intensity is good.
And that’s exactly what we have done in this code, we made the LED to turn on when the light intensity is below 50 Lux and turn it off other than that so it’s maybe the same idea of the clock shield example but it’s a bit smarter.
Arduino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#define CUSTOM_SETTINGS
#define INCLUDE_LIGHT_SENSOR_SHIELD
/* Include 1Sheeld library. */
#include <OneSheeld.h>
/* A name for the LED on pin 13. */
intledPin=13;
voidsetup()
{
/* Start communication. */
OneSheeld.begin();
/* Set the LED pin as output. */
pinMode(ledPin,OUTPUT);
}
voidloop()
{
/* Always check the light intensity. */
if(LightSensor.getValue()<50)
{
/* Turn on the LED. */
digitalWrite(ledPin,HIGH);
}
else
{
/* Turn off the LED. */
digitalWrite(ledPin,LOW);
}
}
6- Mic Shield:
Mic Shield uses the mic inside your smartphone to detect noise in surrounding environment, so this time I will turn on an LED when the noise level exceeds a certain threshold,for example 80 decibels.
Arduino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#define CUSTOM_SETTINGS
#define INCLUDE_MIC_SHIELD
/* Include 1Sheeld library. */
#include <OneSheeld.h>
/* A name for the LED on pin 13. */
intledPin=13;
voidsetup()
{
/* Start communication. */
OneSheeld.begin();
/* Set the LED pin as output. */
pinMode(ledPin,OUTPUT);
}
voidloop()
{
/* Always check the noise level. */
if(Mic.getValue()>80)
{
/* Turn on the LED. */
digitalWrite(ledPin,HIGH);
}
else
{
/* Turn off the LED. */
digitalWrite(ledPin,LOW);
}
}
Just like the example of the getting started tutorial here:
(//Line not needed//)Moreover you can use it in an analog way where you can indicate the level of noise on the LED but you will just need to change the hardware a little bit and put the LED control pin on a PWM pin just like the color shield example.
7- SMS Shield:
SMS Shield gives the ability to send/receive messages through the smartphone, so i will control the led by receiving a certain SMS (“Turn ON” or “Turn Off”) from another phone to turn on/off the LED.
Arduino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#define CUSTOM_SETTINGS
#define INCLUDE_SMS_SHIELD
/* Include 1Sheeld library. */
#include <OneSheeld.h>
constcharbody1[]="turn on";
constcharbody2[]="turn off";
constcharphone[]="+201099999999";
/* A name for the LED on pin 13. */
intledPin=13;
voidsetup()
{
/* Start communication. */
OneSheeld.begin();
/* Set the LED pin as output. */
pinMode(ledPin,OUTPUT);
}
voidloop()
{
SMS.setOnSmsReceive(&myFunction);
}
/* This function will be invoked each time a new sms comes to smratphone. */
voidmyFunction(char*phoneNumber,char*messageBody)
{
if(!strcmp(phone,phoneNumber))
{
if(!strcmp(body1,messageBody))
{
/* Turn on the LED. */
digitalWrite(ledPin,HIGH);
}
elseif(!strcmp(body2,messageBody))
{
/* Turn off the LED. */
digitalWrite(ledPin,LOW);
}
}
}
As coded SMS shield can check if there’s a new received SMS by only 1Line of code, moreover sending SMS is actually much easier:
8- Terminal Shield:
Time for one of the most powerful 1Sheeld shields, the Terminal Shield, which turns the smartphone as a serial terminal for debugging and data display.
In this code, I will send commands from the smartphone so the Arduino board compares them with the commands saved in the code,for example, if I send “turn on” the LED will turn on, and if I send “turn off” the LED will turn off plus printing the current state of the LED.
Arduino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#define CUSTOM_SETTINGS
#define INCLUDE_TERMINAL_SHIELD
/* Include 1Sheeld library. */
#include <OneSheeld.h>
charmyArray[8];
/* A name for the LED on pin 13. */
intledPin=13;
voidsetup(){
/* Start communication. */
OneSheeld.begin();
/* Set the LED pin as output. */
pinMode(ledPin,OUTPUT);
}
voidloop(){
Terminal.readBytes(myArray,8);
if(!memcmp("turn on",myArray,7)){
/* Turn on the LED. */
digitalWrite(ledPin,HIGH);
Terminal.println(" LED turned on");
}
elseif(!memcmp("turn off",myArray,8)){
/* Turn off the LED. */
digitalWrite(ledPin,LOW);
Terminal.println(" LED turned off ");
}
}
By using terminal shield to send text messages back and forth between the smartphone and the Arduino board, so what about making a digital voltmeter and display the readings on your smartphone like this lovely idea voltset ?
9- Toggle Button Shield:
The special thing about the Toggle Button Shield is that it can be used without the intervention of 1Sheeld library, just like a hardware switch in your connections. So with a simple code of a normal hardware button controlling an LED,I will use the toggle shield by pressing the Arduino logo after choosing the shield,then an arduino schematic view will pop up, and by swiping my finger I could choose any pin to be controlled.
Arduino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* A name for the switch on pin 2. */
intsw=2;
/* A name for the LED on pin 13. */
intledPin=13;
voidsetup(){
/* Set the LED pin as output. */
pinMode(sw,INPUT);
/* Set the LED pin as output. */
pinMode(ledPin,OUTPUT);
}
voidloop(){
if(digitalRead(sw)==1){
/* Turn on the LED. */
digitalWrite(ledPin,HIGH);
}
else{
/* Turn off the LED. */
digitalWrite(ledPin,LOW);
}
}
10- Twitter Shield:
For me, the Twitter Shield is one of the coolest ways to control things, imagine you want to turn on an LED every time your school or favorite team name mentioned on Twitter. Cool, Right? 1Sheeld is giving you the ability to track any work you want on all tweets posted since you have operated the system.
And as I’m a big fan of Game of Thrones series I have added it as my tracking keyword cause season 7 is approaching in the next July so everytime the LED turned on I will know that the “Winter is Coming” 🙂
Arduino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#define CUSTOM_SETTINGS
#define INCLUDE_TWITTER_SHIELD
/* Include 1Sheeld library. */
#include <OneSheeld.h>
intledPin=13;
voidsetup(){
/* Start communication. */
OneSheeld.begin();
pinMode(ledPin,OUTPUT);
/* Subscribe to setOnSelected event for the Twitter shield. */
Twitter.setOnSelected(&shieldSelection);
/* Subscribe to onNewTweet event. */
Twitter.setOnNewTweet(&myTweet);
}
voidloop(){}
voidshieldSelection()
{
/* Track keyword 1Sheeld on Twitter. */
Twitter.trackKeyword("Game of Thrones");
}
voidmyTweet(char*userName,char*userTweet)
{
/* Check if the tweet has 1Sheeld keyword. */
if(strstr(userTweet,"Game of Thrones")!=0)
{
/* Turn on the LED. */
digitalWrite(ledPin,HIGH);
OneSheeld.delay(10000);
digitalWrite(ledPin,LOW);
}
else{
digitalWrite(ledPin,LOW);
}
}
But what about tweeting using Arduino, actually, it’s even more simple and as always with 1Line of code, checkout this video tutorial for this thirsty plant tweeting:
11- Voice Recognition Shield:
Last but not least, our beloved Voice Recognition Shield which is giving you the ability to control things just with using voice commands and it can be activated also with 1Line of code: “VoiceRecognition.start();”
In this code you will find that I saved two commands “Turn on” and “turn off” and when the Arduino detect a voice commands it will compare it to them and then it decides the action to be taken in each state.
Many devices are running into the market nowadays for controlling homes with voice commands like Amazon echo and Google home, so why to buy one of them while you can make them yourself, just like this Amazon Echo clone made using 1Sheeld:
Integration
Time for code integration, I have combined all the codes together in one project so you can use up to 11 shields to control the LED or even more you can add peripherals as much as you want.
The only difference will be in controlling the LED with the color shield as we were using it as an analog but now I turned it to digital so it can fit within the rest shields.
Arduino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#define CUSTOM_SETTINGS
#define INCLUDE_ACCELEROMETER_SENSOR_SHIELD
#define INCLUDE_CLOCK_SHIELD
#define INCLUDE_COLOR_DETECTOR_SHIELD
#define INCLUDE_FACE_DETECTOR_SHIELD
#define INCLUDE_LIGHT_SENSOR_SHIELD
#define INCLUDE_MIC_SHIELD
#define INCLUDE_SMS_SHIELD
#define INCLUDE_TERMINAL_SHIELD
#define INCLUDE_TWITTER_SHIELD
#define INCLUDE_VOICE_RECOGNIZER_SHIELD
/* Include 1Sheeld library. */
#include <OneSheeld.h>
/* A name for the LED on pin 13. */
intledPin=13;
/* A name for the switch on pin 2. */
intsw=2;
/* Define some variables for the date and time. */
inthour,minute,second,day,month,year;
/* Define the expected phone numbers and messages body for the SMS. */
constcharbody1[]="turn on";
constcharbody2[]="turn off";
constcharphone[]="+201099999999";
/* Define an array of character to receive the terminal messages in. */
charmyArray[8];
/* Voice commands set by the user. */
constcharturnonCommand[]="turn on";
constcharturnoffCommand[]="turn off";
/* We recommend to press the "Arduino" reset button after turning into the operating mode to make sure that all commands in the setup function performed. */
voidsetup()
{
/* Start communication. */
OneSheeld.begin();
/* Set the LED pin as output. */
pinMode(ledPin,OUTPUT);
/* Set the LED pin as output. */
pinMode(sw,INPUT);
/* Start the clock shield. */
Clock.queryDateAndTime();
/* Set the color detection palette to get only 8 different colors instead of the default 16 million. */
ColorDetector.setPalette(_3_BIT_RGB_PALETTE);
/* Subscribe to setOnSelected event for the Twitter shield. */
Twitter.setOnSelected(&shieldSelection);
/* Subscribe to onNewTweet event. */
Twitter.setOnNewTweet(&myTweet);
/* Activate the voice recognition. */
VoiceRecognition.start();
}
voidloop()
{
/* Always get the date and time. */
hour=Clock.getHours();
minute=Clock.getMinutes();
second=Clock.getSeconds();
day=Clock.getDay();
month=Clock.getMonth();
year=Clock.getYear();
SMS.setOnSmsReceive(&myFunction);
Terminal.readBytes(myArray,8);
/* Check X-axis acceleration. */
if(AccelerometerSensor.getX()>15)
{
digitalWrite(ledPin,HIGH);
}
/* If the time is 6 pm turn on the LED and if it's 6 am turn it off. */
/* This function will be invoked each time a new sms comes to smratphone. */
voidmyFunction(char*phoneNumber,char*messageBody)
{
if(!strcmp(phone,phoneNumber))
{
if(!strcmp(body1,messageBody))
{
/* Turn on the LED. */
digitalWrite(ledPin,HIGH);
}
elseif(!strcmp(body2,messageBody))
{
/* Turn off the LED. */
digitalWrite(ledPin,LOW);
}
}
}
voidshieldSelection()
{
/* Track keyword 1Sheeld on Twitter. */
Twitter.trackKeyword("Game of Thrones");
}
voidmyTweet(char*userName,char*userTweet)
{
/* Check if the tweet has 1Sheeld keyword. */
if(strstr(userTweet,"Game of Thrones")!=0)
{
/* Turn on the LED. */
digitalWrite(ledPin,HIGH);
OneSheeld.delay(10000);
digitalWrite(ledPin,LOW);
}
else{
digitalWrite(ledPin,LOW);
}
}
At the end of this tutorial, hope I covered all the needed points to operate it yourselves and of course, if you have any questions just leave them bellow in the comments 🙂 .
Arduino keeps standing out from the crowd of all-around development boards due too its ease of use and budget price. As a result, this has enabled almost anyone to get his own idea into life no matter how crazy or even useless to the whole world it was, except for its maker! Also, it has …
Arduino robots are always funny and definitely more enjoyable when combined with robotic arm! And today, I will walk you through the making of a simple Arduino Robot Arm that’s made of cardboard and how you can attach it over your Arduino Bluetooth RC Car / Robot that you have made so far through this series. …
Arduino Line Following Robot is one of the easiest and most well-known projects that anyone can make to learn the basics of programming, electronics, and mechanics all in one project. It’s known that this project is common for most of the makers and tech students and today I am going to give it a revisit …
Back again with another Arduino Bluetooth RC Car tutorial but with an advanced feature that makes your car autonomous by adding ultrasonic sensors to the RC Car you have made before!. Yeah, I know that you may have seen other tutorials using ultrasonic to make the car/robot avoid obstacles ahead, but I am going to …
Cardboard crafts are one of the most popular and easy to make DIY stuff. Mixing this with the unmatchable enjoyment of RC Cars and the ease of using Arduino, I am going to show you how to make a Cardboard Arduino Bluetooth RC car that you can control via Bluetooth from your smartphone. …
Arduino Security Camera Have you ever wanted to check your home in real time? Afraid that maybe someone has stormed in, don’t remember if you shut the door or not or maybe wanna check if your Hyper-energetic dog has broken any of your dishes AGAIN!! 🙂 Then this is the perfect place for you cause today …