Sensors and Actuator
Understand networking theories and concepts, such as OSI model, TCP/IP protocols, and subnetting
Build logical and abstract thinking
5. Internet of Things
▪ The Internet of Things (IoT) represents the network of physical objects
“Things” that are integrated with sensors, software and other technologies
for the purpose of exchanging data with other devices on the Internet.
6. Sensors
▪ A sensor is a device that detects some type of input from the physical
environment.
▪ The input can be light, heat, motion, pressure or any number of other
environmental phenomena.
8. Actuators
▪ Sensors turn a physical input into an electrical output, while
actuators do the opposite.
▪ Actuators take electrical signals from control modules and turn them
into physical outputs.
LEDs Buzzer DC Fan Servo Motor
9. Actuators: Servo Motor
▪ A servo motor is an electrical device which can push or rotate an
object with great precision.
10. Actuators: Servo Motor
▪ The HBE-ROBONOVA AI 3 is an intelligent robot with an MR-C3024
controller board capable of controlling 32 servo motors simultaneously.
12. Arduino
▪ Arduino is open-source hardware that can be used to develop
embedded systems with open-source software.
▪ Arduino has gained massive popularity among students for making a
working model.
▪ The reasons behind the popularity of Arduino are its low cost,
availability of software, and easy- to-interface possibility.
▪ The Arduino environment has been designed to be easy to use for
beginners who have no software or electronics experience.
13. Arduino
▪ Arduino is used in many educational programs around the world,
particularly by designers who want to easily create prototypes but do
not need a deep understanding of the technical details.
▪ Because it is designed to be used by nontechnical people, the
software includes plenty of example code to demonstrate how to use
the Arduino board.
▪ People already working with microcontrollers are also attracted to
Arduino because of its facility for quick implementation of ideas.
26. Arduino Sketches
▪ A sketch is the name that Arduino uses for a program.
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
27. Arduino Sketches
▪ There are two special functions that are a part of every Arduino
sketch: setup() and loop().
▪ The setup() is called once, when the sketch starts.
▪ It’s a good place to do setup tasks like setting pin modes.
▪ The loop() function is called over and over and is heart of most
sketches.
▪ You need to include both functions in your sketch, even if you don’t
need them for anything.
30. Turning on an LED: Steps
1. Connect breadboard power (+) and ground (-) rails to Arduino 5V
and ground (GND), respectively.
31. Turning on an LED: Steps
2. Plug the LED into two different breadboard rows.
32. Turning on an LED: Steps
3. The cathode (shorter leg) connects to one leg of a resistor of 330Ω,
and the other resistor leg to the ground.
33. Turning on an LED: Steps
4. Wire up the LED anode (longer leg) to the power.
34. Your First Arduino Project: Blinking an LED
▪ Turn an LED on and off every second.
35. Your First Arduino Project: Circuit
▪ Turn an LED on and off every second.
36. Your First Arduino Project: Steps
1. Connect breadboard power (+) and ground (-) rails to Arduino 5V
and ground (GND), respectively.
37. Your First Arduino Project: Steps
2. Plug the LED into two different breadboard rows.
38. Your First Arduino Project: Steps
3. The cathode (shorter leg) connects to one leg of a resistor of 330Ω,
and the other resistor leg to the ground.
39. Your First Arduino Project: Steps
4. Wire up the LED anode (longer leg) to Arduino pin 13.
41. Your First Arduino Project: Blink
You may also load it from File → Examples → 01.Basics → Blink
42. Your First Arduino Project: Code
// Turns an LED on for one second, then off for one second, repeatedly.
// The setup function runs once when you press reset or power the board
void setup() {
// Initialize digital pin LED_BUILTIN (13) as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// The loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED on
delay(1000); // Wait for a second
digitalWrite(LED_BUILTIN, LOW); // Turn the LED off
delay(1000); // Wait for a second
}
43. Your First Arduino Project: Arduino AVR Boards
Go to Tools → Board, and select your board.
44. Your First Arduino Project: Port
Go to Tools → Port, and select the port of the Arduino board.
45. Your First Arduino Project: Verify a Sketch
Click the Verify button to try compiling the sketch and check for errors.
46. Your First Arduino Project: Upload a Sketch
Click the Upload button to program the board with the sketch.
47. Your First Arduino Project: Discussion
▪ The first thing you do is to initialize LED_BUILTIN pin as an output pin
with the line:
pinMode(LED_BUILTIN, OUTPUT);
▪ In the main loop, you turn the LED on with the line:
digitalWrite(LED_BUILTIN, HIGH);
▪ Then you turn it off with the line:
digitalWrite(LED_BUILTIN, LOW);
48. Your First Arduino Project: Discussion
▪ The delay() causes the Arduino to wait for the specified number of
milliseconds before continuing on to the next line.
▪ There are 1000 milliseconds in a second, so the following line creates a
delay of one second.
delay(1000);
▪ Constants are used to make the programs easier to read.
▪ The constant LED_BUILTIN is the number of the pin to which the on-
board LED is connected.
▪ Most boards have this LED connected to digital pin 13.
49. Your First Arduino Project: Alternative Code
// Turns an LED on for one second, then off for one second, repeatedly.
// 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
delay(1000); // Wait for a second
digitalWrite(13, LOW); // Turn the LED off
delay(1000); // Wait for a second
}
63. Photoresistor: Code
int photoresistor = 0; // A variable holds the value of photoresistor
int threshold = 750; //
void setup()
{
Serial.begin(9600); // Start a serial connection with the computer
pinMode(13, OUTPUT); // Set pin 13 as an output pin
}
void loop()
{
photoresistor = analogRead(A0); // Read the brightness of the LED
Serial.println(photoresistor); // Print the value of photoresistor
// If the photoresistor value < threshold turn the light on, otherwise turn it off
if (photoresistor < threshold)
digitalWrite(13, HIGH); // Turn on the LED
else
digitalWrite(13, LOW); // Turn off the LED
delay(100); // Short delay
}
65. Read Analog Voltage
▪ The microcontroller of the board has a circuit inside called an
analog-to-digital converter (ADC) that reads this changing voltage
and converts it to a number between 0 and 1023.
▪ The ADC in Arduino is 10-bit.
0 0 0 0 0 0 0 0 0 0 0V
1 1 1 1 1 1 1 1 1 1 5V
66. Read Analog Voltage
▪ The analogRead() returns a number between 0 and 1023 that is
proportional to the amount of voltage being applied to the pin.
▪ To scale the numbers between 0 and 5, divide 5 by 1023 and multiply that
by sensorValue :
voltage = sensorValue * (5.0 / 1023.0);
67. Closed-Loop vs. Open-Loop Control Systems
▪ An open-loop control system does not monitor the output to determine
what adjustments to make to the input.
▪ For example, when using a clothes dryer, you might set the timer on the
dryer to run the drying cycle for one hour.
▪ At the end of the hour, the dryer will stop.
▪ The level of dryness of the clothes will vary depending upon their level of
wetness at the beginning of the cycle.
Controller Process
Input Output
68. Closed-Loop vs. Open-Loop Control Systems
▪ In a closed-loop control system, the output is measured to determine
whether it is the desired output and adjust the input as appropriate.
▪ For example, if the clothes dryer is equipped with moisture sensors, the
input may be a level of dryness that adjusts the cycle by extending the
drying time until the sensors indicate the clothes are dried.
Controller Process
Sensor
Input Output
Error
69. Appendix 1: SparkFun Inventor's Kit (SIK)
▪ Go to https://www.sparkfun.com/sikcode and download the examples.
70. Appendix 2: Arduino Reference
▪ Go to https://www.arduino.cc/reference/en/ to learn Arduino basics.