You are on page 1of 87

This work is licensed under a Creative Commons

Attribution-NonCommercial 4.0 International License.


Vikas Yadav
do.vikas1369@gmail.com

INTERNET OF
THINGS
LAB MANUAL
List of Experiments

1. Study of various development boards such as Arduino Uno, Intel Edison & Raspberry
Pi
Arduino Uno based experiments
2. Blinking LED using Arduino Uno R3
3. Communication through Serial Monitor on Arduino Uno
4. Controlling LED using a Pushbutton using Arduino Uno
5. Programmatically controlling LED using two pushbuttons on Arduino Uno
6. LED fading using Pulse Width Modulation(PWM) on Arduino Uno
7. Blinking LED at different rates based on the voltage value read from Potentiometer
8. Blinking LED at different rates based on the voltage value read from Light Dependent
Resistor(LDR) or Light Sensor using Arduino Uno
9. Reading and Writing in EEPROM of Arduino Uno
Intel Edison, Grove Kit & Arduino IDE based experiments
10. Grove Kit LED Socket Kit
11. Grove Kit Temperature Sensor
12. Grove Kit POT
13. Grove Kit Light Sensor
14. Grove Kit Buzzer
15. Grove Kit Button
16. Grove Kit Touch Sensor
17. Grove Kit LCD RGB Backlight Display
Intel Edison & Python based experiments
18. Blinking LED on Intel Edison using Python
19. Using UPM library to produce sound from Grove Buzzer in Python
20. Displaying message on Grove LCD using UPM library in Python
21. Reading temperature value from Grove Temperature Sensor using UPM library in
Python
22. MQTT communication on Intel Edison using RSMB
23. MQTT communication on Intel Edison with HiveMQ broker
24. Blinking LED remotely from Web based interface using MQTT & Websocket protocol
Raspberry Pi based experiments
25. Blinking LED using Raspberry PI GPIO in Python
26. Reading Analog value on Raspberry Pi using ADS1115 ADC Module
IoT Platform based experiments
27. Remotely controlling LED from Blynk App
28. Sending Sensor data to IBM Bluemix Cloud in quick start and registered mode
Experiment 1: Development boards

Aim: Study of various development boards- Intel Edison, Arduino Uno and Raspberry Pi

Hardware Components:
● Arduino Uno board
● Intel Edison board
● Raspberry Pi board

Theory:
A] Arduino Uno

Introduction:
The Arduino Uno is a microcontroller board based on the ATmega328. It has 14 digital
input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz
crystal oscillator, a USB connection, a power jack, an ICSP header, and a reset button. It
contains everything needed to support the microcontroller; simply connect it to a computer
with a USB cable or power it with a AC-to-DC adapter or battery to get started. The Uno
differs from all preceding boards in that it does not use the FTDI USB-to-serial driver chip.
Instead, it features the Atmega8U2 programmed as a USB-to-serial converter.

"Uno" means one in Italian and is named to mark the upcoming release of Arduino 1.0. The
Uno and version 1.0 will be the reference versions of Arduino, moving forward. The Uno is
the latest in a series of USB Arduino boards, and the reference model for the Arduino
platform; for a comparison with previous versions.

Power:
The Arduino Uno can be powered via the USB connection or with an external power supply.
The power source is selected automatically. The board can operate on an external supply of
6 to 20 volts. If supplied with less than 7V, however, the 5V pin may supply less than five
volts and the board may be unstable. If using more than 12V, the voltage regulator may
overheat and damage the board. The recommended range is 7 to 12 volts.

Memory:
The Atmega328 has 32 KB of flash memory for storing code (of which 0,5 KB is used for the
bootloader); It has also 2 KB of SRAM and 1 KB of EEPROM.

Communication:
The Arduino software includes a serial monitor which allows simple textual data to be sent to
and from the Arduino board. The RX and TX LEDs on the board will flash when data is being
transmitted via the USB-to serial chip and USB connection to the computer.
Pin Diagram:

Pin Configuration:
The power pins are as follows:
● VIN. The input voltage to the Arduino board when it's using an external power source
(as opposed to 5 volts from the USB connection or other regulated power source).
You can supply voltage through this pin, or, if supplying voltage via the power jack,
access it through this pin.
● 5V. The regulated power supply used to power the microcontroller and other
components on the board. This can come either from VIN via an on-board regulator,
or be supplied by USB or another regulated 5V supply.
● 3V3. A 3.3 volt supply generated by the on-board regulator. Maximum current draw is
50 mA.
● GND. Ground pins.
Communication Pins are:
● Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data.
These pins are connected to the corresponding pins of the ATmega8U2 USB-to-TTL
Serial chip.
● External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on
a low value, a rising or falling edge, or a change in value.
● PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite()
function.
● SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI
communication, which, although provided by the underlying hardware, is not currently
included in the Arduino language.
● LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH
value, the LED is on, when the pin is LOW, it's off.
● AREF. Reference voltage for the analog inputs. Used with analogReference().
● Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset
button to shields which block the one on the board.
● I2C: 4 (SDA) and 5 (SCL). Support I2C (TWI) communication using the Wire library.

Specifications:
B] Intel Edison

Introduction:
The Intel® Edison Module is a tiny, SD-card-sized computing chip designed for building
Internet of Things (IoT) and wearable computing products. The Edison module contains a
high-speed, dual-core processing unit, integrated Wi-Fi*, Bluetooth* low energy, storage and
memory, and a broad spectrum of input/output (I/O) options for interfacing with user
systems. Because of its small footprint and low power consumption, the Edison module is an
ideal choice for projects that need a lot of processing power without being connected to a
power supply.

The Intel® Edison Arduino Breakout includes a micro SD card connector, a micro USB
device port connected to UART2, and a combination micro USB device connector and
dedicated standard size USB 2.0 host Type-A connector (selectable via a mechanical
micro-switch). Though this kit won’t turn your Edison into an Arduino itself, you will, however,
gain access to the Arduino’s shield library and resources.

The Edison module is meant to be embedded in devices or development boards for


connectivity and power options.

The Intel® Edison Kit for Arduino allows for quick and easy prototyping with open source
hardware and the widely used Arduino software development environment. The kit gives you
the option to extend the Edison module to interface with existing Arduino UNO R3 shields for
extended functionality. The Intel® Edison Breakout Board Kit primarily provides power and
USB connectivity options; for instance, you can connect the Edison board to your laptop’s
USB port and get started quickly.

Features:

● Intel Atom system-on-a-chip (SoC) based on leading-edge 22nm Silvermont


microarchitecture, including a dual-core CPU and single-core microcontroller (MCU)
● Integrated WiFi, Bluetooth LE, memory and storage
● Support for more than 30 industry-standard I/O interfaces via a 70-pin connector
● Support for Yocto Linux, Arduino, Python, Node.js and Wolfram
● Open source community software tools enabling ease of adoption and inspiring
third-party app developers to build apps for consumers.
● EDI1.SPON.AL.S (System-On-Modules, SOM, Edison Module IoT Internal Antenna)
Intel Edison Compute Module with Arduino Breakout Board:

Specifications:
C] Raspberry Pi

Introduction:
The Raspberry Pi is a series of credit card-sized single-board computers developed in the
United Kingdom by the Raspberry Pi Foundation to promote the teaching of basic computer
science in schools and in developing countries. It is a capable little computer which can be
used in electronics projects, and for many of the things that your desktop PC does, like
spreadsheets, word processing, browsing the internet, and playing games. It also plays
high-definition video.

The Raspberry Pi is open hardware, with the exception of the primary chip on the Raspberry
Pi, the Broadcom SoC (System on a Chip), which runs many of the main components of the
board–CPU, graphics, memory, the USB controller, etc. Many of the projects made with a
Raspberry Pi are open and well-documented as well and are things you can build and
modify yourself.

The Raspberry Pi was designed for the Linux operating system, and many Linux
distributions now have a version optimized for the Raspberry Pi.

One powerful feature of the Raspberry Pi is the row of GPIO (general purpose input/output)
pins along the top edge of the board. These pins are a physical interface between the Pi and
the outside world. At the simplest level, you can think of them as switches that you can turn
on or off (input) or that the Pi can turn on or off (output). Of the 40 pins, 26 are GPIO pins
and the others are power or ground pins (plus two ID EEPROM pins which you should not
play with unless you know your stuff!)

You can program the pins to interact in amazing ways with the real world. Inputs don't have
to come from a physical switch; it could be input from a sensor or a signal from another
computer or device, for example. The output can also do anything, from turning on an LED
to sending a signal or data to another device. If the Raspberry Pi is on a network, you can
control devices that are attached to it from anywhere and those devices can send data back.
Connectivity and control of physical devices over the internet is a powerful and exciting
thing, and the Raspberry Pi is ideal for this.
Raspberry Pi Board with GPIO:

Technical Specification:

● Broadcom BCM2837 64bit ARMv7 Quad Core Processor powered Single Board
Computer running at 1.2GHz
● 1GB RAM
● BCM43143 WiFi on board
● Bluetooth Low Energy (BLE) on board
● 40pin extended GPIO
● 4 x USB 2 ports
● 4 pole Stereo output and Composite video port
● Full size HDMI
● CSI camera port for connecting the Raspberry Pi camera
● DSI display port for connecting the Raspberry Pi touch screen display
● Micro SD port for loading your operating system and storing data
● Upgraded switched Micro USB power source (now supports up to 2.4 Amps)
● Expected to have the same form factor has the Pi 2 Model B, however the LEDs will
change position

Conclusion:
Thus, we have studied various development boards- Intel Edison, Arduino Uno and
Raspberry Pi.
Experiment 2: Arduino Blink Example

Aim: To get familiar with Arduino IDE by blinking LED using Arduino Uno R3.

Hardware Components & Services Required:

● Arduino IDE
● Arduino UNO R3
● Jumper Wire
● 1 LED
● 1 x 1kΩ Resistor
● Breadboard

Theory:
The Arduino Software (IDE) allows you to write programs and upload them to your board.
Download the Arduino IDE from https://www.arduino.cc/en/Main/Software and install it.
Following is how Arduino IDE looks like.

Follow these steps to upload your sketch:

1. Connect your Arduino using the USB cable.


