Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Workshops On Designing Electronic Toys #9

Hirotaka Nakajima
June 03, 2014
130

Workshops On Designing Electronic Toys #9

Hirotaka Nakajima

June 03, 2014
Tweet

More Decks by Hirotaka Nakajima

Transcript

  1. 5IFTFTMJEFTBSFDPQZSJHIU˜)JSPUBLB/BLBKJNB3FEJTUSJCVUFBOEEJTDMPTVSFPGUIFTFTMJEFTBSFOPUQFSNJUUFEXJUIPVUQFSNJTTJPOT ,FJP6OJWFSTJUZJTMJDFOTFECZJUTDPQZSJHIUIPMEFST Final Project 4 • According to Syllabus:
 It

    is mandatory to present/demonstrate your masterpiece (electronic gadget) with written reports. ! • Electronic Gadget • Must have some sensor • Report • Written reports • Circuit Diagram
  2. 5IFTFTMJEFTBSFDPQZSJHIU˜)JSPUBLB/BLBKJNB3FEJTUSJCVUFBOEEJTDMPTVSFPGUIFTFTMJEFTBSFOPUQFSNJUUFEXJUIPVUQFSNJTTJPOT ,FJP6OJWFSTJUZJTMJDFOTFECZJUTDPQZSJHIUIPMEFST Serial Communication 8 • Way to communicate between

    PCs • Wireless LAN • Ethernet • Serial: Most basic / old network • Serial (RS-232C, UART) • Simple pin assign (Tx / Rx / GND) • end-to-end communication • Very slow
 (max 115,200 bps, e.g. WiFi 54Mbps = 54000kbps)
  3. 5IFTFTMJEFTBSFDPQZSJHIU˜)JSPUBLB/BLBKJNB3FEJTUSJCVUFBOEEJTDMPTVSFPGUIFTFTMJEFTBSFOPUQFSNJUUFEXJUIPVUQFSNJTTJPOT ,FJP6OJWFSTJUZJTMJDFOTFECZJUTDPQZSJHIUIPMEFST Serial in Arduino 9 • Atmega 328p has

    UART(≒Serial) interface • RX (pin2), TX (pin3) (Check with pin mapping)
 http://arduino.cc/en/Hacking/PinMapping168 • Connect RX to TX, TX to RX • 328 TX -> AE-UW232R RxD • 328 RX -> AE-UW232R TxD • Use Serial library to setup serial connection • Serial.begin to setup the connection • Serial.println to send the data to PC
  4. 5IFTFTMJEFTBSFDPQZSJHIU˜)JSPUBLB/BLBKJNB3FEJTUSJCVUFBOEEJTDMPTVSFPGUIFTFTMJEFTBSFOPUQFSNJUUFEXJUIPVUQFSNJTTJPOT ,FJP6OJWFSTJUZJTMJDFOTFECZJUTDPQZSJHIUIPMEFST LED3 11 • Send the data to PC

    through serial • http://web.sfc.keio.ac.jp/~takefuji/led3.tar ! • If you have done, draw diagram • AE-UM232R fritzing data
 http://www.densikit.com/home/fritzing
  5. 5IFTFTMJEFTBSFDPQZSJHIU˜)JSPUBLB/BLBKJNB3FEJTUSJCVUFBOEEJTDMPTVSFPGUIFTFTMJEFTBSFOPUQFSNJUUFEXJUIPVUQFSNJTTJPOT ,FJP6OJWFSTJUZJTMJDFOTFECZJUTDPQZSJHIUIPMEFST 12 int ledPin=8; int sensorPin = A0; int

    sensorValue = 0; ! void setup(){ pinMode(ledPin, OUTPUT); Serial.begin(9600); } ! void loop(){ sensorValue = analogRead(sensorPin); if(sensorValue>250){ digitalWrite(ledPin, 0); } else { digitalWrite(ledPin,1); } Serial.println(sensorValue,DEC); delay(1000); }
  6. 5IFTFTMJEFTBSFDPQZSJHIU˜)JSPUBLB/BLBKJNB3FEJTUSJCVUFBOEEJTDMPTVSFPGUIFTFTMJEFTBSFOPUQFSNJUUFEXJUIPVUQFSNJTTJPOT ,FJP6OJWFSTJUZJTMJDFOTFECZJUTDPQZSJHIUIPMEFST LED3’ 13 • LED is turned on if

    the sensor value is > 250 • It works with specific LED but not works mine (for example) • Threshold should be based on the environment • Sensor LED data several times • Determine the threshold ! • Let’s change the program!