Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ubiquitous Computing Practice (Photo Resistor) Youn-Hee Han, In-Seok Kang {yhhan, Laboratory of Intelligent Networks Advanced Technology.

Similar presentations


Presentation on theme: "Ubiquitous Computing Practice (Photo Resistor) Youn-Hee Han, In-Seok Kang {yhhan, Laboratory of Intelligent Networks Advanced Technology."— Presentation transcript:

1 Ubiquitous Computing Practice (Photo Resistor) Youn-Hee Han, In-Seok Kang {yhhan, iseka}@koreatech.ac.kr Laboratory of Intelligent Networks Advanced Technology Research Center Korea University of Technology http://link.koreatech.ac.kr

2 / 24 Introduction PhotoResistor LED 밝기 조절 Processing 를 이용한 Graph 2 Contents

3 / 24 PhotoResistor ( Cadmium sulfide or Light dependent resistor ) 빛의 세기에 따라 저항 값이 변하는 센서이다 3 Introduction

4 / 244 Introduction

5 / 245 Introduction http://www.ladyada.net/learn/sensors/cds.html

6 / 246 Introduction

7 / 247 Introduction

8 / 24 PHOTO RESISTOR 8

9 / 249 Photo resistor

10 / 2410 schematic

11 / 2411 Result

12 / 24 Functions analogRead(pin) – analog pin 에서 int (0~1023) 반환 analogWrite(pin, val) – val(0~255) 값 출력 Serial begin(baud) – bits per second  ex)9600, 19200.. print(val) – 시리얼 통신 이용 val 출력  Serial.print(78) gives "78" print(val, format) – val 을 원하는 format 에 맞춰 출력  Serial.print(78, BIN) gives "1001110" 12 Reference

13 / 24 Math map(value, fromLow, fromHigh, toLow, toHigh)  Value 현재 값의 범위 fromLow ~ fromHigh  변경하고 싶은 값의 범위 toLow, toHigh  ex) int val = analogRead(0); val = map(val, 0, 1023, 0, 255); constrain(inputVal, lowRange, highRange)  inputVal 값이 lowRange ~ highRange 사이의 값이면 inputVal 반환  inputVal 값이 lowRange 값 보다 작으면 lowRange 값 반환  inputVal 값이 highRange 값 보다 크면 highRange 값 반환 13 Reference

14 / 2414 센서의 analog 값 출력 Sketch int photocellPin = 0; int photocellReading; void setup(void) { Serial.begin(9600); // bit per second. } void loop(void) { photocellReading = analogRead(photocellPin); Serial.print("Analog reading = "); Serial.println(photocellReading); delay(1000); }

15 / 24 LED 밝기 조절 15

16 / 2416 LED 밝기 조절

17 / 2417 schematic

18 / 2418 LED 밝기 조절 Sketch int lightPin = 0; int ledPin = 11; void setup() { pinMode(ledPin, OUTPUT); } void loop() { int lightLevel = analogRead(lightPin); lightLevel = 1023 – lightLevel; lightLevel = map(lightLevel, 0, 1023, 0, 255); lightLevel = constrain(lightLevel, 0, 255); analogWrite(ledPin, lightLevel); }

19 / 24 PROCESSING 를 이용한 GRAPH Processing 을 이용하여 Graph 를 출력하기 19

20 / 2420 Arduino board

21 / 2421 Arduino - Sketch int photoPin = 0; void setup() { Serial.begin(9600); } void loop() { Serial.println(analogRead(photoPin)); delay(100); }

22 / 2422 Processing - Sketch import processing.serial.*; Serial myPort; // The serial port int xPos = 1; // horizontal position of the graph void setup () { size(400, 300); println(Serial.list()); myPort = new Serial(this, Serial.list()[1], 9600); myPort.bufferUntil('\n'); background(0); } void draw () { }

23 / 2423 Processing - Sketch void serialEvent (Serial myPort) { String inString = myPort.readStringUntil('\n'); if (inString != null) { inString = trim(inString); float inByte = float(inString); inByte = map(inByte, 0, 1023, 0, height); stroke(127,34,255); line(xPos, height, xPos, height - inByte); if (xPos >= width) { xPos = 0; background(0); } else { xPos++; }

24 / 2424 Result


Download ppt "Ubiquitous Computing Practice (Photo Resistor) Youn-Hee Han, In-Seok Kang {yhhan, Laboratory of Intelligent Networks Advanced Technology."

Similar presentations


Ads by Google