The square end of the USB cable connects to your Arduino and the flat end connects
to a USB port on your computer.
2. Choose Tools→Board→Arduino Uno to find your board in the Arduino menu.
You can also find all boards through this menu, such as the Arduino MEGA 2560 and
Arduino Leonardo.
3. Choose the correct serial port for your board.
You find a list of all the available serial ports by choosing Tools→Serial Port→ comX
or /dev/tty.usbmodemXXXXX. X marks a sequentially or randomly assigned number.
In Windows, if you have just connected your Arduino, the COM port will normally be
the highest number, such as com 3 or com 15.
Many devices can be listed on the COM port list, and if you plug in multiple Arduinos,
each one will be assigned a new number. On Mac OS X, the /dev/tty.usbmodem
number will be randomly assigned and can vary in length, such as
/dev/tty.usbmodem1421 or /dev/tty.usbmodem262471. Unless you have another
Arduino connected, it should be the only one visible.
4. Click the Upload button.
This is the button that points to the right in the Arduino environment. You can also
use the keyboard shortcut Ctrl+U for Windows or Cmd+U for Mac OS X.

Note:The verify button only compiles the code but the upload button compiles and uploads
the code on arduino.

LED
LEDs (that’s “ell-ee-dees”) are a particular type of diode that convert electrical energy into
light. In fact, LED stands for “Light Emitting Diode.”

The positive side of the LED is called the “anode” and is marked by having a longer “lead,”
or leg. The other, negative side of the LED is called the “cathode.” Current flows from the
anode to the cathode and never the opposite direction. A reversed LED can keep an entire
circuit from operating properly by blocking current flow.
Breadboard

Circuit Connection:
Code:

// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever


void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Conclusion: Hence familiarity with Arduino IDE was developed.
Experiment 3: Communication through Serial Monitor on Arduino

Aim: To learn to use facility of Serial Monitor provided with Arduino IDE to send commands
directly to Arduino Board.

Hardware Components & Services Required:

● Arduino IDE
● Arduino UNO R3
● Jumper Wire
● 1 LED
● 1 x 1kΩ Resistor
● Breadboard

Theory
You can use the Arduino environment's built-in serial monitor to communicate with an
Arduino board. Click the serial monitor button in the toolbar and select the same baud rate
used in the call to begin().

Circuit Connection:
Code:

void setup() {
// put your setup code here, to run once:
pinMode(13,OUTPUT);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
char input=Serial.read();
if(input=='1'){
digitalWrite(13,HIGH);
}
else if(input=='2'){
digitalWrite(13,LOW);
}
}

Conclusion: Hence in this experiment it is demonstrated how serial monitor built in with the
Arduino IDE can be used to send commands to Arduino Uno.
Experiment 4: Push Button Demonstration 1

Aim: To understand the functioning of Pushbutton.

Hardware Components & Services Required:


● Arduino IDE
● Arduino UNO R3
● Jumper Wires
● 1 LED
● 1 Pushbutton
● 1 x 1kΩ Resistor
● Breadboard

Theory:
The pushbutton is a component that connects two points in a circuit when you press it.The
example turns on an LED when you press the button.

Circuit Connection:
Code:

const int buttonPin = 2; // the number of the pushbutton pin


const int ledPin = 13; // the number of the LED pin

// variables will change:


int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.


// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
Conclusion: Hence the operation of Pushbutton is understood.
Experiment 5: Pushbutton Demonstration 2

Aim: To build a circuit that contains two pushbuttons and an LED & any other basic
components required. The LED would only light when both push button are pressed.

Hardware Components & Services Required:


● Arduino IDE
● Arduino UNO R3
● Jumper Wires
● 1 LED
● 1 Pushbutton
● 1 x 1kΩ Resistor
● Breadboard

Circuit Connection:

Code:
int button1=2;
int button2=3;
int led=13;
void setup() {
// put your setup code here, to run once:
pinMode(13,OUTPUT);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
int buttonstate1=digitalRead(button1);
int buttonstate2=digitalRead(button2);
if(buttonstate1==HIGH&&buttonstate2==HIGH){
digitalWrite(led,HIGH);
Serial.println("HIGH");
}
else{
digitalWrite(led,LOW);
}
}

Conclusion: Hence by performing this experiment it is learnt how to connect multiple


pushbuttons to the board and control the actuator(in this case a LED).
Experiment 6: Pulse Width Modulation

Aim: To understand the operation of Pulse width modulation by producing varying voltage
programmatically.

Hardware Components & Services Required:

● Arduino IDE
● Arduino UNO
● Jumper Wire
● 1 LED
● 1 x 1KΩ Resistor
● Breadboard

Theory:
Pulse Width Modulation, or PWM, is a technique for getting analog results with digital
means. Digital control is used to create a square wave, a signal switched between on and
off. This on-off pattern can simulate voltages in between full on (5 Volts) and off (0 Volts) by
changing the portion of the time the signal spends on versus the time that the signal spends
off. The duration of "on time" is called the pulse width. To get varying analog values, you
change, or modulate, that pulse width. If you repeat this on-off pattern fast enough with an
LED for example, the result is as if the signal is a steady voltage between 0 and 5v
controlling the brightness of the LED.

In the graphic below, the green lines represent a regular time period. This duration or period
is the inverse of the PWM frequency. In other words, with Arduino's PWM frequency at about
500Hz, the green lines would measure 2 milliseconds each. A call to analogWrite() is on a
scale of 0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on), and
analogWrite(127) is a 50% duty cycle (on half the time) for example.
analogWrite()

Writes an analog value (PWM wave) to a pin. Can be used to light a LED at varying
brightnesses or drive a motor at various speeds. After a call to analogWrite(), the pin will
generate a steady square wave of the specified duty cycle until the next call to analogWrite()
(or a call to digitalRead() or digitalWrite() on the same pin).

Circuit Connection:

Code:
int led = 9; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by

// the setup routine runs once when you press reset:


void setup() {
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:


void loop() {
// set the brightness of pin 9:
analogWrite(led, brightness);

// change the brightness for next time through the loop:


brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade:


if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}

Conclusion: Hence operation of Pulse Width Modulation(PWM) was understood.


Experiment 7: Demonstration of Potentiometer

Aim: Blinking LED at different rates based on the voltage value read from Potentiometer

Hardware Components & Services Required:


● Arduino IDE
● Arduino UNO
● Jumper Wire
● 1 LED
● 1 x 1kΩ Resistor
● 1 x 10kΩ Present Potentiometer
● Breadboard

Theory:
Potentiometer
Resistors provide a fixed value of resistance that blocks or resists the flow of electrical
current around a circuit, as well as producing a voltage drop in accordance with Ohm’s
law.Turn the pot and the resistance changes. Connect VCC to an outer pin, GND to the
other, and the center pin will have a voltage that varies from 0 to VCC depending on the
rotation of the pot.
Circuit Connection:

Code:

int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}

Conclusion: Hence It is leant how actuator(LED) can be controlled by varying the voltage
from Potentiometer using A/D Converter functionality present in the form of hardware on
Arduino Uno
Experiment 8: Demonstration of Light Dependent Resistor(LDR) or Light Sensor

Aim: Blinking LED at different rates based on the voltage value read from Light Dependent
Resistor(LDR) or Light Sensor

Hardware Components & Services Required:


● Arduino IDE
● Arduino UNO
● Jumper Wire
● 1 LED
● 1 x 1kΩ Resistor
● 1 x Light Dependent Resistor
● Breadboard

Theory:
Mini Photocell
This is a very small light sensor. A photocell changes (also called a photodetector, photo
resistor, CdS or photoconductive cell) resistance depending on the amount of light it is
exposed to. These little sensors make great ambient light triggers (when light in the room
turns on, do something).
Circuit Connection:

Code:

int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}

Conclusion: Hence It is leant how actuator(LED) can be controlled by providing varying the
light intensity exposure of LDR which changes the voltage using A/D Converter functionality
present in the form of hardware on Arduino Uno.
Experiment 9: Reading and Writing in EEPROM of Arduino Uno R3

Aim: To learn to use EEPROM library of Arduino to read and write from EEPROM.

Hardware Components & Services Required:


● Arduino Uno

Theory:
EEPROM Library

The microcontroller on the Arduino and Genuino AVR based board has EEPROM: memory
whose values are kept when the board is turned off (like a tiny hard drive). This library
enables you to read and write those bytes.

The supported micro-controllers on the various Arduino and Genuino boards have different
amounts of EEPROM: 1024 bytes on the ATmega328, 512 bytes on the ATmega168 and
ATmega8, 4 KB (4096 bytes) on the ATmega1280 and ATmega2560. The Arduino and
Genuino 101 boards have an emulated EEPROM space of 1024 bytes.

Code:
#include <EEPROM.h>
String str;
int a=0;//Used to signal that information has already been printed on Serial Monitor a=0
means not yet printed a=1 means already printed
int t=0;//Used to signal that some command has been sent via Arduino Serial Monitor t=0
means no command sent t=1 means command sent
int addr,val;
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
Serial.println("Serial communication initiated \nPlease enter 'read <addr>' to read and 'write
<val> <addr>' to write");
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
a=0;
str = Serial.readStringUntil(' ');
if(str=="read"){
addr = Serial.parseInt();
}
else if(str=="write"){
addr = Serial.parseInt();
val = Serial.parseInt();
}
t=1;
}
else{
if(t==1&&a==0){
if(str=="read"){
Serial.print("Content read from the address ");
Serial.print(addr);
Serial.print(" is ");
Serial.println(EEPROM.read(addr),DEC);
}
else if(str=="write"){
Serial.print("Value ");
Serial.print(val);
Serial.print(" written at the memory location ");
Serial.println(addr);
EEPROM.write(addr,val);
}
a=1;
}
}
}

Conclusion: Hence EEPROM read and write operation was performed.


Experiment 10: Blink LED using Grove Kit on Intel Edison

Aim: To get familiar with Grove Kit Components

Hardware Components & Services Required:

● Intel Edison with Arduino Expansion Board


● Base shield for Arduino
● USB Cable
● 1x Grove LED Socket Kit v1.5
● 1x LED
● 1x Grove Connector
● 1x USB Type A to Type B Connector Cable

