You are on page 1of 15

ME 203

MECHATRONICS SYSTEM DESIGN

Lecture 5
KAIST ME
Sensors & Actuators II Fall 2018

(Remote Control)

LEARNING OBJECTIVES

1. Understanding Arduino Sensors


2. Basics of Bluetooth
3. Prepare to build remote controlled car
ARDUINO SENSORS

ARDUINO SENSORS
HALL SENSOR

https://www.youtube.com/watch?v=Scpi91e1JKc

APPLICATION OF HALL EFFECT SENSOR

https://youtu.be/3vF9l3__l_k
GESTURE BASED CONTROL WITH IMU

https://youtu.be/rejZmqRrKMc

COLOR SENSOR

TCS230 (RGB Color Sensor) TCS34725 (RGB Color Sensor)


S2 S3 Color

LOW LOW Red

LOW HIGH Blue

HIGH LOW Clear

HIGH HIGH Green


COLOR SENSING PRACTICE
/* Connect SCL to analog 5, Connect SDA to analog 4, Connect VIN to 3.3V DC, Connect
GND to common ground */
#include <Wire.h>
#include “Adafruit_TCS34725.h”
int redpin = 3; 
int greenpin = 5; 
int bluepin = 6; 
Adafruit_TCS34725 tcs =
Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X); 
void setup() 
{
Serial.begin(9600); 
if (tcs.begin()) Serial.println("Found sensor");
pinMode(redpin, OUTPUT); // For color LED
pinMode(greenpin, OUTPUT); 
pinMode(bluepin, OUTPUT);
}
void loop()
{
uint16_t clear, red, green, blue, lux;
tcs.setInterrupt(false); // turn on LED
delay(60); // takes 50ms to read
tcs.getRawData(&red, &green, &blue, &clear);
tcs.setInterrupt(false); // turn off LED
lux = tcs.calculateLux(red, green, blue);
int r = map(red, 0, 21504, 0, 255); //21504=1024*50/2.4
int g = map(green, 0, 21504, 0, 255); 
int b = map(blue, 0, 21504, 0, 255); 
analogWrite(redpin, red); 
analogWrite(greenpin, green); 
analogWrite(bluepin, blue); 
}

DEMONSTRATION

https://youtu.be/RHO3bPcbysM
COLOR SORTER

https://www.youtube.com/watch?v=g3i51hdfLaw

ARDUINO ROBOTIC CAR FOLLOWING


COLOR LINE

https://youtu.be/Ze_z15DlWdw
ARDUINO LINE TRACER

if((sensorValue[2] < sensorRef[2]) && (sensorValue[3] < sensorRef[3]))
{
analogWrite(LMOTOR,120); // GO forward
analogWrite(RMOTOR,120);
}
else if(sensorValue[0] < sensorRef[0]) // LOW at Left End Sensor 

SKETCH CODE
{
analogWrite(LMOTOR,20); // Turn left
analogWrite(RMOTOR,120);
}
else if(sensorValue[5] < sensorRef[5]) // LOW at Right End Sensor 
{
analogWrite(LMOTOR,120); // Turn right
const int sensor_pin[6] = {A0,A1,A2,A3,A4,A5}; analogWrite(RMOTOR,20);
const int ir_led = 10; //IR LED }
const int LMOTOR = 5; //For Left Motor else if(sensorValue[1] < sensorRef[1])
const int RMOTOR = 6; //For Right Motor {
const int sensorRef[6]={ 600,600,600,600,600,600}; analogWrite(LMOTOR,50);
int sensorValue[6];  analogWrite(RMOTOR,110);
}
void setup() else if(sensorValue[4] < sensorRef[4])
{ {
Serial.begin(9600); analogWrite(LMOTOR,110);
analogWrite(RMOTOR,50);
pinMode(LMOTOR,OUTPUT); }
pinMode(RMOTOR,OUTPUT); else if(sensorValue[2] < sensorRef[2])
pinMode(ir_led , OUTPUT);  {
analogWrite(LMOTOR,0); analogWrite(LMOTOR,60);
analogWrite(RMOTOR,0); analogWrite(RMOTOR,100);
delay(1000); }
} else if(sensorValue[3] < sensorRef[3])
{
void loop() analogWrite(LMOTOR,100);
{ analogWrite(RMOTOR,60);
digitalWrite(ir_led,HIGH); }
delay(1); else
for(int i=0 ; i<6 ; i++) {
{ analogWrite(LMOTOR,0);
sensorValue[i] = analogRead(sensor_pin[i]);  analogWrite(RMOTOR,0);
} }
digitalWrite(ir_led,LOW);
delay(30);
}
DEMONSTRATION

https://youtu.be/QBgfy6m5g0U

BLUETOOTH
 Its name comes from ‘Harald Blåtand’
 A Near Field Communication (NFC) Standard
 Developed by Ericsson in 1994
 Frequency : 2.4~2.485GHz
- ISM (Industrial, Scientific and Medical band)
2.4~2.48GHz, 5.725~5.875GHz, 24~24.25GHz, 61~61.5GHz, …
ex) WiFi, Bluetooth, RFID, wireless phone, ZigBee and etc.
POWER CLASS AND DISTANCE

CLASS Maximum Power Max. Distance

CLASS 1 100 mW / (20dBm) 100m

CLASS 2 2.5 mW / (20dBm) 10m

CLASS 3 1.0 mW / (20dBm) 1m

