Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. Show all posts

Sunday, June 10, 2018

SG90 / MG90S / MG995 Tutorial

Arduino IDE Reference:

https://www.arduino.cc/en/Reference/servo



Sample Code for Arduino:

GND - GND

Vcc - 5V

Orange - D9




Friday, June 8, 2018

Analog / Digital Sample Code

Sample Code for Arduino using Any Analog / Digital Sensor



Because all analog input sensor use 0-1023 to represent data between 0V - 5V (or 3.3V), digital sensor use threshold level,

these code simply display the value it reads into serial monitor and LCD 1602 I2C display.



Connect

  • Vcc - 5V

  • GND   - GND

  • A0 - A0

  • D0 - D1   (Don't use D0 Pin in Arduino, otherwise "avrdude stk500_getsync() not in sync resp=0x30" error occured)



Code To Display Using Serial Monitor:






Thursday, June 7, 2018

MQ Sensor Sample Code

MQ Sensor Sample Code for Arduino





MQ-2 煙霧氣敏傳感器 (甲烷/液化氣/可燃氣體)

MQ-3 酒精乙醇傳感器模塊 酒精氣敏檢測報警

MQ-4 天然氣、甲烷傳感器模塊

MQ-5 液化氣 天然氣 城市煤氣傳感器模塊 氣體傳感器

MQ-6 丙烷 / 丁烷 / 液化氣傳感器模塊

MQ-7 一氧化碳 / 氣敏傳感器檢測報警模塊

MQ-8 氫氣傳感器檢測報警模塊

MQ-9 一氧化碳 可燃氣體傳感器檢測報警模塊

MQ-135 空氣質量傳感器模塊 有害氣體檢測傳感器報警模塊 空氣污染



Connect

  • Vcc - 5V

  • GND   - GND

  • A0 - A0



Code To Display Using Serial Monitor:






Code To Display Using I2C LCD 1602



Monday, April 16, 2018

I2C Scanner

[pastacode lang="c" manual="%2F%2F%20--------------------------------------%0A%2F%2F%20i2c_scanner%0A%2F%2F%0A%2F%2F%20Version%201%0A%2F%2F%20This%20program%20(or%20code%20that%20looks%20like%20it)%0A%2F%2F%20can%20be%20found%20in%20many%20places.%0A%2F%2F%20For%20example%20on%20the%20Arduino.cc%20forum.%0A%2F%2F%20The%20original%20author%20is%20not%20know.%0A%2F%2F%20Version%202%2C%20Juni%202012%2C%20Using%20Arduino%201.0.1%0A%2F%2F%20Adapted%20to%20be%20as%20simple%20as%20possible%20by%20Arduino.cc%20user%20Krodal%0A%2F%2F%20Version%203%2C%20Feb%2026%202013%0A%2F%2F%20V3%20by%20louarnold%0A%2F%2F%20Version%204%2C%20March%203%2C%202013%2C%20Using%20Arduino%201.0.3%0A%2F%2F%20by%20Arduino.cc%20user%20Krodal.%0A%2F%2F%20Changes%20by%20louarnold%20removed.%0A%2F%2F%20Scanning%20addresses%20changed%20from%200...127%20to%201...119%2C%0A%2F%2F%20according%20to%20the%20i2c%20scanner%20by%20Nick%20Gammon%0A%2F%2F%20http%3A%2F%2Fwww.gammon.com.au%2Fforum%2F%3Fid%3D10896%0A%2F%2F%20Version%205%2C%20March%2028%2C%202013%0A%2F%2F%20As%20version%204%2C%20but%20address%20scans%20now%20to%20127.%0A%2F%2F%20A%20sensor%20seems%20to%20use%20address%20120.%0A%2F%2F%20Version%206%2C%20November%2027%2C%202015.%0A%2F%2F%20Added%20waiting%20for%20the%20Leonardo%20serial%20communication.%0A%2F%2F%0A%2F%2F%0A%2F%2F%20This%20sketch%20tests%20the%20standard%207-bit%20addresses%0A%2F%2F%20Devices%20with%20higher%20bit%20address%20might%20not%20be%20seen%20properly.%0A%2F%2F%0A%0A%23include%20%3CWire.h%3E%0A%0Avoid%20setup()%0A%7B%0AWire.begin()%3B%0A%0ASerial.begin(9600)%3B%0Awhile%20(!Serial)%3B%20%2F%2F%20Leonardo%3A%20wait%20for%20serial%20monitor%0ASerial.println(%22%5CnI2C%20Scanner%22)%3B%0A%7D%0A%0Avoid%20loop()%0A%7B%0Abyte%20error%2C%20address%3B%0Aint%20nDevices%3B%0A%0ASerial.println(%22Scanning...%22)%3B%0A%0AnDevices%20%3D%200%3B%0Afor(address%20%3D%201%3B%20address%20%3C%20127%3B%20address%2B%2B%20)%0A%7B%0A%2F%2F%20The%20i2c_scanner%20uses%20the%20return%20value%20of%0A%2F%2F%20the%20Write.endTransmisstion%20to%20see%20if%0A%2F%2F%20a%20device%20did%20acknowledge%20to%20the%20address.%0AWire.beginTransmission(address)%3B%0Aerror%20%3D%20Wire.endTransmission()%3B%0A%0Aif%20(error%20%3D%3D%200)%0A%7B%0ASerial.print(%22I2C%20device%20found%20at%20address%200x%22)%3B%0Aif%20(address%3C16)%0ASerial.print(%220%22)%3B%0ASerial.print(address%2CHEX)%3B%0ASerial.println(%22%20!%22)%3B%0A%0AnDevices%2B%2B%3B%0A%7D%0Aelse%20if%20(error%3D%3D4)%0A%7B%0ASerial.print(%22Unknown%20error%20at%20address%200x%22)%3B%0Aif%20(address%3C16)%0ASerial.print(%220%22)%3B%0ASerial.println(address%2CHEX)%3B%0A%7D%0A%7D%0Aif%20(nDevices%20%3D%3D%200)%0ASerial.println(%22No%20I2C%20devices%20found%5Cn%22)%3B%0Aelse%0ASerial.println(%22done%5Cn%22)%3B%0A%0Adelay(5000)%3B%20%2F%2F%20wait%205%20seconds%20for%20next%20scan%0A%7D" message="" highlight="" provider="manual"/]

LCD1602 I2C Source Code To Display Serial Input to LCD Output

LCD 1602 I2C Source Code To Display Serial Monitor Input to LCD Output

 

[pastacode lang="c" manual="%23include%20%3CWire.h%3E%20%2F%2F%20Arduino%20IDE%20%E5%85%A7%E5%BB%BA%0A%2F%2F%20LCD%20I2C%20Library%EF%BC%8C%E5%BE%9E%E9%80%99%E8%A3%A1%E5%8F%AF%E4%BB%A5%E4%B8%8B%E8%BC%89%EF%BC%9A%0A%2F%2F%20https%3A%2F%2Fbitbucket.org%2Ffmalpartida%2Fnew-liquidcrystal%2Fdownloads%0A%23include%20%3CLiquidCrystal_I2C.h%3E%0A%0A%2F%2F%20Set%20the%20pins%20on%20the%20I2C%20chip%20used%20for%20LCD%20connections%3A%0A%2F%2F%20addr%2C%20en%2Crw%2Crs%2Cd4%2Cd5%2Cd6%2Cd7%2Cbl%2Cblpol%0ALiquidCrystal_I2C%20lcd(0x27%2C%202%2C%201%2C%200%2C%204%2C%205%2C%206%2C%207%2C%203%2C%20POSITIVE)%3B%20%2F%2F%20%E8%A8%AD%E5%AE%9A%20LCD%20I2C%20%E4%BD%8D%E5%9D%80%0A%0Avoid%20setup()%20%7B%0ASerial.begin(9600)%3B%20%2F%2F%20%E7%94%A8%E6%96%BC%E6%89%8B%E5%8B%95%E8%BC%B8%E5%85%A5%E6%96%87%E5%AD%97%0Alcd.begin(16%2C%202)%3B%20%2F%2F%20%E5%88%9D%E5%A7%8B%E5%8C%96%20LCD%EF%BC%8C%E4%B8%80%E8%A1%8C%2016%20%E7%9A%84%E5%AD%97%E5%85%83%EF%BC%8C%E5%85%B1%202%20%E8%A1%8C%EF%BC%8C%E9%A0%90%E8%A8%AD%E9%96%8B%E5%95%9F%E8%83%8C%E5%85%89%0A%0A%2F%2F%20%E9%96%83%E7%88%8D%E4%B8%89%E6%AC%A1%0Afor(int%20i%20%3D%200%3B%20i%20%3C%203%3B%20i%2B%2B)%20%7B%0Alcd.backlight()%3B%20%2F%2F%20%E9%96%8B%E5%95%9F%E8%83%8C%E5%85%89%0Adelay(250)%3B%0Alcd.noBacklight()%3B%20%2F%2F%20%E9%97%9C%E9%96%89%E8%83%8C%E5%85%89%0Adelay(250)%3B%0A%7D%0Alcd.backlight()%3B%0A%0A%2F%2F%20%E8%BC%B8%E5%87%BA%E5%88%9D%E5%A7%8B%E5%8C%96%E6%96%87%E5%AD%97%0Alcd.setCursor(0%2C%200)%3B%20%2F%2F%20%E8%A8%AD%E5%AE%9A%E6%B8%B8%E6%A8%99%E4%BD%8D%E7%BD%AE%E5%9C%A8%E7%AC%AC%E4%B8%80%E8%A1%8C%E8%A1%8C%E9%A6%96%0Alcd.print(%22HKSTEM.CLUB%22)%3B%0Adelay(1000)%3B%0Alcd.setCursor(0%2C%201)%3B%20%2F%2F%20%E8%A8%AD%E5%AE%9A%E6%B8%B8%E6%A8%99%E4%BD%8D%E7%BD%AE%E5%9C%A8%E7%AC%AC%E4%BA%8C%E8%A1%8C%E8%A1%8C%E9%A6%96%0Alcd.print(%22TEL%3A98511356%22)%3B%0Adelay(8000)%3B%0A%0A%2F%2F%20%E5%91%8A%E7%9F%A5%E4%BD%BF%E7%94%A8%E8%80%85%E5%8F%AF%E4%BB%A5%E9%96%8B%E5%A7%8B%E6%89%8B%E5%8B%95%E8%BC%B8%E5%85%A5%E8%A8%8A%E6%81%AF%0Alcd.clear()%3B%0Alcd.setCursor(0%2C%200)%3B%0Alcd.print(%22Use%20Serial%20Mon%22)%3B%0Alcd.setCursor(0%2C%201)%3B%0Alcd.print(%22Type%20to%20display%22)%3B%0A%7D%0A%0Avoid%20loop()%20%7B%0A%2F%2F%20%E7%95%B6%E4%BD%BF%E7%94%A8%E8%80%85%E6%89%8B%E5%8B%95%E8%BC%B8%E5%85%A5%E8%A8%8A%E6%81%AF%0Aif%20(Serial.available())%20%7B%0A%2F%2F%20%E7%AD%89%E5%BE%85%E4%B8%80%E5%B0%8F%E6%AE%B5%E6%99%82%E9%96%93%EF%BC%8C%E7%A2%BA%E8%AA%8D%E8%B3%87%E6%96%99%E9%83%BD%E6%8E%A5%E6%94%B6%E4%B8%8B%E4%BE%86%E4%BA%86%0Adelay(100)%3B%0A%2F%2F%20%E6%B8%85%E9%99%A4%E8%88%8A%E8%A8%8A%E6%81%AF%0Alcd.clear()%3B%0A%2F%2F%20%E8%AE%80%E5%8F%96%E6%96%B0%E8%A8%8A%E6%81%AF%0Awhile%20(Serial.available()%20%3E%200)%20%7B%0A%2F%2F%20%E5%B0%87%E8%A8%8A%E6%81%AF%E9%A1%AF%E7%A4%BA%E5%9C%A8%20LCD%20%E4%B8%8A%0Alcd.write(Serial.read())%3B%0A%7D%0A%7D%0A%7D" message="" highlight="" provider="manual"/]

Friday, December 22, 2017

光學指紋模塊 ARDUINO 識別鎖 FPM10A Fingerprint Sensor Tutorial

Library

https://github.com/adafruit/Adafruit-Fingerprint-Sensor-Library

 

Tutorial

https://cdn-learn.adafruit.com/downloads/pdf/adafruit-optical-fingerprint-sensor.pdf

https://github.com/adafruit/Adafruit-Fingerprint-Sensor-Library/blob/master/documentation/ZFM-20_Fingerprint_Module.pdf

http://www.instructables.com/id/Arduino-Fingerprint-Lock/

http://blog.sina.com.cn/s/blog_54bf41d30102w33v.html

Tuesday, November 14, 2017

mBlock for Arduino Uno R3


  1. 安裝CH340 / Arduino Driver

  2. 安裝mBlock

  3. 開啟mBlock -> 連接 -> 序列埠 -> COM3 (請自行測試連接埠)

  4. 控制版 -> Arduino UNO

  5. 連接 -> 更新軔體


 

 

mBlock & Arduino
mBlock & Arduino(1)哈囉!LED!
mBlock & Arduino(2)點亮外接 LED
mBlock & Arduino(3)利用按鍵控制 Scratch 貓咪
mBlock & Arduino(4)利用 PWM 模擬類比訊號
mBlock & Arduino(5)可變電阻、ADC 與節拍器
mBlock & Arduino(6)使用蜂鳴器來打節拍
mBlock & Arduino(7)七段顯示器之 HELLO!
mBlock & Arduino(8)光敏電阻、亮度感應器與光線追蹤器
mBlock & Arduino(9)伺服馬達控制
mBlock & Arduino(10)mBlock 2.1.4 與 Arduino IDE
mBlock & Arduino(11)認識紅外線接收與發射
mBlock & Arduino(12)使用超音波感應器測量距離
mBlock & Arduino(13)使用搖桿控制
mBlock & Arduino(14)使用人體動作感應器
mBlock & Arduino(15)認識電晶體與繼電器
mBlock & Arduino(16)控制步進馬達
mBlock & Arduino(17)四位數七段顯示器
mBlock & Arduino(18)74HC595 與七段顯示器
mBlock & Arduino(19)透過網路調節 LED 亮度
mBlock & Arduino(20)探討 Me-Baseboard 與各模組相容性
mBlock & Arduino(21)使用 Me 藍牙模組
mBlock & Arduino(22)使用 Me RGB LED 模組打地鼠
mBlock & Arduino(23)使用 Me 搖桿模組打地鼠
mBlock & Arduino(24)使用 Me 七段顯示器模組計分
mBlock & Arduino(25)實作超音波感應器雷達
mBlock & Arduino(26)Me 動作、光線感應器實作小夜燈
mBlock & Arduino(27)Me 音量感應器實作特效燈
mBlock & Arduino(28)Me 溫度感應器實作降溫器

Thursday, July 6, 2017

Arduino Software Downloads

Main Software:

  1. Arduino IDE  

  2. CH340 for Windows 


 

CH340for Other OS (Windows, MAC, Linux), https://sparks.gogo.co.nz/ch340.html

 

Other Software 其他開發環境:

mBlock

S4A

S4A Firmware

Python

 

 

WeMos D1

Monday, July 3, 2017

Thermometer using TO-92 with Light Indicator



 

//This program sense temperature using TO-92 to A0 analog input, with lighting indicator to digital pin 2,3,4, and output voltage level through serial output at 9600bps

//20C -> OFF, OFF OFF

//22C-> ON, OFF OFF

//24C-> ON, ON OFF

//26C-> ON ON ON

 

const int sensorPin = A0;
const float baselineTemp = 20.0;

void setup(){
Serial.begin(9600);

for(int pinNumber = 2; pinNumber<5; pinNumber++){
pinMode(pinNumber,OUTPUT);
digitalWrite(pinNumber, LOW);
}
}

void loop(){
int sensorVal = analogRead(sensorPin);
Serial.print("Sensor Value: ");
Serial.print(sensorVal);

float voltage = (sensorVal/1024.0) * 5.0;
Serial.print(", Volts: ");
Serial.print(voltage);
Serial.print(", degrees C: ");
float temperature = (voltage -0.5) * 100;
Serial.println(temperature);

if (temperature < baselineTemp){
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
}else if (temperature >= baselineTemp+2 &&
temperature < baselineTemp+4){
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}else if (temperature >= baselineTemp+4 &&
temperature < baselineTemp+6){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
}else if (temperature >= baselineTemp+6){
digitalWrite(1, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}
delay(1);
}

Resistor Color Code

https://www.digikey.com/en/resources/conversion-calculators/conversion-calculator-resistor-color-code-4-band

 

Friday, June 23, 2017

Arduino Starter Kit

Official Site:

https://store.arduino.cc/usa/arduino-starter-kit

 

Projects you can make:

  • 01 GET TO KNOW YOUR TOOLS an introduction to the basics

  • 02 SPACESHIP INTERFACE design the control panel for your starship

  • 03 LOVE-O-METER measure how hot-blooded you are

  • 04 COLOR MIXING LAMP produce any color with a lamp that uses light as an input

  • 05 MOOD CUE clue people in to how you're doing

  • 06 LIGHT THEREMIN create a musical instrument you play by waving your hands

  • 07 KEYBOARD INSTRUMENT play music and make some noise with this keyboard

  • 08 DIGITAL HOURGLASS a light-up hourglass that can stop you from working too much

  • 09 MOTORIZED PINWHEEL a colored wheel that will make your head spin

  • 10 ZOETROPE create a mechanical animation you can play forward or reverse

  • 11 CRYSTAL BALL a mystical tour to answer all your tough questions

  • 12 KNOCK LOCK tap out the secret code to open the door

  • 13 TOUCHY-FEEL LAMP a lamp that responds to your touch

  • 14 TWEAK THE ARDUINO LOGO control your personal computer from your Arduino

  • 15 HACKING BUTTONS create a master control for all your devices!


 

 

Video Tutorial

 

 

Specification

1 Projects Book (170 pages),

Arduino / Genuino Uno,

USB cable,

Breadboard 400 points,

70Solid core jumper wires,

Easy-to-assemble wooden base,

9v battery snap,

1 Stranded jumper wires (black),

1 Stranded jumper wires (red),

Phototransistor,

Potentiometer 10kOhms,

10Pushbuttons,

Temperature sensor [TMP36],

Tilt sensor,

alphanumeric LCD (16x2 characters),

1LED (bright white),

LED (RGB),

LEDs (red),

LEDs (green),

LEDs (yellow),

LEDs (blue),

Small DC motor 6/9V,

1 Small servo motor,

Piezo capsule [PKM17EPP-4001-B0],

H-bridge motor driver [L293D],

Optocouplers [4N35],

Mosfet transistors [IRF520],

Capacitors 100uF,

Diodes [1N4007],

Transparent gels (red, green, blue),

Male pins strip (40x1),

20 Resistors 220 Ohms,

5Resistors 560 Ohms,

Resistors 1 kOhms,

Resistors 4.7 kOhms,

20 Resistors 10 kOhms,

5Resistors 1 MOhms,

Resistors 10 MOhms