Theory:
Grove - LED is designed for the beginners of Arduino/Seeeduino to monitor controls from
digital ports. It can be mounted to the surface of your box or desk easily and used as pilot
lamp for power or signal. Its brightness can be adjust by potentiometer.

Connection
1. Mount the base shield on Intel Edison Arduino Expansion Board
2. Using the power switch on the Base shield put the voltage at the base shield to 5V
3. Connect one end of the Grove connector to Digital Port D2 and other end to Grove
Socket Kit
4. Mount an LED on LED Socket Kit
5. Connect Intel Edison to Host and wait for It’s flash drive to mount
6. Write and Upload the Code on Arduino IDE
7. You will see the mounted LED blinking at the interval of 500 ms.

Program
#define LED 2 //connect LED to digital pin2
void setup() {
// initialize the digital pin2 as an output.
pinMode(LED, OUTPUT);
}

void loop() {
digitalWrite(LED, HIGH); // set the LED on
delay(500); // for 500ms
digitalWrite(LED, LOW); // set the LED off
delay(500);
}

Conclusion: In this way by using the Grove LED Socket Kit it is learnt how to connect
Grove kit component using the Grove Base Shield and connectors.

References
http://wiki.seeedstudio.com/wiki/Grove_-_LED_Socket_Kit
Experiment 11: Grove Kit Temperature Sensor

Aim: To observe changing temperature data on Serial Monitor in Arduino IDE

Hardware Components & Services Required:


● Intel Edison with Arduino Expansion Board
● Base shield for Arduino
● USB Cable
● Grove Temperature Sensor 1.2
● 1x Grove Connector
● 1x USB Type A to Type B Connector Cable

Theory
The Grove - Temperature Sensor uses a Thermistor to detect the ambient temperature. The
resistance of a thermistor will increase when the ambient temperature decreases. It's this
characteristic that we use to calculate the ambient temperature. The detectable range of this
sensor is -40 - 125ºC, and the accuracy is ±1.5ºC

Specifications
Voltage: 3.3 ~ 5V
Zero power resistance: 100 KΩ
Resistance Tolerance: ±1%
Operating temperature range: -40 ~ +125 ℃
Nominal B-Constant: 4250 ~ 4299K
Connection
1. Mount the base shield on Intel Edison Arduino Expansion Board
2. Using the power switch on the Base shield put the voltage at the base shield to 5V
3. Connect one end of the Grove connector to Analog Port A0 and other end to Grove
Temperature Sensor
4. Connect Intel Edison to Host and wait for It’s flash drive to mount
5. Upload the Code on Arduino
6. Open the Serial Monitor in Arduino from Tools->Serial Monitor
7. It will show the temperature.
8. If you hold the sensor with fingers for considerable amount of time you will observe
change in temperature values in serial monitor

Program

#include <math.h>

const int B=4275; // B value of the thermistor


const int R0 = 100000; // R0 = 100k
const int pinTempSensor = A0; // Grove - Temperature Sensor connect to A5

void setup()
{
Serial.begin(9600);
}

void loop()
{
int a = analogRead(pinTempSensor );

float R = 1023.0/((float)a)-1.0;
R = 100000.0*R;

float temperature=1.0/(log(R/100000.0)/B+1/298.15)-273.15;//convert to temperature via


datasheet ;

Serial.print("temperature = ");
Serial.println(temperature);

delay(100);
}
Significance of Power Switch
1. Every Grove connector has four wires, one of which is Vcc. However, not every
micro-controller main board needs a supply voltage of 5V, some need 3.3V. That's
why we add a power switch to Base Shield v2. In this way, you can adjust the voltage
of Vcc via this switch, making sure the voltage of Vcc is the same as supply power of
the main board.
2. So While using Arduino UNO with Base Shield v2, please turn the switch to 5v
position; While using Seeeduino Arch with Base Shield v2, please turn the switch to
3.3v.

Conclusion: Hence temperature sensor was interfaced to Intel Edison using Grove base
shield and its changing temperature was printed live on Serial Monitor.

References
http://wiki.seeedstudio.com/wiki/Grove_-_Temperature_Sensor_V1.2
Experiment 12: Grove Kit POT

Aim: To get familiar with Grove Potentiometer by performing Pulse width modulation on
LED.

Hardware Components & Services Required:


1. Intel Edison with Arduino Expansion Board
2. Base shield for Arduino
3. USB Cable
4. 1x Grove LED Socket Kit v1.5
5. 1x Grove Rotary Angle Sensor v1.1
6. 1x LED
7. 2x Grove Connector
8. 1x USB Type A to Type B Connector Cable

Theory
The rotary angle sensor produces analog output between 0 and Vcc (5V DC with
Seeeduino) on its D1 connector. The D2 connector is not used. The angular range is 300
degrees with a linear change in value. The resistance value is 10k ohms, perfect for Arduino
use. This may also be known as a “potentiometer ”

Connection
1. Mount the base shield on Intel Edison Arduino Expansion Board
2. Using the power switch on the Base shield put the voltage at the base shield to 5V
3. Connect one end of the Grove connector to Digital Port D3 and other end to Grove
Socket Kit
4. Connect one end of the Grove connector to Analog Port A0 and other end to Grove
Rotary Angle Sensor
5. Mount an LED on LED Socket Kit
6. Connect Intel Edison to Host and wait for It’s flash drive to mount
7. Write and Upload the Code on Arduino IDE
8. If you rotate the POT you will see the LED fading in and fading out

Code:
#define ROTARY_ANGLE_SENSOR A0
#define LED 3//the Grove - LED is connected to D3 of Arduino
#define ADC_REF 5//reference voltage of ADC is 5v.If the Vcc switch on the seeeduino
//board switches to 3V3, the ADC_REF should be 3.3
#define GROVE_VCC 5//VCC of the grove interface is normally 5v
#define FULL_ANGLE 300//full value of the rotary angle is 300 degrees
void setup()
{
Serial.begin(9600);
pinsInit();
}

void loop()
{
int degrees;
degrees = getDegree();
Serial.println("The angle between the mark and the starting position:");
Serial.println(degrees);

int brightness;
/*The degrees is 0~300, should be converted to be 0~255 to control the*/
/*brightness of LED */
brightness = map(degrees, 0, FULL_ANGLE, 0, 255);
controlBrightness(brightness);

delay(500);
}
void pinsInit()
{
pinMode(ROTARY_ANGLE_SENSOR, INPUT);
pinMode(LED,OUTPUT);
}

/*PWM control brightness */


/*If brightness is 0,the LED is off. */
/*The Greater the brightness, the brighter the LED.*/
/*The range of brightness is 0~255 */
void controlBrightness(int brightness)
{
analogWrite(LED,brightness);
}
/************************************************************************/
/*Function: Get the angle between the mark and the starting position */
/*Parameter:-void */
/*Return: -int,the range of degrees is 0~300 */
int getDegree()
{
int sensor_value = analogRead(ROTARY_ANGLE_SENSOR);
float voltage;
voltage = (float)sensor_value*ADC_REF/1023;
float degrees = (voltage*FULL_ANGLE)/GROVE_VCC;
return degrees;
}

Conclusion: Hence familiarity with Grove Potentiometer was developed.

References
http://wiki.seeedstudio.com/wiki/Grove_-_Rotary_Angle_Sensor
https://github.com/Seeed-Studio/Rotary_Angle_Sensor/blob/master/examples/ControlLEDBri
ghtness/ControlLEDBrightness.ino
http://wiki.seeed.cc/Grove-Rotary_Angle_Sensor/
Experiment 13: Grove Kit Light Sensor

Aim: To get familiar with Grove light sensor by performing Pulse width modulation on LED.

Theory

Grove Light sensor module uses GL5528 photoresistor(light dependent resistor) to detect
the intensity of light in the environment. The resistance of photoresistor decreases when the
intensity of light increases. A dual OpAmp chip LM358 on board produces voltage
corresponding to intensity of light(i.e based on resistance value). The output signal from this
module will be HIGH in bright light and LOW in the dark.

This module can be used to build a light controlled switch i.e switch off lights during day time
and switch on lights during night time.

Hardware Components & Services Required:


1. Intel Edison with Arduino Expansion Board
2. Base shield for Arduino
3. USB Cable
4. 1x Grove LED Socket Kit v1.5
5. 1x Grove Light Sensor v1.1
6. 1x LED
7. 2x Grove Connector
8. 1x USB Type A to Type B Connector Cable
Circuit Connection:
1. Mount the base shield on Intel Edison Arduino Expansion Board
2. Using the power switch on the Base shield put the voltage at the base shield to 5V
3. Connect one end of the Grove connector to Digital Port D2 and other end to Grove
Socket Kit
4. Connect one end of the Grove connector to Analog Port A0 and other end to Grove
Light Sensor
5. Mount an LED on LED Socket Kit
6. Connect Intel Edison to Host and wait for It’s flash drive to mount
7. Write and Upload the Code on Arduino IDE
8. If the resistance of light sensor falls below 20K then the LED will glow. More is the
light intensity lesser will be the resistance, higher will be the voltage and higher will
be the value read from A/D converter.

Code:
#include <math.h>

#define LIGHT_SENSOR A0//Grove - Light Sensor is connected to A0 of Arduino


const int ledPin=2; //Connect the LED Grove module to Pin12, Digital 12
const int thresholdvalue=20; //The threshold for which the LED should turn on. Setting it
lower will make it go on at more light, higher for more darkness
float Rsensor; //Resistance of sensor in K
void setup()
{
Serial.begin(9600); //Start the Serial connection
pinMode(ledPin,OUTPUT); //Set the LED on Digital 12 as an OUTPUT
}
void loop()
{
int sensorValue = analogRead(LIGHT_SENSOR);
Rsensor = (float)(1023-sensorValue)*10/sensorValue;
if(Rsensor<20){
digitalWrite(ledPin,HIGH);
}
else{
digitalWrite(ledPin,LOW);
}
Serial.println("the analog read data is ");
Serial.println(sensorValue);
Serial.println("the sensor resistance is ");
Serial.println(Rsensor,DEC);//show the ligth intensity on the serial monitor;
}

References
https://github.com/Seeed-Studio/Light_Sensor/blob/master/examples/Light_Sensor/Light_Se
nsor.ino