CLASS 4 0.5 mW / (20dBm) 50cm

BLUETOOH NETWORK
 piconets
- Master/Slave Model
BLUETOOTH PROTOCOL STACK & PROFILE

Definition of Bluetooth Application for compatibility

HC-06 BLUETOOTH SERIAL MODULE


 Class 2 Slave Bluetooth Module
 Bluetooth v2.0+EDR
 2.4GHz ISM band frequency
 Default baudrate: 9600
Pin Description
 Power supply: 3.3V to 5.5V DC
VCC Supply input 3.3V to 5.5V Input
(Internally, Bluetooth chip uses ‘3.3V’) GND Ground
 Passkey: 1234 Transmit Data (Connect RX line fr
TXD
om other peripheral here)
Receive Data (Connect TX line fro
RXD
m other peripheral here)
AT COMMANDS
AT pings the device (response back “OK”over serial)
AT+PINxxx
AT+NAMExxx
AT+BAUD4 (sets baudrate to 9600 – default rate)
AT+BAUD7 (sets baudrate to 57600)

CHANGING NAME AND PIN


#include <SoftwareSerial.h>
int blueTx=2;
int blueRx=3;
SoftwareSerial mySerial(blueTx, blueRx);
void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
}
void loop()
{
if (mySerial.available())
{
Serial.write(mySerial.read());
}
if (Serial.available())
{
mySerial.write(Serial.read());
}
}
DEMONSTRATION: RC CAR CONTROL

https://youtu.be/kewza7RyKMQ

EXAMPLE OF BLUETOOTH CONTROL


#include <SoftwareSerial.h> void forward(){
#define LEFT_A1 4 digitalWrite(LEFT_A1, HIGH);
#define LEFT_B1 5 digitalWrite(LEFT_B1, LOW);
#define RIGHT_A2 6 digitalWrite(RIGHT_A2, HIGH);
#define RIGHT_B2 7 digitalWrite(RIGHT_B2, LOW);
#define BLUE_TX 2 }
#define BLUE_RX 3 void backward(){
SoftwareSerial mySerial(BLUE_TX, BLUE_RX); digitalWrite(LEFT_A1, LOW);
char value; digitalWrite(LEFT_B1, HIGH);
digitalWrite(RIGHT_A2, LOW);
void setup() digitalWrite(RIGHT_B2, HIGH);
{ }
Serial.begin(9600); void left(){
mySerial.begin(9600); digitalWrite(LEFT_A1, LOW);
pinMode(LEFT_A1, OUTPUT); digitalWrite(LEFT_B1, HIGH);
pinMode(RIGHT_A2, OUTPUT); digitalWrite(RIGHT_A2, HIGH);
pinMode(LEFT_B1, OUTPUT); digitalWrite(RIGHT_B2, LOW);
pinMode(RIGHT_B2, OUTPUT); }
} void right(){
void loop() { digitalWrite(LEFT_A1, HIGH);
while(mySerial.available()) digitalWrite(LEFT_B1, LOW);
{ digitalWrite(RIGHT_A2, LOW);
value = mySerial.read(); digitalWrite(RIGHT_B2, HIGH);
if(value == 'l') left(); }
else if(value == 'r') right(); void stop(){
else if(value == 'f') forward(); digitalWrite(LEFT_A1, LOW);
else if(value == 'b') backward(); digitalWrite(LEFT_B1, LOW);
else if(value == 's') stop(); digitalWrite(RIGHT_A2, LOW);
} digitalWrite(RIGHT_B2, LOW);
} }
MAKE YOU OWN APP:
HTTP://APPINVENTOR.MIT.EDU

PREVIEW: DRIVE YOUR RC CAR WITH


YOUR ANDROID PHONE

Smart phone
PREVIEW OF NEXT CLASS
We will learn basic machine learning
- background
- necessity
- application area

MID-TERM EXAM
 When: 5~6:30 PM (October 16th, 2018)
Where: classroom
 3 Problems
- 1 design problem
- 2 Concept Quizzes
DESIGN PROBLEM EXAMPLE
You are developing a mobile robot
vacuum cleaner. (A vacuum pump is
wall already installed in a robot.) There
are a 4-legged wooden table, a
glass vase and a charging station
dock in the room. A corner of the
room is lower with threshold for shoe
removal place. The robot should clean
wall the floor without collision to other
objects. After cleaning, the robot
should return to the station dock and
Charging station dock make exact ‘plug-in’ for charging.

1. Design your own mobile robot based on what you have learned in the classes. Describe what kinds
of actuators, sensors, electronic components and IO board connections will be used in your robot.
2. Describe your strategy for cleaning the room with a flow chart.
3. Describe ‘excellency’ of your robot.

CONCEPT QUIZ EXAMPLE


1. What is difference between ‘pooling’ and ‘timer interrupt’?
2. What is pull-up resistor?
What is purpose of using pull-up resistor?
3. What is difference between PWM(pulse width modulation) and Analog Output?
What is similarity of PWM and Analog Output?
4. Timer Interrupt Frequency is defined as
Interrupt frequency (Hz) = Clock Frequency(Hz)/(prescaler x value of output compare register)

What is ‘prescaler’ and why is it used?


5. IR sensors detect ‘proximity’ and ‘distance’ between sensor and external object.
But ‘IR’ sensor is hard to be used in real vehicles. Describe why.

You might also like