FSIoT Chapter3
FSIoT Chapter3
MACHINE-TO-MACHINE
COMMUNICATIONS
Machine-to-Machine
Communications
What is Machine to Machine (M2M)
communication?
Interaction between two or more entities (machines) on a
network, to exchange information and perform actions.
IoT is known as the Internet of Things where things are said to be the
communicating devices that can interact with each other using a
communication media.
Usually, every day some new devices are being integrated which uses IoT
devices for its function.
These devices use various sensors and actuators for sending and receiving
data over the internet.
M2M is communication could carry over mobile networks, for ex- GSM-
GPRS, CDMA EVDO Networks .
void loop() {
digitalWrite(13, HIGH); // Turn the LED on
delay(1000); // Wait for one second
digitalWrite(13, LOW); // Turn the LED off
delay(1000); // Wait for one second
}
In this program:
o The setup() function configures pin 13 as an output (connected to the
built-in LED).
o The loop() function turns the LED on and off every second by using the
digitalWrite() and delay() functions.
Arduino Programming Basics
1. Data Types
o Arduino uses common programming data types such as:
int (integer): Used for whole numbers.
float: Used for decimal numbers.
boolean: True or false values.
char: Single characters.
2. Variables
o You can define variables to store data and use them in your program. For example:
int ledPin = 13; // Assign pin 13 to the variable ledPin
3. Control Structures
o Arduino programming supports common control structures like:
if, else, while, for, and switch statements to control the flow of the program.
Example of an if statement:
if (sensorValue > threshold) {
digitalWrite(ledPin, HIGH); // Turn on the LED if
the sensor value is above the threshold
} else {
digitalWrite(ledPin, LOW); // Otherwise, turn it
off
}
4. Functions
o Functions are blocks of code designed to perform specific tasks. The two main functions
(setup() and loop()) are essential in Arduino, but you can create your own functions
to simplify your program.
Example:
void turnOnLED() {
digitalWrite(13, HIGH);
}
5. Libraries
o Libraries are collections of pre-written code that extend the functionality of Arduino. For
example, if you’re working with sensors like the DHT11 temperature sensor or controlling
motors, you can use specific libraries to make programming easier.
o To include a library:
#include <DHT.h> // Include the DHT sensor library
Working with Inputs and Outputs
1. Digital I/O
o Digital pins on an Arduino can either be inputs (reading data from sensors) or outputs (sending data to devices like LEDs
or motors).
o To read or write digital values, you use the following functions:
digitalRead(pin): Reads the value from a specified digital pin (HIGH or LOW).
digitalWrite(pin, value): Sets the specified digital pin to HIGH or LOW.
2. Analog I/O
o Analog pins can be used to read analog sensors like temperature sensors, light sensors, etc.
o The analogRead(pin) function reads the voltage on a specified analog pin and returns a value between 0 and 1023
(for a 10-bit resolution).
o The analogWrite(pin, value) function (on supported pins) outputs a PWM (pulse-width modulation) signal
between 0 and 255 to control devices like LEDs or motors.
Example:
int sensorValue = analogRead(A0); // Read the value from sensor connected to analog
pin A0
Common Arduino Projects and Applications
1. Blinking LEDs
o One of the first projects is blinking an LED, as seen in the example program. You can use
external LEDs or the built-in one on pin 13.
2. Reading Sensor Data
o Using sensors like temperature, humidity, or light sensors, you can collect data and use it to
control outputs. For instance, turning on a fan if the temperature exceeds a threshold.
3. Controlling Motors
o Arduino can control various types of motors such as DC motors, servos, and stepper
motors, which are essential for robotics projects.
4. Internet of Things (IoT) Projects
o By integrating Arduino with modules like the ESP8266 or ESP32, you can create IoT
projects, enabling your devices to connect to the internet and interact remotely.
Debugging and Serial Communication
Arduino has a serial monitor tool that allows you to send and receive data from the Arduino to
your computer, which is useful for debugging.
void setup() {
Serial.begin(9600); // Start the serial communication at 9600
baud
}
void loop() {
Serial.println("Hello, Arduino!"); // Print a message to the
serial monitor
delay(1000); // Wait for a second
}
Integration of Sensors and Actuators with Arduino
Arduino offers an easy-to-use platform for integrating sensors and actuators to
build various interactive and automated projects.
By reading data from sensors (input devices) and controlling actuators (output
devices), you can develop projects ranging from simple environmental
monitoring systems to complex robotics.
Sensors
Sensors are devices that detect changes in the environment and send information to the Arduino.
This information can be used to make decisions and control the actuators accordingly.
Common Types of Sensors
1. Temperature Sensors – Measure ambient temperature (e.g., DHT11, LM35, DS18B20).
2. Light Sensors – Measure the intensity of light (e.g., LDR (Light Dependent Resistor)).
3. Ultrasonic Sensors – Measure distance using sound waves (e.g., HC-SR04).
4. Motion Sensors – Detect movement (e.g., PIR (Passive Infrared) sensor).
5. Gas Sensors – Measure the presence of gases like carbon monoxide (e.g., MQ-2, MQ-7).
6. Humidity Sensors – Measure moisture in the air (e.g., DHT11, DHT22).
Actuators
Actuators are devices that take action in response to input data from sensors. They
convert electrical signals into mechanical movement, sound, or light. Examples
include motors, lights, and displays.
Common Types of Actuators
1. Motors – Move objects (e.g., DC motors, servo motors, stepper motors).
2. LEDs – Light up to indicate status or provide feedback.
3. Relays – Switch higher power devices like fans, lights, and home appliances.
4. Buzzer – Produce sound for alarms or notifications.
5. Displays – Show information (e.g., LCD displays, 7-segment displays).
Steps to Integrate Sensors and Actuators with Arduino
1. Connecting Sensors
o Sensors are connected to Arduino’s analog or digital pins depending on their
nature. Analog sensors output continuous signals (e.g., temperature sensors),
while digital sensors output discrete signals (e.g., PIR motion sensors).
o Arduino reads sensor data using the analogRead() or digitalRead()
functions.
2. Connecting Actuators
o Actuators are typically connected to digital pins and controlled using the
digitalWrite() function for simple devices (e.g., LEDs or buzzers). For
more complex actuators like motors, the analogWrite() function (PWM)
may be used to vary the power.