Conclusion: Hence familiarity with Grove Light Sensor was developed.


Experiment 14: Grove Buzzer

Aim: To develop familiarity with Grove Buzzer by producing sound from it of certain
frequency.

Theory
The Grove - Buzzer module has a piezo buzzer as the main component. The piezo can be
connected to digital outputs, and will emit a tone when the output is HIGH. Alternatively, it
can be connected to an analog pulse-width modulation output to generate various tones and
effects.

Hardware Components & Services Required:


1. Intel Edison with Arduino Expansion Board
2. Base shield for Arduino v2.1
3. USB Cable
4. 1x Grove Buzzer v1.2
5. 1x Grove Potentiometer
6. 1x Grove Connector
7. 1x USB Type A to Type B Connector Cable

Circuit Connection:
1. Mount the base shield on Intel Edison Arduino Expansion Board
2. Using the power switch on the Base shield put the voltage at the base shield to 5V
3. Connect one end of the Grove connector to Digital Port D3 and other end to Grove
Buzzer
4. Connect Intel Edison to Host and wait for It’s flash drive to mount
5. Write and Upload the Code on Arduino IDE
6. Move the slider of Grove POT from the GND position to VCC and see how the tone
and frequency of the buzzer vary as the supplied voltage increases.

Code:
void setup()
{
pinMode(3, OUTPUT);
}

void loop()
{
digitalWrite(3, HIGH);
delay(analogRead(0));
digitalWrite(3, LOW);
delay(analogRead(0));
}

Conclusion: Hence Grove Buzzer is used to produce sound of different frequency.

References
http://wiki.seeedstudio.com/wiki/Grove_-_Buzzer
Experiment 15: Grove Button

Aim: To control the actuator(LED) using Grove Button.

Hardware Components & Services Required:


1. Intel Edison with Arduino Expansion Board
2. Base shield for Arduino
3. USB Cable
4. 1x Grove LED Socket Kit v1.5
5. 1x Grove Button v1.1
6. 1x LED
7. 2x Grove Connector
8. 1x USB Type A to Type B Connector Cable

Theory:
Grove - Button is a momentary push button. It contains one independent “momentary on/off”
button. “Momentary” means that the button rebounds on its own after it is released. The
button outputs a HIGH signal when pressed, and LOW when released. The button signals
the SIG Pin of the Grove Interface while NC is not used at all.

Circuit Connection:
1. Mount the base shield on Intel Edison Arduino Expansion Board
2. Using the power switch on the Base shield put the voltage at the base shield to 5V
3. Connect one end of the Grove connector to Digital Port D2 and other end to Grove
Socket Kit
4. Connect one end of the Grove connector to Digital Port D7 and other end to Grove
Button
5. Mount an LED on LED Socket Kit
6. Connect Intel Edison to Host and wait for It’s flash drive to mount
7. Write and Upload the Code on Arduino IDE
8. If you click the button LED will glow otherwise it will be off.

Code:
int button = 7; //attach a button to digital pin 3
int LED = 2; //attach an LED to digital pin 7

void setup()
{
pinMode(button, INPUT); //define button an INPUT device
pinMode(LED, OUTPUT); //define LED an OUTPUT device
}

void loop()
{
int buttonState = digitalRead(button); //read the status of the button
if(buttonState == 1)
digitalWrite(LED,1);
else
digitalWrite(LED,0);
}

References
http://wiki.seeedstudio.com/wiki/Grove_-_Button
http://wiki.seeedstudio.com/wiki/Grove_-_Starter_Kit_Plus

Conclusion: Hence it is learnt how to control the LED using Grove Button.
Experiment 16: Grove Touch Sensor

Aim: To control the actuator(LED) using Grove touch sensor

Hardware Components & Services Required:


1. Intel Edison with Arduino Expansion Board
2. Base shield for Arduino
3. USB Cable
4. 1x Grove LED Socket Kit v1.5
5. 1x Grove Touch Sensor v1.1
6. 1x LED
7. 2x Grove Connector
8. 1x USB Type A to Type B Connector Cable

Theory
Grove - Touch Sensor enables you to replace press with touch. It can detect the change in
capacitance when a finger is nearby. That means no matter your finger directly touches the
pad or just stays close to the pad, Grove - Touch Sensor would outputs HIGH also.

Circuit Connection:
1. Mount the base shield on Intel Edison Arduino Expansion Board
2. Using the power switch on the Base shield put the voltage at the base shield to 5V
3. Connect one end of the Grove connector to Digital Port D2 and other end to Grove
Socket Kit
4. Connect one end of the Grove connector to Digital Port D6 and other end to Grove
Touch Sensor
5. Mount an LED on LED Socket Kit
6. Connect Intel Edison to Host and wait for It’s flash drive to mount
7. Write and Upload the Code on Arduino IDE
8. If you click touch the specific area on Touch sensor the LED will glow.

Code:

const int TouchPin=6;


const int ledPin=2;
void setup() {
pinMode(TouchPin, INPUT);
pinMode(ledPin,OUTPUT);
}

void loop() {
int sensorValue = digitalRead(TouchPin);
if(sensorValue==1)
{
digitalWrite(ledPin,HIGH);
}
else
{
digitalWrite(ledPin,LOW);
}
}

Conclusion: Hence in this way it is learnt how to control an actuator(LED) using Grove
Touch Sensor.

Reference
http://wiki.seeedstudio.com/wiki/Grove_-_Touch_Sensor
Experiment 17: Grove Kit LCD RGB backlight display

Aim: To display some message on Grove LCD panel on a specific background

Hardware Components & Services Required:


1. Intel Edison with Arduino Expansion Board
2. Base shield for Arduino
3. USB Cable
4. 1x Grove LCD RGB Backlight v4.0
5. 2x Grove Connector
6. 1x USB Type A to Type B Connector Cable

Theory:
Grove LCD module enables you to set the color to whatever you like via the simple and
concise Grove interface. It takes I2C as communication method with your microcontroller. So
number of pins required for data exchange and backlight control shrinks from ~10 to 2,
relieving IOs for other challenging tasks. Besides, Grove - LCD RGB Backlight supports
user-defined characters. Want to get a love heart or some other foreign characters? Just
take advantage of this feature and design it

Circuit Connection:
1. Mount the base shield on Intel Edison Arduino Expansion Board
2. Using the power switch on the Base shield put the voltage at the base shield to 5V
3. Connect one end of the Grove connector to I2C Port and other end to Grove LCD
RGB Backlight
4. Connect Intel Edison to Host and wait for It’s flash drive to mount
5. Write and Upload the Code on Arduino IDE
6. You will see the message ‘Hello World’ in RED background along with counter which
increases every second.’

Code:
Main File
#include <Wire.h>
#include "rgb_lcd.h"

const int colorR = 255;


const int colorG = 0;
const int colorB = 0;
rgb_lcd lcd;
void setup()
{
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);

lcd.setRGB(colorR, colorG, colorB);

// Print a message to the LCD.


lcd.print("hello, world!");

delay(1000);
}

void loop()
{
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);

delay(100);
}

rgb_lcc.cpp

#include <Arduino.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <Wire.h>

#include "rgb_lcd.h"

void i2c_send_byte(unsigned char dta)


{
Wire.beginTransmission(LCD_ADDRESS); // transmit to device #4
Wire.write(dta); // sends five bytes
Wire.endTransmission(); // stop transmitting
}

void i2c_send_byteS(unsigned char *dta, unsigned char len)


{
Wire.beginTransmission(LCD_ADDRESS); // transmit to device #4
for(int i=0; i<len; i++)
{
Wire.write(dta[i]);
}
Wire.endTransmission(); // stop transmitting
}

rgb_lcd::rgb_lcd()
{
}

void rgb_lcd::begin(uint8_t cols, uint8_t lines, uint8_t dotsize)


