IBC Lecture Week3
IBC Lecture Week3
Biomedical
Computing
1
Overview
• IoT Hardware
– Sensors and Actuators
2
Class Activity
Arduino Programming
3
Tasks
• void setup() {
• // put your setup code here, to run once:
• }
• void loop() {
• // put your main code here, to run
repeatedly:
• }
5
Read a potentiometer/print its state out to the
Arduino Serial Monitor
void setup() {
// initialize serial communication at 9600 bits per
Reads an analog input on pin 0, second:
prints the result to the Serial
Serial.begin(9600);
Monitor. Attach the center pin of a
potentiometer to pin A0, and the }
outside pins to +5V and ground.
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(1); // delay in between reads for stability
} 6
Example 2
int potPin = A0; // Potentiometer wiper connected to
The potentiometer's position is analog pin A0
read as an analog input (ranging int potValue = 0; // Variable to store the potentiometer
from 0 to 1023), which can then be value
used for various applications, such
as adjusting brightness or void setup() {
controlling servo motors. Serial.begin(9600); // Start serial communication at 9600
bps
}
void loop() {
potValue = analogRead(potPin); // Read the
potentiometer value
Serial.println(potValue); // Print the value to the Serial
Monitor
delay(100); // Small delay for readability
}
7
Blink: Turn an LED on and off
• void setup() {
• On the UNO, MEGA and
ZERO, it is attached to • pinMode(LED_BUILTIN, OUTPUT);
digital pin 13, on • }
MKR1000 on pin 6.
• void loop() {
• LED_BUILTIN is set to the
correct LED pin • digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is
independent of which the voltage level)
board is used. • delay(1000); // wait for a second
• digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making
the voltage LOW
• delay(1000);
• }
8
Read a switch, print the state out to the Arduino
Serial Monitor.
// digital pin 2 has a pushbutton attached to it. Give it a name:
• Reads a digital int pushButton = 2;
input on pin 2, prints // the setup routine runs once when you press reset:
the result to the void setup() {
Serial Monitor
Serial.begin(9600);
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
}
void loop() {
// read the input pin:
int buttonState = digitalRead(pushButton);
// print out the state of the button:
Serial.println(buttonState);
delay(1);
} 9
Reading an analog input/print to the Serial Monitor
void setup() {
• Reads an analog input on
pin 0, converts it to Serial.begin(9600);
}
voltage, and prints the
result to the Serial Monitor. void loop() {
// read the input on analog pin 0:
• Attach the center pin of a int sensorValue = analogRead(A0);
potentiometer to pin A0,
and the outside pins to // Convert the analog reading (which goes from 0 -
1023) to a voltage (0 - 5V):
+5V and ground.
float voltage = sensorValue * (5.0 / 1023.0);
Serial.println(voltage);
} 10
11
Bridging Physical and Digital
12
Cont..
13
SENSORS
18
Accelerometers
The Remote uses an accelerometer to detect rotation; the WiiMotionPlus adds a gyroscope for more
accurate movement detection—this is used in many sports games
20
Activity tracking
21
ACTUATORS
23
Wireless Sensor Networks (WSN)
24
Cont.
26
Structure of IoT-WSNs
The components of IoT-WSN are:
• Sensor field: A sensor field is like a coverage area such as a forest, ocean,
home, etc., in which sensors are deployed in a distributed manner.
• Sensor node: This is a miniature machine or IoT device that contains
following components: transceiver, power source, microcontroller, sensing
unit, and processor. IoT devices collect, process, and record all the data
traffic that is communicated through the whole network.
• Sink: The sink is the point where every IoT device forwards the collected
healthcare data, which is later aggregated in order to start communication
with the sink station.
• Base station: It provides all the services to the user according to their
requirements. It manages all the communication tasks between the sensor
nodes or IoT devices.
27
Cont.
28
Characteristics of IoT-WSNs
• Scalability: Sensor networks possess dynamic topology in which we can
either increase or decrease the number of sensor nodes (IoT devices).
• Resilience: IoT-WSNs are highly resilient and provide an immediate service if
any fault or node failure occurs within the network.
• Self-organized: The randomly deployed IoT devices can adjust easily and
work in a cooperative manner. IoT devices may be mobile or static depending
upon whether we are using an ad-hoc network or not.
• Multi-hop communication: Sensor nodes (IoT devices) transmit the data
packets of healthcare systems through the multiple hops present among
sources and destinations.
• Application-oriented: Due to its very nature, IoT-WSNs can be effectively
used for application-oriented problems. The deployment of the IoT devices
done accordingly and its behaviour vary from application to application
29
Challenges of IoT-WSNs
• Real-time operation: Most critical applications of IoT-WSNs deal with real-time environments.
Successful transmission of medical data packets in real time is somewhat difficult. Message
loss by intermediate nodes, congestion, disturbing noise, and other transmission problems
delay the operation of IoT devices. Thus, the delivery of packets cannot be done in time,
which is the main challenge in WSNs.
• Security: Maintaining the security in WSNs is the biggest challenge. IoT networks are
developed in an environment where they can easily be affected by malicious activities. There
should be security methods associated with every sensor node.
• Unreliable communication: All the medical data packets are broadcasted through multiple
hops with connectionless routing protocols for large distances. In this way communication
between nodes is not reliable. Thus, there is a need to use connection-oriented protocols.
• Energy: Maintaining the overall energy of a sensor network is a big challenge. Every sensor
node has its own energy, which is consumed when the node transmits the medical data
packets. If there are large numbers of sensors, then more energy is required. There may be
the case when regular power becomes low or negligible. Thus, there should be technology
that works in the area of energy utilization of IoT-WSNs.
30
Security Concerns in IoT-WSNs
31
Class Activity
32
Tasks
• Problem: Read an analog input pin, map the result, and then use
that data to dim or brighten an LED.
• Algo: Reads an analog input pin, maps the result to a range from
0 to 255 and uses the result to set the pulse width modulation
(PWM) of an output pin. Also prints the results to the Serial
Monitor.
• The circuit: potentiometer connected to analog pin 0. Center pin of
the potentiometer goes to the analog pin.side pins of the
potentiometer go to +5V and ground. LED connected from digital
pin 9 to ground through 220 ohm resistor.
33
Code
• const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
• const int analogOutPin = 9; // Analog output pin that the LED is attached to
• int sensorValue = 0; // value read from the pot
• int outputValue = 0; // value output to the PWM (analog out)
• void setup() {
• Serial.begin(9600);
• }
• void loop() {
• sensorValue = analogRead(analogInPin);
• outputValue = map(sensorValue, 0, 1023, 0, 255); // map it to the range of the analog out:
• analogWrite(analogOutPin, outputValue); // change the analog out value:
• Serial.print("sensor = ");
• Serial.print(sensorValue);
• Serial.print("\t output = ");
• Serial.println(outputValue);
• delay(2);
• }
34
Task 2
35
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() {
• pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT:
• }
• void loop() {
• sensorValue = analogRead(sensorPin); // read the value from the sensor:
• digitalWrite(ledPin, HIGH); // turn the ledPin on
• delay(sensorValue); // stop the program for <sensorValue> milliseconds:
• digitalWrite(ledPin, LOW); // turn the ledPin off:
• delay(sensorValue); // stop the program for <sensorValue> milliseconds:
• }
36