SlideShare a Scribd company logo
1 of 74
Download to read offline
1 / 74
Sensors & Actuators
SelectedI/OsEueung Mulyana
https://eueung.github.io/012017/inout
CodeLabs | Attribution-ShareAlike CC BY-SA
Outline
Preparation
Light/Laser Sensor
PIR Sensor
LM35 & DHT11
Processing & Local Visualization
Ultrasonic Sensor
2 / 74
Preparation
3 / 74
Preparation Notes
We reuse the previous nRF24L01+ example (Simple Remote Control) with some changes i.e.:
for simplicity both nodes are now Nano-based, an LCD is attached to Node-2 for a better
communication and debugging experience.
In the next examples, the switch will be replaced with laser and PIR
sensors.
4 / 74
5 / 74
I2C LCD1602
An LCD display that can display a max
of 16x2 characters.
As the pin resources of ucontroller is limited, your project may
be not able to use normal LCD shield after connected with a
certain quantity of sensors/actuators i.e. if you are doing more
than a simple project, you may be out of pins using a normal
LCD shield. With this I2C interface LCD module, you only need 2
lines (I2C) to display information.
Interface: connect the I2C LCD1602 to the I2C port of Arduino
(SDA - A4 and SCL - A5) and power this module with 5V.
Ref: arduino-info, elecrow
Node-1 & Node-2 (Both with nRF24L01+) 6 / 74
Node-1 (Remote Switch / Sensor Node) 7 / 74
Node-2 (Display Node) 8 / 74
Node-1 9 / 74
Node-2 10 / 74
Install I2C LiquidCrystal Library 11 / 74
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
RF24 myRadio (7, 8);
const int SW1 = 5;
const int SW2 = 6;
byte addresses[][6] = {"1Node"};
int dataTransmitted;
int button1;
int button2;
void setup()
{
pinMode(SW1, INPUT);
pinMode(SW2, INPUT);
button1 = 0;
button2 = 1;
dataTransmitted = 10;
Serial.begin(115200);
delay(1000);
myRadio.begin();
myRadio.setRetries(0,15);
myRadio.setChannel(108);
myRadio.setPALevel(RF24_PA_MAX);
myRadio.openWritingPipe( addresses[0]);
delay(1000);
}
void loop()
{
int newButton = digitalRead(SW1);
if (newButton != button1) {
button1 = newButton;
if (button1 == HIGH){
dataTransmitted = 20;
} 12 / 74
Node-1
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
RF24 myRadio (7, 8);
byte addresses[][6] = {"1Node"};
int dataReceived;
const int LED = 2;
#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>
LiquidCrystal_PCF8574 lcd(0x27);
int lcdexist;
unsigned long started_waiting_at = 0;
bool bklight = false;
void setup()
{
pinMode(LED, OUTPUT);
Serial.begin(115200);
delay(1000);
myRadio.begin();
myRadio.setAutoAck(1);
myRadio.setChannel(108);
myRadio.setPALevel(RF24_PA_MAX);
myRadio.openReadingPipe(1, addresses[0]);
myRadio.startListening();
Wire.begin();
Wire.beginTransmission(0x27);
lcdexist = Wire.endTransmission();
lcd.begin(16, 2);
}
void loop()
{
13 / 74
Node-2
Switch ON 14 / 74
Switch OFF 15 / 74
Light/Laser Sensor
16 / 74
Laser Mini Transmitter & Receiver Module 17 / 74
Light/Laser Receiver Module
Utilizing LDR and Voltage Comparator for Digital Output
18 / 74
19 / 74
LDR
LDR or Light Dependent Resistor (sometimes called
a photoresistor or photocell) is a two-terminal,
resistive component that increases or decreases its
resistance depending on the light it senses. An LDR
initially has a very high resistance. But, as light falls
on it, the resistance will drop, allowing more current
through.
Ref: Earthshine Design
20 / 74
LDR Sensor Module
LDR sensor module is used to detect the intensity of
light. It might have both analog output pin and
digital output pin labelled as AO and DO
respectively on the board. When there is light, the
resistance of LDR will become low according to the
intensity of light. The greater the intensity of light,
the lower the resistance of LDR. The sensor has a
potentiometer knob that can be adjusted to change
the sensitivity of LDR towards light.
Ref: LDR Sensor Module
Switch Replacement with a Laser Receiver 21 / 74
Switch Replacement with a Laser Receiver 22 / 74
PIR Sensor
23 / 74
24 / 74
PIR Sensor
A PIR (Passive Infra-Red) sensor is an electronic
sensor that measures infrared light radiating from
objects in its eld of view. Normally this type of
sensor would be used as a motion or proximity
sensor. Quite often they are referred to as: PIR,
Motion, Proximity, or Pyroelectric sensor.
The sensor in the PIR detects or "reads" infrared radiation "emitted"
from objects all around us. Each object with a temperature above
absolute zero will radiate infrared, even us humans, and even though we
mere humans cannot see this. Note that the PIR just uses a relatively
simple sensor - it is most de nitely not an IR camera!
Ref: Testing and Playing with PIR sensors @Tweaking4All
Switch Replacement with a PIR Sensor 25 / 74
LM35 & DHT11
26 / 74
LM35 & DHT11 27 / 74
28 / 74
LM35
LM35 is a linear temperature sensor with the output
voltage calibrated in centigrade celsius. 1 degree
celsius makes an output voltage of 10mV. So when
you have room temperature at 22C the LM35 gives
you a voltage of 220mV = 0.22V.
The sensor has only 3 pins: VCC which can be between +4V and +20V,
GND and Vout. Vout has to be connected to one of the analog inputs and
that's all - in most cases.
Ref: connecting an arduino with a LM35 temperature sensor @heliosoph
29 / 74
DHT11
DHT11 is a temperature and humidity sensor with a
calibrated digital signal output.
The DHT11 sensor has four pins. Connect the rst pin on left of sensor
('VCC') to 5V of your board, the second pin ('Data') to a digital pin and
the fourth pin ('GND') to ground. When the connecting cable is shorter
than 20m, a 5K pull-up resistor between the second Pin of sensor and 5V
is recommended.
Ref: DHT11 Temperature and Humidity Sensor Example @arduino.org
Install Library for DHTxx Sensors 30 / 74
float tlm35;
void setup() {
Serial.begin(9600);
//analogReference(INTERNAL);
}
void loop() {
tlm35 = 0.0;
for(int j = 0; j < 10; j++) {
tlm35 += analogRead(A0);
delay(20);
}
tlm35 = tlm35 * 5.0 * 10.0 / 1023.0;
//tlm35 = tlm35 * 1.1 * 10.0 / 1023.0;
Serial.println(tlm35);
}
31 / 74
LM35
#include "DHT.h"
#define DHTPIN 3
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.println(t);
}
32 / 74
DHT11
Local Visualization & UI
Processing
33 / 74
34 / 74
Processing
Processing is a exible software sketchbook and a
language for learning how to code within the
context of the visual arts.
Since 2001, Processing has promoted software literacy within the visual
arts and visual literacy within technology. There are tens of thousands of
students, artists, designers, researchers, and hobbyists who use
Processing for learning and prototyping.
Ref: Processing.org
35 / 74
Processing is an open source language/
development tool for writing programs in other
computers. Useful when you want those other
computers to talk with an Arduino, for instance to
display or save some data collected by the Arduino.
How to Work with Processing?
Write Arduino sketch as usual, except for input/output intended to
be retrieved from or sent to Processing
Write Processing program that receives/sends data from/to
Arduino
If you just want to control an Arduino board from a Processing program,
you may want to use the Arduino Library for Processing.
Ref: Arduino Playground - Processing
Switch Example
Ref: Electronics @Processing.org 36 / 74
int switchPin = 5;
void setup() {
pinMode(switchPin, INPUT);
Serial.begin(9600);
delay(1000);
}
void loop() {
if (digitalRead(switchPin) == HIGH) {
//Serial.println(1);
Serial.write(1);
} else {
//Serial.println(0);
Serial.write(0);
}
delay(100);
}
37 / 74
Arduino
import processing.serial.*;
Serial port;
int val;
String stext;
void setup() {
size(200, 200);
frameRate(10);
port = new Serial(this, "/dev/ttyUSB0", 9600);
}
void draw() {
if (0 < port.available()) {
val = port.read();
}
background(255);
if (val == 0) {
fill(0);
stext = "OFF";
} else {
fill(255,0,0);
stext = "ON";
}
rect(50, 50, 100, 100);
textAlign(CENTER);
textSize(30);
fill(255);
text(stext, 100, 112);
}
38 / 74
Processing
Using Arduino IDE Serial Plotter 39 / 74
Using Arduino IDE Serial Plotter 40 / 74
Controlling a Servo
Ref: Electronics @Processing.org 41 / 74
Micro Servo
Tower Pro SG90 42 / 74
#include <Servo.h>
Servo myservo;
int servoPin = 4;
int val = 0;
void setup() {
myservo.attach(servoPin);
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
val = Serial.read();
}
myservo.write(val);
delay(15);
}
43 / 74
Arduino
import processing.serial.*;
Serial port;
float mx = 0.0;
void setup() {
size(200, 200);
noStroke();
frameRate(10);
port = new Serial(this, "/dev/ttyUSB0", 9600);
}
void draw() {
background(0);
fill(204);
rect(40, height/2-15, 120, 25);
float dif = mouseX - mx;
if (abs(dif) > 1.0) {
mx += dif/4.0;
}
mx = constrain(mx, 50, 149);
noStroke();
fill(255);
rect(50, (height/2)-5, 100, 5);
fill(204, 102, 0);
rect(mx-2, height/2-5, 4, 5);
int angle = int(map(mx, 50, 149, 0, 180));
port.write(angle);
}
44 / 74
Processing
Arduino Built-In Example - Graph 45 / 74
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println(analogRead(A0));
// wait a bit for the analog-to-digital converter
// to stabilize after the last reading:
delay(2);
}
46 / 74
Arduino
import processing.serial.*;
Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph
float inByte = 0;
void setup () {
size(400, 300);
myPort = new Serial(this, "/dev/ttyUSB0", 9600);
myPort.bufferUntil('n');
background(0);
}
void draw () {
stroke(127, 34, 255);
line(xPos, height, xPos, height - inByte);
if (xPos >= width) {
xPos = 0;
background(0);
} else {
xPos++;
}
}
void serialEvent (Serial myPort) {
String inString = myPort.readStringUntil('n');
if (inString != null) {
inString = trim(inString);
inByte = float(inString);
println(inByte);
inByte = map(inByte, 0, 1023, 0, height);
//inByte = map(inByte, 0, 100, 0, height);
}
}
47 / 74
Processing
Circuit & Processing Plot 48 / 74
HC-SR04
Ultrasonic Sensor
49 / 74
50 / 74
Ultrasonic Sensor
HC-SR04 ultrasonic ranging sensor provides 2cm to
400cm of non-contact measurement functionality
with a ranging accuracy that can reach up to 3mm. It
is a very a ordable proximity/distance sensor that
has been used mainly for object avoidance in
various robotics projects.
Each HC-SR04 module includes an ultrasonic transmitter, a receiver and
a control circuit. It has 4 pins: VCC, GND, Trigger and Echo pin.
Install Arduino NewPing Library 51 / 74
Install Processing gra ca Library 52 / 74
NewPing Example 53 / 74
#include <NewPing.h>
#define TRIGGER_PIN 3
#define ECHO_PIN 4
#define MAX_DISTANCE 300
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup() {
Serial.begin(9600);
}
void loop() {
delay(500);
Serial.println(sonar.ping_cm());
}
54 / 74
Arduino
import grafica.*;
import processing.serial.*;
GPlot plot;
int i = 0;
int points = 100;
public float[] values;
Serial myPort;
float inByte = 0;
void setup(){
size (900,450);
myPort = new Serial(this, "/dev/ttyUSB0", 9600);
GPointsArray points1 = new GPointsArray(points);
values = new float[points];
for (i = 0; i < points; i++) {
points1.add(i,0);
values[i]=0;
}
plot = new GPlot(this);
plot.setPos(25, 20);
plot.setDim(750, 310);
plot.setXLim(0, points);
plot.setYLim(0, 310);
plot.setTitleText("Distance");
plot.getXAxis().setAxisLabelText("Sample Time");
plot.getYAxis().setAxisLabelText("cm");
plot.setPoints(points1);
}
void draw() {
background(150);
GPointsArray points1 = new GPointsArray(points);
for (i = 0; i < values.length; i++) { 55 / 74
Processing
Processing Plot with gra ca Library 56 / 74
#include <NewPing.h>
#include <Servo.h>
#define TRIGGER_PIN 3
#define ECHO_PIN 4
#define MAX_DISTANCE 300
Servo myservo;
int servoPin = 5;
int val = 0;
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup() {
myservo.attach(servoPin);
Serial.begin(9600);
}
void loop() {
val = analogRead(A0);
val = map(val, 0, 1023, 0, 180);
myservo.write(val);
//delay(15);
delay(500);
Serial.println(sonar.ping_cm());
}
Rotating SR04 with a Servo - Manually via a Potentiometer 57 / 74
Arduino
#include <NewPing.h>
#include <Servo.h>
#define TRIGGER_PIN 3
#define ECHO_PIN 4
#define MAX_DISTANCE 300
Servo myservo;
int servoPin = 5;
int val = 0;
int lastval = 0;
unsigned long timer;
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup() {
myservo.attach(servoPin);
Serial.begin(9600);
timer = millis();
}
void loop() {
val = analogRead(A0);
val = map(val, 0, 1023, 0, 180);
int dif = val - lastval;
if(abs(dif)>1) {
val = lastval + dif/4;
}
myservo.write(val);
lastval = val;
delay(15);
if((millis()-timer)>500) {
Serial.println(sonar.ping_cm());
timer = millis();
}
}
Rotating SR04 with a Servo - Try this too! 58 / 74
Arduino
HC-SR04 + SG90 59 / 74
SR04 Sonar
Our previous case can be rearranged to make a simple DIY Sonar
(SOund Navigation And Ranging) system.
The following example was modi ed from Dejan Nedelkovski's code.
60 / 74
61 / 74
#include <NewPing.h>
#include <Servo.h>
#define TRIGGER_PIN 3
#define ECHO_PIN 4
#define MAX_DISTANCE 300
Servo myservo;
int servoPin = 5;
const int angle_start = 5;
const int angle_end = 175;
const int delaytime = 20;
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup() {
myservo.attach(servoPin);
Serial.begin(9600);
}
void loop() {
for(int i=angle_start;i<=angle_end;i++){
myservo.write(i);
delay(delaytime);
Serial.print(i);
Serial.print(",");
Serial.print(sonar.ping_cm());
Serial.print(".");
}
for(int i=angle_end;i>angle_start;i--){
myservo.write(i);
delay(delaytime);
Serial.print(i);
Serial.print(",");
Serial.print(sonar.ping_cm());
Serial.print(".");
}
}
62 / 74
Arduino
String distance="";
String data="";
String noObject;
float pixsDistance;
int iAngle, iDistance;
int index1=0;
int index2=0;
final float MAX_DIST = 300;
//-------------------------------------------------
void setup() {
size(1200, 700);
smooth();
myPort = new Serial(this, "/dev/ttyUSB0", 9600);
myPort.bufferUntil('.');
orcFont = loadFont("OCRAExtended-30.vlw");
}
//-------------------------------------------------
void draw() {
float covered_height = height*0.935;
noStroke();
fill(0,4);
rect(0, 0, width, covered_height);
fill(98,245,31);
textFont(orcFont);
drawRadar();
drawLine();
drawObject();
drawText();
}
//-------------------------------------------------
void serialEvent (Serial myPort) {
data = myPort.readStringUntil('.');
data = data.substring(0,data.length()-1);
index1 = data.indexOf(",");
angle= data.substring(0, index1);
distance= data.substring(index1+1, data.length());
63 / 74
Processing
Tools | Create Font 64 / 74
Tools | Create Font 65 / 74
66 / 74
drawRadar()
67 / 74
drawText()
68 / 74
drawRadar()
drawText()
69 / 74
drawLine()
70 / 74
drawObject()
71 / 74
Refs/Resources
72 / 74
Refs/Resources
1. LDR Sensor Module Interface With Arduino
2. Using a Photocell @Adafruit
3. Photoresistor @ElectroSchematics
4. Testing and Playing with PIR sensors @Tweaking4All
5. Arduino Playground - Processing
6. Processing Foundation
7. Electronics - Processing.org
8. Typography, Strings and Drawing Text
9. Arduino library for DHT11DHT22, etc Temp & Humidity Sensors
10. A simple and con gurable plotting library for Processing
11. Clipart - Strain Gauge
73 / 74
74 / 74
ENDEueung Mulyana
https://eueung.github.io/012017/inout
CodeLabs | Attribution-ShareAlike CC BY-SA

More Related Content

What's hot

LinuxCNC 入門簡介
LinuxCNC 入門簡介LinuxCNC 入門簡介
LinuxCNC 入門簡介
roboard
 
Audio led bargraph equalizer
Audio led bargraph equalizerAudio led bargraph equalizer
Audio led bargraph equalizer
douglaslyon
 
8051-mazidi-solution
8051-mazidi-solution8051-mazidi-solution
8051-mazidi-solution
ZunAib Ali
 

What's hot (20)

True stories on the analysis of network activity using Python
True stories on the analysis of network activity using PythonTrue stories on the analysis of network activity using Python
True stories on the analysis of network activity using Python
 
W10: Interrupts
W10: InterruptsW10: Interrupts
W10: Interrupts
 
Lcd module interface with xilinx software using verilog
Lcd module interface with xilinx software using verilogLcd module interface with xilinx software using verilog
Lcd module interface with xilinx software using verilog
 
37471656 interrupts
37471656 interrupts37471656 interrupts
37471656 interrupts
 
LinuxCNC 入門簡介
LinuxCNC 入門簡介LinuxCNC 入門簡介
LinuxCNC 入門簡介
 
Audio led bargraph equalizer
Audio led bargraph equalizerAudio led bargraph equalizer
Audio led bargraph equalizer
 
FPGA Tutorial - LCD Interface
FPGA Tutorial - LCD InterfaceFPGA Tutorial - LCD Interface
FPGA Tutorial - LCD Interface
 
SAS (Secure Active Switch)
SAS (Secure Active Switch)SAS (Secure Active Switch)
SAS (Secure Active Switch)
 
Mobile Development For Arduino 201 - ConnectTech
Mobile Development For Arduino 201 - ConnectTechMobile Development For Arduino 201 - ConnectTech
Mobile Development For Arduino 201 - ConnectTech
 
Digital system design lab manual
Digital system design lab manualDigital system design lab manual
Digital system design lab manual
 
B tech Final Year Projects & Embedded Systems Training
B tech Final Year Projects & Embedded Systems Training B tech Final Year Projects & Embedded Systems Training
B tech Final Year Projects & Embedded Systems Training
 
FINISHED_CODE
FINISHED_CODEFINISHED_CODE
FINISHED_CODE
 
Class8
Class8Class8
Class8
 
8051
80518051
8051
 
codings related to avr micro controller
codings related to avr micro controllercodings related to avr micro controller
codings related to avr micro controller
 
IT6712 lab manual
IT6712 lab manualIT6712 lab manual
IT6712 lab manual
 
8051-mazidi-solution
8051-mazidi-solution8051-mazidi-solution
8051-mazidi-solution
 
Lab 4 marking
Lab 4 markingLab 4 marking
Lab 4 marking
 
A meta model supporting both hardware and smalltalk-based execution of FPGA c...
A meta model supporting both hardware and smalltalk-based execution of FPGA c...A meta model supporting both hardware and smalltalk-based execution of FPGA c...
A meta model supporting both hardware and smalltalk-based execution of FPGA c...
 
8051 Inturrpt
8051 Inturrpt8051 Inturrpt
8051 Inturrpt
 

Similar to selected input/output - sensors and actuators

What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdf
SIGMATAX1
 
INT4073 L07(Sensors and AcutTORS).pdf
INT4073 L07(Sensors and AcutTORS).pdfINT4073 L07(Sensors and AcutTORS).pdf
INT4073 L07(Sensors and AcutTORS).pdf
MSingh88
 
Using Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR LibrariesUsing Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR Libraries
Corrado Santoro
 
Arduino: Analog I/O
Arduino: Analog I/OArduino: Analog I/O
Arduino: Analog I/O
June-Hao Hou
 
Arduino Workshop (3).pptx
Arduino Workshop (3).pptxArduino Workshop (3).pptx
Arduino Workshop (3).pptx
HebaEng
 
Pipeline stalling in vhdl
Pipeline stalling in vhdlPipeline stalling in vhdl
Pipeline stalling in vhdl
Sai Malleswar
 

Similar to selected input/output - sensors and actuators (20)

Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digital
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digital
 
Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdf
 
Direct analog
Direct analogDirect analog
Direct analog
 
INT4073 L07(Sensors and AcutTORS).pdf
INT4073 L07(Sensors and AcutTORS).pdfINT4073 L07(Sensors and AcutTORS).pdf
INT4073 L07(Sensors and AcutTORS).pdf
 
Product catlog
Product catlogProduct catlog
Product catlog
 
CC2500 Wireless Trans-receiver Module
CC2500 Wireless Trans-receiver ModuleCC2500 Wireless Trans-receiver Module
CC2500 Wireless Trans-receiver Module
 
Multi Sensory Communication 2/2
Multi Sensory Communication 2/2Multi Sensory Communication 2/2
Multi Sensory Communication 2/2
 
Iot 101
Iot 101Iot 101
Iot 101
 
Using Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR LibrariesUsing Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR Libraries
 
Arduino
ArduinoArduino
Arduino
 
Arduino
ArduinoArduino
Arduino
 
Arduino: Analog I/O
Arduino: Analog I/OArduino: Analog I/O
Arduino: Analog I/O
 
Arduino Workshop (3).pptx
Arduino Workshop (3).pptxArduino Workshop (3).pptx
Arduino Workshop (3).pptx
 
Pipeline stalling in vhdl
Pipeline stalling in vhdlPipeline stalling in vhdl
Pipeline stalling in vhdl
 
Arduino Programming
Arduino ProgrammingArduino Programming
Arduino Programming
 
Arduino projects &amp; tutorials
Arduino projects &amp; tutorialsArduino projects &amp; tutorials
Arduino projects &amp; tutorials
 
All about ir arduino - cool
All about ir   arduino - coolAll about ir   arduino - cool
All about ir arduino - cool
 
m.tech esd lab manual for record
m.tech esd lab manual for recordm.tech esd lab manual for record
m.tech esd lab manual for record
 

More from Eueung Mulyana

More from Eueung Mulyana (20)

FGD Big Data
FGD Big DataFGD Big Data
FGD Big Data
 
Hyper-Connectivity and Data Proliferation - Ecosystem Perspective
Hyper-Connectivity and Data Proliferation - Ecosystem PerspectiveHyper-Connectivity and Data Proliferation - Ecosystem Perspective
Hyper-Connectivity and Data Proliferation - Ecosystem Perspective
 
Industry 4.0 And Beyond The A.I* For Surviving A Tech-Accelerated World
Industry 4.0 And Beyond The A.I* For Surviving A Tech-Accelerated WorldIndustry 4.0 And Beyond The A.I* For Surviving A Tech-Accelerated World
Industry 4.0 And Beyond The A.I* For Surviving A Tech-Accelerated World
 
Blockchain Introduction
Blockchain IntroductionBlockchain Introduction
Blockchain Introduction
 
Bringing Automation to the Classroom: A ChatOps-Based Approach
Bringing Automation to the Classroom: A ChatOps-Based ApproachBringing Automation to the Classroom: A ChatOps-Based Approach
Bringing Automation to the Classroom: A ChatOps-Based Approach
 
FinTech & Cryptocurrency Introduction
FinTech & Cryptocurrency IntroductionFinTech & Cryptocurrency Introduction
FinTech & Cryptocurrency Introduction
 
Open Source Networking Overview
Open Source Networking OverviewOpen Source Networking Overview
Open Source Networking Overview
 
ONOS SDN Controller - Clustering Tests & Experiments
ONOS SDN Controller - Clustering Tests & Experiments ONOS SDN Controller - Clustering Tests & Experiments
ONOS SDN Controller - Clustering Tests & Experiments
 
Open stack pike-devstack-tutorial
Open stack pike-devstack-tutorialOpen stack pike-devstack-tutorial
Open stack pike-devstack-tutorial
 
Basic onos-tutorial
Basic onos-tutorialBasic onos-tutorial
Basic onos-tutorial
 
ONOS SDN Controller - Introduction
ONOS SDN Controller - IntroductionONOS SDN Controller - Introduction
ONOS SDN Controller - Introduction
 
OpenDaylight SDN Controller - Introduction
OpenDaylight SDN Controller - IntroductionOpenDaylight SDN Controller - Introduction
OpenDaylight SDN Controller - Introduction
 
Mininet Basics
Mininet BasicsMininet Basics
Mininet Basics
 
Android Programming Basics
Android Programming BasicsAndroid Programming Basics
Android Programming Basics
 
Cloud Computing: Overview and Examples
Cloud Computing: Overview and ExamplesCloud Computing: Overview and Examples
Cloud Computing: Overview and Examples
 
Connected Things, IoT and 5G
Connected Things, IoT and 5GConnected Things, IoT and 5G
Connected Things, IoT and 5G
 
NodeMCU with Blynk and Firebase
NodeMCU with Blynk and FirebaseNodeMCU with Blynk and Firebase
NodeMCU with Blynk and Firebase
 
Trends and Enablers - Connected Services and Cloud Computing
Trends and Enablers  - Connected Services and Cloud ComputingTrends and Enablers  - Connected Services and Cloud Computing
Trends and Enablers - Connected Services and Cloud Computing
 
Digital Ecosystems - Connected Services and Cloud Computing
Digital Ecosystems - Connected Services and Cloud ComputingDigital Ecosystems - Connected Services and Cloud Computing
Digital Ecosystems - Connected Services and Cloud Computing
 
Services Convergence - Connected Services and Cloud Computing
Services Convergence - Connected Services and Cloud ComputingServices Convergence - Connected Services and Cloud Computing
Services Convergence - Connected Services and Cloud Computing
 

Recently uploaded

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

selected input/output - sensors and actuators

  • 1. 1 / 74 Sensors & Actuators SelectedI/OsEueung Mulyana https://eueung.github.io/012017/inout CodeLabs | Attribution-ShareAlike CC BY-SA
  • 2. Outline Preparation Light/Laser Sensor PIR Sensor LM35 & DHT11 Processing & Local Visualization Ultrasonic Sensor 2 / 74
  • 4. Preparation Notes We reuse the previous nRF24L01+ example (Simple Remote Control) with some changes i.e.: for simplicity both nodes are now Nano-based, an LCD is attached to Node-2 for a better communication and debugging experience. In the next examples, the switch will be replaced with laser and PIR sensors. 4 / 74
  • 5. 5 / 74 I2C LCD1602 An LCD display that can display a max of 16x2 characters. As the pin resources of ucontroller is limited, your project may be not able to use normal LCD shield after connected with a certain quantity of sensors/actuators i.e. if you are doing more than a simple project, you may be out of pins using a normal LCD shield. With this I2C interface LCD module, you only need 2 lines (I2C) to display information. Interface: connect the I2C LCD1602 to the I2C port of Arduino (SDA - A4 and SCL - A5) and power this module with 5V. Ref: arduino-info, elecrow
  • 6. Node-1 & Node-2 (Both with nRF24L01+) 6 / 74
  • 7. Node-1 (Remote Switch / Sensor Node) 7 / 74
  • 11. Install I2C LiquidCrystal Library 11 / 74
  • 12. #include <SPI.h> #include "nRF24L01.h" #include "RF24.h" RF24 myRadio (7, 8); const int SW1 = 5; const int SW2 = 6; byte addresses[][6] = {"1Node"}; int dataTransmitted; int button1; int button2; void setup() { pinMode(SW1, INPUT); pinMode(SW2, INPUT); button1 = 0; button2 = 1; dataTransmitted = 10; Serial.begin(115200); delay(1000); myRadio.begin(); myRadio.setRetries(0,15); myRadio.setChannel(108); myRadio.setPALevel(RF24_PA_MAX); myRadio.openWritingPipe( addresses[0]); delay(1000); } void loop() { int newButton = digitalRead(SW1); if (newButton != button1) { button1 = newButton; if (button1 == HIGH){ dataTransmitted = 20; } 12 / 74 Node-1
  • 13. #include <SPI.h> #include "nRF24L01.h" #include "RF24.h" RF24 myRadio (7, 8); byte addresses[][6] = {"1Node"}; int dataReceived; const int LED = 2; #include <Wire.h> #include <LiquidCrystal_PCF8574.h> LiquidCrystal_PCF8574 lcd(0x27); int lcdexist; unsigned long started_waiting_at = 0; bool bklight = false; void setup() { pinMode(LED, OUTPUT); Serial.begin(115200); delay(1000); myRadio.begin(); myRadio.setAutoAck(1); myRadio.setChannel(108); myRadio.setPALevel(RF24_PA_MAX); myRadio.openReadingPipe(1, addresses[0]); myRadio.startListening(); Wire.begin(); Wire.beginTransmission(0x27); lcdexist = Wire.endTransmission(); lcd.begin(16, 2); } void loop() { 13 / 74 Node-2
  • 14. Switch ON 14 / 74
  • 17. Laser Mini Transmitter & Receiver Module 17 / 74
  • 18. Light/Laser Receiver Module Utilizing LDR and Voltage Comparator for Digital Output 18 / 74
  • 19. 19 / 74 LDR LDR or Light Dependent Resistor (sometimes called a photoresistor or photocell) is a two-terminal, resistive component that increases or decreases its resistance depending on the light it senses. An LDR initially has a very high resistance. But, as light falls on it, the resistance will drop, allowing more current through. Ref: Earthshine Design
  • 20. 20 / 74 LDR Sensor Module LDR sensor module is used to detect the intensity of light. It might have both analog output pin and digital output pin labelled as AO and DO respectively on the board. When there is light, the resistance of LDR will become low according to the intensity of light. The greater the intensity of light, the lower the resistance of LDR. The sensor has a potentiometer knob that can be adjusted to change the sensitivity of LDR towards light. Ref: LDR Sensor Module
  • 21. Switch Replacement with a Laser Receiver 21 / 74
  • 22. Switch Replacement with a Laser Receiver 22 / 74
  • 24. 24 / 74 PIR Sensor A PIR (Passive Infra-Red) sensor is an electronic sensor that measures infrared light radiating from objects in its eld of view. Normally this type of sensor would be used as a motion or proximity sensor. Quite often they are referred to as: PIR, Motion, Proximity, or Pyroelectric sensor. The sensor in the PIR detects or "reads" infrared radiation "emitted" from objects all around us. Each object with a temperature above absolute zero will radiate infrared, even us humans, and even though we mere humans cannot see this. Note that the PIR just uses a relatively simple sensor - it is most de nitely not an IR camera! Ref: Testing and Playing with PIR sensors @Tweaking4All
  • 25. Switch Replacement with a PIR Sensor 25 / 74
  • 27. LM35 & DHT11 27 / 74
  • 28. 28 / 74 LM35 LM35 is a linear temperature sensor with the output voltage calibrated in centigrade celsius. 1 degree celsius makes an output voltage of 10mV. So when you have room temperature at 22C the LM35 gives you a voltage of 220mV = 0.22V. The sensor has only 3 pins: VCC which can be between +4V and +20V, GND and Vout. Vout has to be connected to one of the analog inputs and that's all - in most cases. Ref: connecting an arduino with a LM35 temperature sensor @heliosoph
  • 29. 29 / 74 DHT11 DHT11 is a temperature and humidity sensor with a calibrated digital signal output. The DHT11 sensor has four pins. Connect the rst pin on left of sensor ('VCC') to 5V of your board, the second pin ('Data') to a digital pin and the fourth pin ('GND') to ground. When the connecting cable is shorter than 20m, a 5K pull-up resistor between the second Pin of sensor and 5V is recommended. Ref: DHT11 Temperature and Humidity Sensor Example @arduino.org
  • 30. Install Library for DHTxx Sensors 30 / 74
  • 31. float tlm35; void setup() { Serial.begin(9600); //analogReference(INTERNAL); } void loop() { tlm35 = 0.0; for(int j = 0; j < 10; j++) { tlm35 += analogRead(A0); delay(20); } tlm35 = tlm35 * 5.0 * 10.0 / 1023.0; //tlm35 = tlm35 * 1.1 * 10.0 / 1023.0; Serial.println(tlm35); } 31 / 74 LM35
  • 32. #include "DHT.h" #define DHTPIN 3 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(9600); dht.begin(); } void loop() { delay(2000); // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float h = dht.readHumidity(); float t = dht.readTemperature(); if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; } Serial.println(t); } 32 / 74 DHT11
  • 33. Local Visualization & UI Processing 33 / 74
  • 34. 34 / 74 Processing Processing is a exible software sketchbook and a language for learning how to code within the context of the visual arts. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology. There are tens of thousands of students, artists, designers, researchers, and hobbyists who use Processing for learning and prototyping. Ref: Processing.org
  • 35. 35 / 74 Processing is an open source language/ development tool for writing programs in other computers. Useful when you want those other computers to talk with an Arduino, for instance to display or save some data collected by the Arduino. How to Work with Processing? Write Arduino sketch as usual, except for input/output intended to be retrieved from or sent to Processing Write Processing program that receives/sends data from/to Arduino If you just want to control an Arduino board from a Processing program, you may want to use the Arduino Library for Processing. Ref: Arduino Playground - Processing
  • 36. Switch Example Ref: Electronics @Processing.org 36 / 74
  • 37. int switchPin = 5; void setup() { pinMode(switchPin, INPUT); Serial.begin(9600); delay(1000); } void loop() { if (digitalRead(switchPin) == HIGH) { //Serial.println(1); Serial.write(1); } else { //Serial.println(0); Serial.write(0); } delay(100); } 37 / 74 Arduino
  • 38. import processing.serial.*; Serial port; int val; String stext; void setup() { size(200, 200); frameRate(10); port = new Serial(this, "/dev/ttyUSB0", 9600); } void draw() { if (0 < port.available()) { val = port.read(); } background(255); if (val == 0) { fill(0); stext = "OFF"; } else { fill(255,0,0); stext = "ON"; } rect(50, 50, 100, 100); textAlign(CENTER); textSize(30); fill(255); text(stext, 100, 112); } 38 / 74 Processing
  • 39. Using Arduino IDE Serial Plotter 39 / 74
  • 40. Using Arduino IDE Serial Plotter 40 / 74
  • 41. Controlling a Servo Ref: Electronics @Processing.org 41 / 74
  • 42. Micro Servo Tower Pro SG90 42 / 74
  • 43. #include <Servo.h> Servo myservo; int servoPin = 4; int val = 0; void setup() { myservo.attach(servoPin); Serial.begin(9600); } void loop() { if (Serial.available()) { val = Serial.read(); } myservo.write(val); delay(15); } 43 / 74 Arduino
  • 44. import processing.serial.*; Serial port; float mx = 0.0; void setup() { size(200, 200); noStroke(); frameRate(10); port = new Serial(this, "/dev/ttyUSB0", 9600); } void draw() { background(0); fill(204); rect(40, height/2-15, 120, 25); float dif = mouseX - mx; if (abs(dif) > 1.0) { mx += dif/4.0; } mx = constrain(mx, 50, 149); noStroke(); fill(255); rect(50, (height/2)-5, 100, 5); fill(204, 102, 0); rect(mx-2, height/2-5, 4, 5); int angle = int(map(mx, 50, 149, 0, 180)); port.write(angle); } 44 / 74 Processing
  • 45. Arduino Built-In Example - Graph 45 / 74
  • 46. void setup() { Serial.begin(9600); } void loop() { Serial.println(analogRead(A0)); // wait a bit for the analog-to-digital converter // to stabilize after the last reading: delay(2); } 46 / 74 Arduino
  • 47. import processing.serial.*; Serial myPort; // The serial port int xPos = 1; // horizontal position of the graph float inByte = 0; void setup () { size(400, 300); myPort = new Serial(this, "/dev/ttyUSB0", 9600); myPort.bufferUntil('n'); background(0); } void draw () { stroke(127, 34, 255); line(xPos, height, xPos, height - inByte); if (xPos >= width) { xPos = 0; background(0); } else { xPos++; } } void serialEvent (Serial myPort) { String inString = myPort.readStringUntil('n'); if (inString != null) { inString = trim(inString); inByte = float(inString); println(inByte); inByte = map(inByte, 0, 1023, 0, height); //inByte = map(inByte, 0, 100, 0, height); } } 47 / 74 Processing
  • 48. Circuit & Processing Plot 48 / 74
  • 50. 50 / 74 Ultrasonic Sensor HC-SR04 ultrasonic ranging sensor provides 2cm to 400cm of non-contact measurement functionality with a ranging accuracy that can reach up to 3mm. It is a very a ordable proximity/distance sensor that has been used mainly for object avoidance in various robotics projects. Each HC-SR04 module includes an ultrasonic transmitter, a receiver and a control circuit. It has 4 pins: VCC, GND, Trigger and Echo pin.
  • 51. Install Arduino NewPing Library 51 / 74
  • 52. Install Processing gra ca Library 52 / 74
  • 54. #include <NewPing.h> #define TRIGGER_PIN 3 #define ECHO_PIN 4 #define MAX_DISTANCE 300 NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); void setup() { Serial.begin(9600); } void loop() { delay(500); Serial.println(sonar.ping_cm()); } 54 / 74 Arduino
  • 55. import grafica.*; import processing.serial.*; GPlot plot; int i = 0; int points = 100; public float[] values; Serial myPort; float inByte = 0; void setup(){ size (900,450); myPort = new Serial(this, "/dev/ttyUSB0", 9600); GPointsArray points1 = new GPointsArray(points); values = new float[points]; for (i = 0; i < points; i++) { points1.add(i,0); values[i]=0; } plot = new GPlot(this); plot.setPos(25, 20); plot.setDim(750, 310); plot.setXLim(0, points); plot.setYLim(0, 310); plot.setTitleText("Distance"); plot.getXAxis().setAxisLabelText("Sample Time"); plot.getYAxis().setAxisLabelText("cm"); plot.setPoints(points1); } void draw() { background(150); GPointsArray points1 = new GPointsArray(points); for (i = 0; i < values.length; i++) { 55 / 74 Processing
  • 56. Processing Plot with gra ca Library 56 / 74
  • 57. #include <NewPing.h> #include <Servo.h> #define TRIGGER_PIN 3 #define ECHO_PIN 4 #define MAX_DISTANCE 300 Servo myservo; int servoPin = 5; int val = 0; NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); void setup() { myservo.attach(servoPin); Serial.begin(9600); } void loop() { val = analogRead(A0); val = map(val, 0, 1023, 0, 180); myservo.write(val); //delay(15); delay(500); Serial.println(sonar.ping_cm()); } Rotating SR04 with a Servo - Manually via a Potentiometer 57 / 74 Arduino
  • 58. #include <NewPing.h> #include <Servo.h> #define TRIGGER_PIN 3 #define ECHO_PIN 4 #define MAX_DISTANCE 300 Servo myservo; int servoPin = 5; int val = 0; int lastval = 0; unsigned long timer; NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); void setup() { myservo.attach(servoPin); Serial.begin(9600); timer = millis(); } void loop() { val = analogRead(A0); val = map(val, 0, 1023, 0, 180); int dif = val - lastval; if(abs(dif)>1) { val = lastval + dif/4; } myservo.write(val); lastval = val; delay(15); if((millis()-timer)>500) { Serial.println(sonar.ping_cm()); timer = millis(); } } Rotating SR04 with a Servo - Try this too! 58 / 74 Arduino
  • 59. HC-SR04 + SG90 59 / 74
  • 60. SR04 Sonar Our previous case can be rearranged to make a simple DIY Sonar (SOund Navigation And Ranging) system. The following example was modi ed from Dejan Nedelkovski's code. 60 / 74
  • 62. #include <NewPing.h> #include <Servo.h> #define TRIGGER_PIN 3 #define ECHO_PIN 4 #define MAX_DISTANCE 300 Servo myservo; int servoPin = 5; const int angle_start = 5; const int angle_end = 175; const int delaytime = 20; NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); void setup() { myservo.attach(servoPin); Serial.begin(9600); } void loop() { for(int i=angle_start;i<=angle_end;i++){ myservo.write(i); delay(delaytime); Serial.print(i); Serial.print(","); Serial.print(sonar.ping_cm()); Serial.print("."); } for(int i=angle_end;i>angle_start;i--){ myservo.write(i); delay(delaytime); Serial.print(i); Serial.print(","); Serial.print(sonar.ping_cm()); Serial.print("."); } } 62 / 74 Arduino
  • 63. String distance=""; String data=""; String noObject; float pixsDistance; int iAngle, iDistance; int index1=0; int index2=0; final float MAX_DIST = 300; //------------------------------------------------- void setup() { size(1200, 700); smooth(); myPort = new Serial(this, "/dev/ttyUSB0", 9600); myPort.bufferUntil('.'); orcFont = loadFont("OCRAExtended-30.vlw"); } //------------------------------------------------- void draw() { float covered_height = height*0.935; noStroke(); fill(0,4); rect(0, 0, width, covered_height); fill(98,245,31); textFont(orcFont); drawRadar(); drawLine(); drawObject(); drawText(); } //------------------------------------------------- void serialEvent (Serial myPort) { data = myPort.readStringUntil('.'); data = data.substring(0,data.length()-1); index1 = data.indexOf(","); angle= data.substring(0, index1); distance= data.substring(index1+1, data.length()); 63 / 74 Processing
  • 64. Tools | Create Font 64 / 74
  • 65. Tools | Create Font 65 / 74
  • 73. Refs/Resources 1. LDR Sensor Module Interface With Arduino 2. Using a Photocell @Adafruit 3. Photoresistor @ElectroSchematics 4. Testing and Playing with PIR sensors @Tweaking4All 5. Arduino Playground - Processing 6. Processing Foundation 7. Electronics - Processing.org 8. Typography, Strings and Drawing Text 9. Arduino library for DHT11DHT22, etc Temp & Humidity Sensors 10. A simple and con gurable plotting library for Processing 11. Clipart - Strain Gauge 73 / 74
  • 74. 74 / 74 ENDEueung Mulyana https://eueung.github.io/012017/inout CodeLabs | Attribution-ShareAlike CC BY-SA