{

Wire.begin();

if (lines > 1) {
_displayfunction |= LCD_2LINE;
}
_numlines = lines;
_currline = 0;

// for some 1 line displays you can select a 10 pixel high font
if ((dotsize != 0) && (lines == 1)) {
_displayfunction |= LCD_5x10DOTS;
}

// SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!


// according to datasheet, we need at least 40ms after power rises above 2.7V
// before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
delayMicroseconds(50000);
// this is according to the hitachi HD44780 datasheet
// page 45 figure 23

// Send function set command sequence


command(LCD_FUNCTIONSET | _displayfunction);
delayMicroseconds(4500); // wait more than 4.1ms

// second try
command(LCD_FUNCTIONSET | _displayfunction);
delayMicroseconds(150);

// third go
command(LCD_FUNCTIONSET | _displayfunction);

// finally, set # lines, font size, etc.


command(LCD_FUNCTIONSET | _displayfunction);

// turn the display on with no cursor or blinking default


_displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
display();

// clear it off
clear();

// Initialize to default text direction (for romance languages)


_displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
// set the entry mode
command(LCD_ENTRYMODESET | _displaymode);

// backlight init
setReg(REG_MODE1, 0);
// set LEDs controllable by both PWM and GRPPWM registers
setReg(REG_OUTPUT, 0xFF);
// set MODE2 values
// 0010 0000 -> 0x20 (DMBLNK to 1, ie blinky mode)
setReg(REG_MODE2, 0x20);

setColorWhite();

/********** high level commands, for the user! */


void rgb_lcd::clear()
{
command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero
delayMicroseconds(2000); // this command takes a long time!
}

void rgb_lcd::home()
{
command(LCD_RETURNHOME); // set cursor position to zero
delayMicroseconds(2000); // this command takes a long time!
}

void rgb_lcd::setCursor(uint8_t col, uint8_t row)


{

col = (row == 0 ? col|0x80 : col|0xc0);


unsigned char dta[2] = {0x80, col};

i2c_send_byteS(dta, 2);

// Turn the display on/off (quickly)


void rgb_lcd::noDisplay()
{
_displaycontrol &= ~LCD_DISPLAYON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}

void rgb_lcd::display() {
_displaycontrol |= LCD_DISPLAYON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}

// Turns the underline cursor on/off


void rgb_lcd::noCursor()
{
_displaycontrol &= ~LCD_CURSORON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}

void rgb_lcd::cursor() {
_displaycontrol |= LCD_CURSORON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}

// Turn on and off the blinking cursor


void rgb_lcd::noBlink()
{
_displaycontrol &= ~LCD_BLINKON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void rgb_lcd::blink()
{
_displaycontrol |= LCD_BLINKON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}

// These commands scroll the display without changing the RAM


void rgb_lcd::scrollDisplayLeft(void)
{
command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
}
void rgb_lcd::scrollDisplayRight(void)
{
command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
}

// This is for text that flows Left to Right


void rgb_lcd::leftToRight(void)
{
_displaymode |= LCD_ENTRYLEFT;
command(LCD_ENTRYMODESET | _displaymode);
}

// This is for text that flows Right to Left


void rgb_lcd::rightToLeft(void)
{
_displaymode &= ~LCD_ENTRYLEFT;
command(LCD_ENTRYMODESET | _displaymode);
}

// This will 'right justify' text from the cursor


void rgb_lcd::autoscroll(void)
{
_displaymode |= LCD_ENTRYSHIFTINCREMENT;
command(LCD_ENTRYMODESET | _displaymode);
}

// This will 'left justify' text from the cursor


void rgb_lcd::noAutoscroll(void)
{
_displaymode &= ~LCD_ENTRYSHIFTINCREMENT;
command(LCD_ENTRYMODESET | _displaymode);
}

// Allows us to fill the first 8 CGRAM locations


// with custom characters
void rgb_lcd::createChar(uint8_t location, uint8_t charmap[])
{

location &= 0x7; // we only have 8 locations 0-7


command(LCD_SETCGRAMADDR | (location << 3));

unsigned char dta[9];


dta[0] = 0x40;
for(int i=0; i<8; i++)
{
dta[i+1] = charmap[i];
}
i2c_send_byteS(dta, 9);
}

// Control the backlight LED blinking


void rgb_lcd::blinkLED(void)
{
// blink period in seconds = (<reg 7> + 1) / 24
// on/off ratio = <reg 6> / 256
setReg(0x07, 0x17); // blink every second
setReg(0x06, 0x7f); // half on, half off
}

void rgb_lcd::noBlinkLED(void)
{
setReg(0x07, 0x00);
setReg(0x06, 0xff);
}

/*********** mid level commands, for sending data/cmds */

// send command
inline void rgb_lcd::command(uint8_t value)
{
unsigned char dta[2] = {0x80, value};
i2c_send_byteS(dta, 2);
}

// send data
inline size_t rgb_lcd::write(uint8_t value)
{

unsigned char dta[2] = {0x40, value};


i2c_send_byteS(dta, 2);
return 1; // assume sucess
}

void rgb_lcd::setReg(unsigned char addr, unsigned char dta)


{
Wire.beginTransmission(RGB_ADDRESS); // transmit to device #4
Wire.write(addr);
Wire.write(dta);
Wire.endTransmission(); // stop transmitting
}

void rgb_lcd::setRGB(unsigned char r, unsigned char g, unsigned char b)


{
setReg(REG_RED, r);
setReg(REG_GREEN, g);
setReg(REG_BLUE, b);
}

const unsigned char color_define[4][3] =


{
{255, 255, 255}, // white
{255, 0, 0}, // red
{0, 255, 0}, // green
{0, 0, 255}, // blue
};

void rgb_lcd::setColor(unsigned char color)


{
if(color > 3)return ;
setRGB(color_define[color][0], color_define[color][1], color_define[color][2]);
}

rgb_lcd.h

#ifndef __RGB_LCD_H__
#define __RGB_LCD_H__

#include <inttypes.h>
#include "Print.h"

// Device I2C Arress


#define LCD_ADDRESS (0x7c>>1)
#define RGB_ADDRESS (0xc4>>1)

// color define
#define WHITE 0
#define RED 1
#define GREEN 2
#define BLUE 3

#define REG_RED 0x04 // pwm2


#define REG_GREEN 0x03 // pwm1
#define REG_BLUE 0x02 // pwm0

#define REG_MODE1 0x00


#define REG_MODE2 0x01
#define REG_OUTPUT 0x08

// commands
#define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
#define LCD_DISPLAYCONTROL 0x08
#define LCD_CURSORSHIFT 0x10
#define LCD_FUNCTIONSET 0x20
#define LCD_SETCGRAMADDR 0x40
#define LCD_SETDDRAMADDR 0x80

// flags for display entry mode


#define LCD_ENTRYRIGHT 0x00
#define LCD_ENTRYLEFT 0x02
#define LCD_ENTRYSHIFTINCREMENT 0x01
#define LCD_ENTRYSHIFTDECREMENT 0x00

// flags for display on/off control


#define LCD_DISPLAYON 0x04
#define LCD_DISPLAYOFF 0x00
#define LCD_CURSORON 0x02
#define LCD_CURSOROFF 0x00
#define LCD_BLINKON 0x01
#define LCD_BLINKOFF 0x00

// flags for display/cursor shift


#define LCD_DISPLAYMOVE 0x08
#define LCD_CURSORMOVE 0x00
#define LCD_MOVERIGHT 0x04
#define LCD_MOVELEFT 0x00

// flags for function set


#define LCD_8BITMODE 0x10
#define LCD_4BITMODE 0x00
#define LCD_2LINE 0x08
#define LCD_1LINE 0x00
#define LCD_5x10DOTS 0x04
#define LCD_5x8DOTS 0x00

class rgb_lcd : public Print


{

public:
rgb_lcd();

void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);

void clear();
void home();

void noDisplay();
void display();
void noBlink();
void blink();
void noCursor();
void cursor();
void scrollDisplayLeft();
void scrollDisplayRight();
void leftToRight();
void rightToLeft();
void autoscroll();
void noAutoscroll();

void createChar(uint8_t, uint8_t[]);


void setCursor(uint8_t, uint8_t);

virtual size_t write(uint8_t);


void command(uint8_t);

// color control
void setRGB(unsigned char r, unsigned char g, unsigned char b); // set rgb
void setPWM(unsigned char color, unsigned char pwm){setReg(color, pwm);} // set pwm

void setColor(unsigned char color);


void setColorAll(){setRGB(0, 0, 0);}
void setColorWhite(){setRGB(255, 255, 255);}

// blink the LED backlight


void blinkLED(void);
void noBlinkLED(void);

using Print::write;

private:
void send(uint8_t, uint8_t);
void setReg(unsigned char addr, unsigned char dta);

uint8_t _displayfunction;
uint8_t _displaycontrol;
uint8_t _displaymode;

uint8_t _initialized;

uint8_t _numlines,_currline;
};

#endif

Conclusion: Hence a custom message was displayed on Grove LCD Panel which uses I2C
protocol.

References
https://github.com/Seeed-Studio/Grove_LCD_RGB_Backlight
Experiment 18: Grove Buzzer & UPM library

Aim: To produce sound of certain frequency from Grove Buzzer using UPM library in Python

Hardware Components & Services Required:


● Intel Edison with Arduino Expansion Board
● Base shield for Arduino v2.1
● USB Cable
● 1x Grove Buzzer v1
● 1x Grove Connector
● 1x USB Type A to Type B Connector Cable

Theory:
The UPM repository provides software drivers for a wide variety of commonly used sensors
and actuators. These software drivers interact with the underlying hardware platform (or
microcontroller), as well as with the attached sensors, through calls to
[MRAA](https://github.com/intel-iot-devkit/mraa ) APIs.

Programmers can access the interfaces for each sensor by including the sensor’s
corresponding header file and instantiating the associated sensor class. In the typical use
case, a constructor initializes the sensor based on parameters that identify the sensor, the
I/O protocol used and the pin location of the sensor.

Circuit Connection:
1. Mount the base shield on Intel Edison Arduino Expansion Board
2. Using the power switch on the Base shield put the voltage at the base shield to 5V
3. Connect one end of the Grove connector to Digital Port D5 and other end to Grove
Buzzer
4. Connect Intel Edison to Host and wait for It’s flash drive to mount
5. Initiate ssh connection to Intel Edison and write the python program using editor like
nano or vi and run it.

Code:
import time
import pyupm_buzzer as upmBuzzer
# Create the buzzer object using GPIO pin 5
buzzer = upmBuzzer.Buzzer(5)
chords = [upmBuzzer.DO, upmBuzzer.RE, upmBuzzer.MI, upmBuzzer.FA,
upmBuzzer.SOL, upmBuzzer.LA, upmBuzzer.SI, upmBuzzer.DO,
upmBuzzer.SI];
# Print sensor name
print buzzer.name()
# Play sound (DO, RE, MI, etc.), pausing for 0.1 seconds between notes
for chord_ind in range (0,7):
# play each note for one second
print buzzer.playSound(chords[chord_ind], 1000000)
time.sleep(0.1)
print "exiting application"
# Delete the buzzer object
del buzzer

Conclusion: Hence a UPM library in python is used to produce sound from buzzer
Experiment 19: Grove LCD & UPM library

Aim: To display message on Grove LCD panel using UPM library in python

Hardware Components & Services Required:


● Intel Edison with Arduino Expansion Board
● Base shield for Arduino
● USB Cable
● 1x Grove LED Socket Kit v1.5
● 1x Grove LCD RGB Backlight v4.0
● 1x Grove Connector
● 1x USB Type A to Type B Connector Cable

Circuit Connection:
1. Mount the base shield on Intel Edison Arduino Expansion Board
2. Using the power switch on the Base shield put the voltage at the base shield to 5V
3. Connect one end of the Grove connector to I2C Port and other end to Grove LCD
RGB Backlight
4. Connect Intel Edison to Host and wait for It’s flash drive to mount
5. Initiate ssh connection to Intel Edison and write the python program using editor like
nano or vi and run it.

Code:
from time import sleep
import pyupm_i2clcd as lcd

# Initialize Jhd1313m1 at 0x3E (LCD_ADDRESS) and 0x62 (RGB_ADDRESS)


myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62)

myLcd.setCursor(0,0)
# RGB Blue
#myLcd.setColor(53, 39, 249)

# RGB Red
myLcd.setColor(255, 0, 0)

myLcd.write('Hello World')
myLcd.setCursor(1,2)
myLcd.write('Hello World')
sleep(30)

Conclusion: Hence a UPM library in python is used to display a message on LCD panel.
Experiment 20: Grove Temperature sensor & UPM library

Aim: To read temperature value from Grove Temperature Sensor using UPM library in
Python

Hardware Components & Services Required:


● Intel Edison with Arduino Expansion Board
● Base shield for Arduino
● USB Cable
● Grove Temperature Sensor 1.2
● 1x Grove Connector
● 1x USB Type A to Type B Connector Cable

Theory
The Grove - Temperature Sensor uses a Thermistor to detect the ambient temperature. The
resistance of a thermistor will increase when the ambient temperature decreases. It's this
characteristic that we use to calculate the ambient temperature. The detectable range of this
sensor is -40 - 125ºC, and the accuracy is ±1.5ºC

Connection
1. Mount the base shield on Intel Edison Arduino Expansion Board
2. Using the power switch on the Base shield put the voltage at the base shield to 5V
3. Connect one end of the Grove connector to Analog Port A0 and other end to Grove
Temperature Sensor
4. Connect Intel Edison to Host and wait for It’s flash drive to mount
5. Make ssh connection to Intel Edison, write the python program and run it.

Code:
import time
import pyupm_grove as grove

# Create the temperature sensor object using AIO pin 0


temp = grove.GroveTemp(0)

for i in range(0, 10):


celsius = temp.value()
fahrenheit = celsius * 9.0/5.0 + 32.0;
print "%d degrees Celsius, or %d degrees Fahrenheit" \
% (celsius, fahrenheit)
time.sleep(1)

# Delete the temperature sensor object


del temp

Conclusion: Hence temperature reading from Grove Temperature sensor was displayed on
command prompt using pyupm library.
Experiment 21: LED blinking in python on Intel Edison

Aim: To perform basic experiment of blinking LED on Intel Edison.

Hardware Components & Services Required:


● Intel Edison with Arduino Expansion Board
● USB Cable
● Jumper Wire
● 1 LED
● 1 x 1kΩ Resistor
● Breadboard

Theory:
The MRAA I/O library (or libmraa) is a low-level library that offers a translation from the
General Purpose Input/Output (GPIO) interfaces to the pins available on your board. MRAA
makes it easier for developers and sensor manufacturers to map their sensors and actuators
on top of supported hardware and to allow control of low-level communication protocol by
high-level languages and constructs.

MRAA (pronounced em-rah) is a low-level library written in the C language. The purpose of
MRAA is to abstract the details associated with accessing and manipulating the basic I/O
capabilities of a platforms, such as the Intel® Galileo or Intel® Edison boards, into a single,
concise API.

MRAA serves as a translation layer on top of the Linux General Purpose Input/Outputs
(GPIO) facilities. Although Linux provides a fairly rich infrastructure for manipulating GPIOs,
and its generic instructions for handling GPIOs are fairly standard, it can be difficult to use.
By definition, all platforms vary. They each have different capabilities, pin numbers, and
types of GPIOs. For instance, a GPIO pin may not support the same type of capabilities from
one platform to the next. A pin may not even exist on a given platform. Further, the way in
which GPIOs are configured on a platform depends on various factors. For instance, using a
GPIO pin in one mode may preclude using another pin in another mode, or in using another
pin at all. Therefore, MRAA makes developing programs less complicated because it can be
used along with other software to create platform-independent code.

Note: Although MRAA can be used to write platform-independent code, developers are still
responsible for ensuring that code is robust enough to accommodate the various limitations
of the platforms it may run on.

Circuit Connection:
● Connect the anode of LED to Pin 8 of Intel Edison and cathode of Intel Edison to
ground in series with 1kΩ resistor.
● Connect Intel Edison to Host and wait for It’s flash drive to mount
● Make ssh connection to Intel Edison and write the python program and run it to see
the LED blink.
Code:
import mraa
import time

led = mraa.Gpio(8)
led.dir(mraa.DIR_OUT)
print "Starting.."
while True:
print "Blink"
led.write(1)
time.sleep(1)
led.write(0)
time.sleep(1)

Conclusion: Hence in this way LED blinking in python was done successfully on Intel
Edison.
Experiment 22: MQTT Communicating using RSMB(Really Simple Message Broker)

Aim: To study and implement the communication between two Intel Edison devices using
default RSMB Broker.

Hardware Components & Services Required:


● 2x Intel Edison Device
● USB cables

Theory
MQTT is a lightweight publish/subscribe messaging protocol. It is useful for use with low
power sensors, but is applicable to many scenarios

The MQTT protocol is based on the principle of publishing messages and subscribing to
topics, or "pub/sub". Multiple clients connect to a broker and subscribe to topics that they are
interested in. Clients also connect to the broker and publish messages to topics. Many
clients may subscribe to the same topics and do with the information as they please. The
broker and MQTT act as a simple, common interface for everything to connect to. This
means that you if you have clients that dump subscribed messages to a database, to Twitter,
Cosm or even a simple text file, then it becomes very simple to add new sensors or other
data input to a database, Twitter or so on.

Messages in MQTT are published on topics. There is no need to configure a topic,


publishing on it is enough. Topics are treated as a hierarchy, using a slash (/) as a separator.
This allows sensible arrangement of common themes to be created, much in the same way
as a filesystem. For example, multiple computers may all publish their hard drive
temperature information on the following topic, with their own computer and hard drive name
being replaced as appropriate:

sensors/COMPUTER_NAME/temperature/HARDDRIVE_NAME

Clients can receive messages by creating subscriptions. A subscription may be to an explicit


topic, in which case only messages to that topic will be received, or it may include wildcards.
Two wildcards are available, + or #.

+ can be used as a wildcard for a single level of hierarchy. It could be used with the topic
above to get information on all computers and hard drives as follows:

sensors/+/temperature/+

Procedure
The Edison OS has been configured to start the RSMB broker automatically. So the default
TCP port 1883 is already used by RSMB. We'll test the mosquitto clients against the rsmb
broker using the default MQTT port.
To test the client, open ssh connection separately on two Intel Edison. In the first connection,
run a mosquitto_sub client that subscribe to a topic called 'test' on the rsmb broker running
remotely on the other Intel Edison. In the second connection run a mosquitto_pub client that
publishes the message ‘Hello World’ on the topic ‘test’ to the local rsmb broker.

Subscriber
$mosquitto_sub -h 172.18.33.88 -t test -v
Publisher
$mosquitto_pub -h localhost -t test -m “Hello World”

In the above case one intel edison is receiving message from another intel edison using
MQTT. Both the Intel Edison have RSMB installed on it by default. So one intel edison has
subscribed to a topic using the address of other intel edison and other intel edison is
publishing to message broker on it’s localhost on the same topic. We can see the ‘Hello
World’ message being sent from one device and being received by another.

Conclusion: Hence MQTT communication using RSMB broker and mosquitto clients was
performed successfully.
Experiment 23: MQTT communication using HiveMQ

Aim: To study and implement MQTT communication on Intel Edison with HiveMQ broker.

Hardware Components & Services Required:


● 2x Intel Edison Device
● USB cables

Theory

MQTT is a protocol and protocols need client implementations. The Eclipse Paho project is
part of the Eclipse Foundation's M2M mission to provide high quality implementations of
M2M libraries and tools. Under the Paho banner, open source client libraries for MQTT are
being curated and developed; there are already MQTT C and Java libraries with Lua,
Python, C++ and JavaScript at various stages of development.

The library implements a client class that can be used to add MQTT support to your Python
program either by creating instances of the client or through inheriting with your own class. It
also provides some helper functions to make publishing one shot messages extremely easy.

Use the standard “pip” tool for installation, either

$ pip install paho-mqtt

To install pip on intel edison


1. Setup the Edison repo by replacing anything you have in the /etc/opkg/base-feeds.conf
file with the following:
src/gz all http://repo.opkg.net/edison/repo/all
src/gz edison http://repo.opkg.net/edison/repo/edison
src/gz core2-32 http://repo.opkg.net/edison/repo/core2-32

2. Setup the IoT repo by running the following commands:


$echo "src intel-iotdk http://iotdk.intel.com/repos/3.0/intelgalactic/opkg/i586" >
/etc/opkg/intel-iotdk.conf

3. Run the following command:


$opkg update

4. Install pip by running the following commands:


$wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate
$python get-pip.py

5. Install setuptools by running the following commands:


$wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py
$python ez_setup.py --insecure

5th step in not needed because in the 4th step setup tool is also installed

mqttpublish.py

import paho.mqtt.client as paho


import time
from random import randint

def on_publish(client, userdata, mid):


print("mid: "+str(mid))

client = paho.Client()
client.on_publish = on_publish
client.connect("broker.mqttdashboard.com", 1883)
client.loop_start()

while True:
temperature = randint(0,9)
print temperature
(rc, mid) = client.publish("encyclopedia/temperature", str(temperature), qos=1)
time.sleep(5)

Client()
The Client() constructor has some optional parameters:

paho.Client(client_id=””, clean_session=True, userdata=None, protocol=paho.MQTTv31)


If you do not specify a client_id, a random id will be generated for you (and clean_session
must be set to True). The userdata parameter can be any value or datatype that you wish
and the data will be passed to all callbacks as the userdata variable.

connect()
client.connect(host=”localhost”, port=1883, keepalive=60, bind_address=””)
The connect() function has some optional parameters as well:
Hopefully these are all obvious with the exception of bind_address, which allows the socket
to be bound to a specific address at the local side of the connection, useful if you have more
than one outgoing interface.

The connect() call blocks until the socket connection is made with the broker, but is
asynchronous afterwards, so once it returns you cannot be sure that the broker has
accepted the connection – the on_connect() callback should be used for this purpose. A
successful connection will result in the rc variable being set to 0, as in the MQTT protocol
specification.

publish()

The publish() call returns a tuple of the function return code and the message id of the
message being published. The message id can be used with the on_publish callback to
determine when a particular message has been published. The client assigns a message id
to all messages internally, even if they are QoS 0.

Staying connected
Once the client is connected, the network traffic between the client and the broker must be
processed. This can be done in one of two ways, either a blocking method or with a
background thread.

client.loop_forever() will block, processing the network traffic and reconnecting automatically
as necessary. This function is most useful if you are only subscribing to the broker and
acting on the messages you receive. It will not return until the client calls disconnect().

client.loop_start() starts a background thread to handle the network traffic and will return
immediately. This is better suited to the situation where you wish to do other tasks in your
program. It is complemented by the client.loop_stop() function, which stops the background
thread.

Finally, you may also use the raw client.loop() function to process the network traffic
manually. If you do this you will need to handle reconnecting yourself, it is recommended to
use one of the previous two methods instead.

Mqttsubscribe.py
import paho.mqtt.client as paho

def on_subscribe(client, userdata, mid, granted_qos):


print("Subscribed: "+str(mid)+" "+str(granted_qos))

def on_message(client, userdata, msg):


print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload))

client = paho.Client()
client.on_subscribe = on_subscribe
client.on_message = on_message
client.connect("broker.mqttdashboard.com", 1883)
client.subscribe("encyclopedia/#", qos=1)

client.loop_forever()

In this example the on_subscribe and on_message callbacks are demonstrated.


on_subscribe is called once the broker has responded to a subscription request. The
granted_qos parameter contains a list of the granted QoS (or failure) codes sent by the
broker. The on_message callback is called for each message received and the msg variable
is an MQTTMessage class, which has members topic, payload, qos, retain and mid. The call
to loop_forever() is blocking, which means the client will continue to print out incoming
message information until the program is killed.

MQTT Qos Levels


http://www.hivemq.com/blog/mqtt-essentials-part-6-mqtt-quality-of-service-levels
Topics and Subscription
https://mosquitto.org/man/mqtt-7.html
References
https://pypi.python.org/pypi/paho-mqtt/1.1
http://www.hivemq.com/blog/mqtt-client-library-paho-python

Conclusion: Hence MQTT communication using external MQTT broker viz HiveMQ was
performed successfully.
Experiment 24: Blinking LED remotely from Web based interface using MQTT and
Websocket protocol

Aim: To study and implement blinking of LED remotely from web interface using MQTT &
Websocket protocol

Hardware Components & Services Required:


● 1x Intel Edison Device
● USB cables

Theory:
WebSocket is a computer communications protocol, providing full-duplex communication
channels over a single TCP connection. The WebSocket protocol was standardized by the
IETF as RFC 6455 in 2011, and the WebSocket API in Web IDL is being standardized by the
W3C.

WebSocket is designed to be implemented in web browsers and web servers, but it can be
used by any client or server application. The WebSocket Protocol is an independent
TCP-based protocol. Its only relationship to HTTP is that its handshake is interpreted by
HTTP servers as an Upgrade request. The WebSocket protocol makes more interaction
between a browser and a web server possible, facilitating the real-time data transfer from
and to the server. This is made possible by providing a standardized way for the server to
send content to the browser without being solicited by the client, and allowing for messages
to be passed back and forth while keeping the connection open. In this way, a two-way
(bi-directional) ongoing conversation can take place between a browser and the server. The
communications are done over TCP port number 80, which is of benefit for those
environments which block non-web Internet connections using a firewall. Similar two-way
browser-server communications have been achieved in non-standardized ways using
stopgap technologies such as Comet.

The WebSocket protocol is currently supported in most major browsers including Microsoft
Edge, Google Chrome, Internet Explorer, Firefox, Safari and Opera. WebSocket also
requires web applications on the server to support it.

Code:
Webmqtt.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"
type="text/javascript"></script>
<script src="http://www.hivemq.com/demos/websocket-client/js/mqttws31.js"
type="text/javascript"></script>
<title>HiveMQ MQTT Websocket Demo App</title>
<script type="text/javascript">
//Using the HiveMQ public Broker, with a random client Id
var client = new Messaging.Client("broker.mqttdashboard.com", 8000, "myclientid_" +
parseInt(Math.random() * 100, 10));

//Gets called if the websocket/mqtt connection gets disconnected for any reason
client.onConnectionLost = function (responseObject) {
//Depending on your scenario you could implement a reconnect logic here
alert("connection lost: " + responseObject.errorMessage);
};

//Gets called whenever you receive a message for your subscriptions


client.onMessageArrived = function (message) {
//Do something with the push message you received
$('#messages').append('<span>Topic: ' + message.destinationName + ' | ' +
message.payloadString + '</span><br/>');
};

//Connect Options
var options = {
timeout: 3,
//Gets Called if the connection has sucessfully been established
onSuccess: function () {
alert("Connected");
},
//Gets Called if the connection could not be established
onFailure: function (message) {
alert("Connection failed: " + message.errorMessage);
}
};

//Creates a new Messaging.Message Object and sends it to the HiveMQ MQTT Broker
var publish = function (payload, topic, qos) {
//Send your message (also possible to serialize it as JSON or protobuf or just use a
string, no limitations)
var message = new Messaging.Message(payload);
message.destinationName = topic;
message.qos = qos;
client.send(message);
}
</script>
</head>
<body>
<button onclick="client.connect(options);">1. Connect</button>
<button onclick="client.subscribe('encyclopedia/temp', {qos: 2}); alert('Subscribed');">2.
Subscribe</button>
<button onclick="publish('Hello Foo !','encyclopedia/temp',2);">3. Publish</button>
<button onclick="client.disconnect();">(4. Disconnect)</button>
<div id="messages"></div>
</body>
</html>
Mqttsubscribe.py

import paho.mqtt.client as paho


import mraa
import time

led = mraa.Gpio(8)
led.dir(mraa.DIR_OUT)
print "Starting.."

def on_subscribe(client, userdata, mid, granted_qos):


print("Subscribed: "+str(mid)+" "+str(granted_qos))

def on_message(client, userdata, msg):


print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload))
print "Blink"
for i in range(0,6):
led.write(1)
time.sleep(1)
led.write(0)
time.sleep(1)

client = paho.Client()
client.on_subscribe = on_subscribe
client.on_message = on_message
client.connect("broker.mqttdashboard.com", 1883)
client.subscribe("encyclopedia/#", qos=1)
client.loop_forever()

The HTML code can be on any device such as desktop computer or mobile.

Conclusion: Hence it is learnt how to control an actuator(LED) remotely from web based
interface using MQTT and Websocket.
Experiment 25: Blink LED using Raspberry Pi

Aim: To blink LED using Raspberry PI GPIO in Python

Hardware Components & Services Required:


● Raspberry Pi 3
● USB cable
● Jumper Wire
● 1 LED
● 1 x 1kΩ Resistor
● Breadboard

Circuit Connection:

Code:

import time
import RPi.GPIO as GPIO ## Import GPIO library
GPIO.setmode(GPIO.BCM) ## Use board pin numbering
GPIO.setup(17, GPIO.OUT) ## Setup GPIO Pin 7 to OUT
while True:
GPIO.output(17,True) ## Turn on GPIO pin 7
time.sleep(1) ## Wait for one second
GPIO.output(17,False) ## Turn off Led
time.sleep(1) ## Wait for one second
Conclusion: Hence familiarity with Raspberry Pi GPIO was developed.
Experiment 26: Reading Analog value on Raspberry Pi using ADS1115 ADC Module

Step 1
Connect the ADC to the Pi as follows:

● ADS1x15 VDD to Raspberry Pi 3.3V


● ADS1x15 GND to Raspberry Pi GND
● ADS1x15 SCL to Raspberry Pi SCL
● ADS1x15 SDA to Raspberry Pi SDA

Step 2
To install from the source on Github connect to a terminal on the Raspberry Pi and run the
following commands:

1. sudo apt-get update


2. sudo apt-get install build-essential python-dev python-smbus git
3. cd ~
4. git clone https://github.com/adafruit/Adafruit_Python_ADS1x15.git
5. cd Adafruit_Python_ADS1x15
6. sudo python setup.py install

Step 3
To run the sample program

1. cd ~/Adafruit_Python_ADS1x15/examples

2. sudo python simpletest.py


Reference
https://learn.adafruit.com/raspberry-pi-analog-to-digital-converters/ads1015-slash-ads1115
Experiment 27: Remotely controlling LED from Blynk App
Aim:
To remotely control LED using Blynk App via Local Blynk server

Theory:
Blynk was designed for the Internet of Things. It can control hardware remotely, it can
display sensor data, it can store data, visualize it and do many other cool things.

There are three major components in the platform:


Blynk App
Blynk Server
Blynk Libraries

Blynk Architecture

Blynk Platform Features


● Similar API & UI for all supported hardware & devices
● Connection to the cloud using:
○ Ethernet
○ WiFi
○ Bluetooth and BLE
○ USB (Serial)
● Set of easy-to-use Widgets
● Direct pin manipulation with no code writing
● Easy to integrate and add new functionality using virtual pins
● History data monitoring via History Graph widget
● Device-to-Device communication using Bridge Widget
● Sending emails, tweets, push notifications, etc.

Requirement for Blynking


● Hardware(Any development board that you can connect to Internet)
● A Smartphone
Installing Blynk Library from Arduino IDE

After installing the Blynk library in Arduino IDE. The default program for Intel Edison to
communicate with Blynk server will be available in File->Examples->
Blynk App Configuration

● Download and Install Blynk App from Google Play


● Create new account by entering the email id and password and selecting local Blynk
server as follows
● After account is created successfully, you will be logged into your account
● Now create a new Project and give it a name.
● Select the appropriate device type and Connection type. After selecting this if you
click create, your project will be created and authentication token for connecting the
Arduino program to Blynk server will be sent to your account email id.
● Now you can add widgets in your project as per your requirements by clicking + on
your Project Dashboard. So you are limited by the total energy balance to add the
widgets in your project.
● To configure a widget just click on it.
● To run your project from the app click on the Play icon in your project dashboard.
● To configure a widget or add new widget come out of running mode.

Note: When you create an account by selecting the Blynk server you get an energy balance
of 2,000 but if you create an account by selecting the Custom(Local) Blynk server then you
get the energy balance of 2,00,000 for adding the widgets.
Conclusion: In this way the principle of remote control via a mobile app was demonstrated.
For our present example we used LED but instead we can use a light bulb or a fan to control
them via an App to do home automation
Experiment 28: Sending Sensor data to IBM Bluemix Cloud in quick start and
registered mode

Aim:
Quickstart Mode
Publish the Grove temperature data from your Intel Edison to the Watson IoT Platform
quickstart service every 5 seconds. You will use NodeRED as the runtime to create a flow
that gets the Grove Temperature data & publish the temperature in the appropriate format to
the quickstart service. Publish the data using the message format {'d' : {'temp' : <Grove
temperature>}}.

Registered Mode

Part 1
This experiment will use the Intel Edison as a gateway, publishing data on behalf of a
temperature sensor .You need to create a new gateway type for your Intel Edison then
register your Edison as a gateway on Watson IoT Platform. You will use the Grove
Temperature Sensor as the remote sensor, so need to create a device type and register the
Grove Temperature Sensor. You will then publish the temperature every 5 seconds.

Part 2
Create a Bluemix application to receive the Grove Temperature data. The flow should also
check to see if the Grove Temperature device data is above or below a specified
temperature (32ºC). If the temperature rises above the specified temperature then send a
command to the device to turn a warning LED on and display message on Grove LCD that
‘Temperature is not safe’, if the temperature is below the specified temperature then send a
command to turn the warning LED off and display message on Grove LCD that ‘Temperature
is safe’. The command should only be sent when the temperature rises to or falls below the
specified temperature - not every time data is received from the device. The temperature
data from the sensor should be output to the debug tab in Bluemix UI.

Solution:

Irrespective of the mode in which we are sending the data to IBM Watson IoT platform (i.e.
Quick Start or Registered) we need to have Node-RED runtime installed on our Intel Edison.

First connect two USB cable to Intel Edison one for powering up the Intel Edison and
another for making serial communication. Use putty to connect serially to Intel Edison. After
getting connected serially, login to Intel Edison and run the command ‘ifconfig’ to find out the
ip address of Intel Edison. This IP address will be used to access Node-RED on any host
machine which is in the same network as that of Intel Edison. It is assumed that Intel Edison
is wirelessly connected to wifi router which has an internet connection.
Steps to install Node-RED on Intel Edison

Step 1: Node-RED is based on Node.js and npm. But in order to get Node-RED running on
Intel Edison we only need to install node-red using npm(node.js package manager) because
latest Linux yocto image comes packaged with node.js and npm.

Step 2: To install Node-RED on intel edison run the following commands

$ npm install -g --unsafe-perm node-red


$ npm install -g --unsafe-perm pm2

This will install node-red and pm2

Pm2 is process manager for Nodejs which can be used to start, stop and auto-start
Node-RED.

Step 3: Start Node-RED using pm2 by entering the following command:

$ pm2 start /usr/bin/node-red --node-args="--max-old-space-size=256"

Step 4: Now you can access Node-RED running on edison by going to following URL on any
host machine connected to same network:

http://<ip_address_of_Intel_Edison>:1880

Step 5: You'd need the Node-RED node called node-red-contrib-grove-edison &


node-red-contrib-ibm-watson-iot to enable Node-RED to talk to Grove Base Shield Pins and
IBM Bluemix Platform respectively. Run following commands to install these nodes.

$ cd ~/.node-red
$ npm install node-red-contrib-grove-edison
$ npm node-red-contrib-ibm-watson-iot

Step 6: To see the new nodes in the flow editor pallet you need to restart Node-Red

$ pm2 restart node-red

Step 7: To get the Node-RED to autostart with the Edison board issue the following
commands

$ mkdir /etc/init.d
$ pm2 save
$ pm2 startup
Now, whenever the Intel Edison is powered up, Node-RED should just get started
automatically.
For Quick Start Mode.

Mount the Grove base shield on Intel Edison and connect Grove Temperature sensor on port
A0 of base shield.

Step 1: Go to http://<ip_address_of_intel_edison>:1880
Step 2: Start creating a flow for publishing environment temperature to Watson IoT platform
in quick start mode. Drag an inject node from left pane and drop it onto the canvas on
Node-RED web interface. Set the duration of Inject node to activate every 5 seconds.
Step 3: Drag the temperature node from left pane which is under the section ‘grove’.
Configure it to use the port A0 on the base shield.
Step 4: Now connect the temperature node to ‘Format Temp’ node which will format the data
received from the temperature node in the correct format so that it can be published on
Watson IoT Platform.
Step 5: Drag IBM Watson Output Node and connect it to ‘Format Temp’ Node and configure
it in Quick Start mode and put the ‘event type’ as ‘event’ and select the format as JSON. If
you click on the link icon displayed beside quickstart id then you will be redirected to Watson
IoT Platform where it will show the temperature data being sent from Grove Temperature
sensor in the form of graph which gets refreshed every 5 seconds due to inject node interval
being set to 5 seconds.

Note: Sending data IBM Watson IoT Platform using Quick Start Mode doesn’t require
registration on IBM Bluemix Platform.

For Registered Mode

Creating a Node-RED Application on IBM Bluemix

Step 1: Create an account on Bluemix by visiting it’s website www.bluemix.net or


www.ibm.com/bluemix

Step 2: After creating the account login to your bluemix account. You will land onto your
dashboard.

Step 3: Select ‘All categories’ and then select ‘Boilerplates’ from ‘Compute and service
offerings’.

Step 4: From Boilerplate select ‘Internet of things platform starter’. Give the application a
name <yourappname> and click ‘Create’. In this way we have created a Node-RED
Application on IBM Bluemix. Now it will show a screen where it show the current status of
the application, information such as whether the application is running or not, how much
memory has been allocated for this application and how many instances of the application is
running etc would be displayed.
Step 5: To start the application click on the start icon. Once the application is running it will
show the status as ‘Your app is running’.

Step 6: Now go to www.<yourappname>.mybluemix.net and click on button ‘Go to your


Node-RED Flow Editor’ Now you will land onto the page where you can create flows for your
application. By default you will have a flow. Select it by dragging the mouse so as to cover
the whole flow and delete it by Clicking on delete button from drop down menu in admin
control button. Now the canvas is empty and you are ready for creating and deploying your
own flow.

Mount the Grove base shield on Intel Edison and connect Grove Temperature sensor on port
A0 of base shield. Connect Grove LED Socket Kit along with an LED to port D3 on Grove
base shield. Connect the Grove LCD to any of the I2C port on Grove base shield.

Before we can send sensor data from Intel Edison using it as a gateway we need to register
both Intel Edison(as a Gateway) and the sensor(as a device).

Registering on Watson IoT Platform

Step1: Go to Node-RED Application’s dashboard and in the connection section select the
‘Internet of Thing Platform’. Now go to ‘Connect your devices’ section and Click on ‘Launch
Dashboard’. You will land on to ‘IBM Watson IoT Platform’ Dashboard.
Step 2: Go to ‘Devices’ section and click on ‘Add Device’.
Step 3: Now select ‘Create Device Type’. You will be given two options ‘Create Device Type’
or ‘Create Gateway Type’. Choose ‘Create Gateway Type’. Enter the ‘Name’ for gateway
type and possibly other optional information and click ‘Finish’. This will create the Gateway
Type
Step 4: Similarly, to create Device Type, select ‘Create Device Type‘ instead of ‘Create
Gateway Type’ and proceed in the same way and a new Device Type will be created.
Step 5: In order to create a Gateway of ‘Gateway Type’ select ‘Add Device’ on the
Dashboard and from the ‘Choose Device Type’ dropdown select the Gateway Type you just
created and next provide the Device Id and authentication token(used for security) and then
click on Finish.
Step 6: Device is also registered the same way as we registered the gateway.

Creating a flow on Intel Edison side to Publish the Temperature event

Go to Node-RED web interface and do the following.

Step 1: Drag the Inject Node and set the interval to 5 seconds.
Step 2: Drag the temperature node on canvas and configure it to receive the temperature
data from port A0 and connect inject node as an input to it.
Step 3: Drag the function node and connect temperature node as an input to it. Write the
javascript code in function node to format the temperature so that Grove Temperature sensor
data can be sent to IBM Watson IoT Platform.
Step 4: Drag the IBM Watson IoT Output Node and connect the function node as an input to
it. Configure the IoT Output Node in ‘Registered Mode’ by providing the Device Type, Device
ID and Authentication Token. This node will now act as a Gateway.

Creating a flow on IBM Bluemix

On IBM Bluemix create the flow for receiving Intel Edison device event and sending the
command back to Intel Edison.

Step 1: Drag the IBM Watson IoT input node on the canvas and configure it to use
Authentication type ‘Bluemix Services’ and Input Type ‘Device Event’.
Step 2: Connect IoT input node to switch node which will forward the JSON message to
respective function node depending on the temperature value i.e. whether it is less than 32
or greater than 32.
Step 3: If temperature is less than 32 then prepare the payload in function node by setting
values for ‘LCD’ and ‘LED parameter i.e. ‘Temp is Safe’ & ‘OFF’ respectively.
Step 4: If temperature is greater than 32 then prepare another payload in the other function
node by setting values for ‘LCD’ and ‘LED’ parameter i.e. ‘Temp is not Safe’ & ‘ON’
respectively.
Step 5: Both the function nodes are connected to JSON Node so as to format it in JSON
format.
Step 6: Connect the JSON Node to RBE node (Report by Exception Node) which will let the
incoming message pass through it only when there is change in the incoming message. This
is used because we don’t want to send the command to Intel Edison every time the event is
received. Command is send only when we want to change the message to be displayed on
LCD and change the LED indication accordingly.
Step 7: Next, the RBE Node is connected to IBM Watson IoT output node which will send
the command to the Intel Edison for taking appropriate action.

Creating a flow on Intel Edison side to receive the command to display the message
on Grove LCD and light the LED

Step 1: In order to receive the command from IBM Bluemix we create a IBM Watson input
node which is connected as Gateway and it subscribes to ‘Gateway Commands’.
Step 2: This IoT Input Node is next connected to LED and LCD function node which take the
respective parameters from the command received from IBM Bluemix and parse it to
prepare the JSON message for Grove LED and LCD node. Depending upon the command
received the Grove LCD will display the message whether temperature is safe or not and
accordingly the LED will glow.

Conclusion: Hence in this way both quick start mode and registered mode to send the
sensor data to IBM Bluemix cloud has been studied.

You might also like