顯示具有 Arduino 標籤的文章。 顯示所有文章
顯示具有 Arduino 標籤的文章。 顯示所有文章

2018年10月12日 星期五

簡易閃光儀測量轉速

#include<Wire.h>
#include< LiquidCrystal_I2C.h>
void setup() {
lcd.begin(16, 2);  // 初始化 LCD,一行 16 的字元,共 2 行,預設開啟背光
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop() {
float a = map(analogRead(A0),0,1023,0,1000); //讀取可變電阻數值改變閃爍時間間隔
digitalWrite(13, HIGH);   // HIGH is the voltage level打開開關5v 電壓通過燈亮
delayMicroseconds(100); //固定亮的時間相對短可忽略
digitalWrite(13, LOW);    // making the voltage LOW關閉開關燈暗
  delay(0.1*a);    //       決定週期大小
  lcd.setCursor(0, 0); // 設定游標位置在第一行行首
  lcd.print(a); //顯示週期
}


    學生弈睿苑智作品:測量繩子擺動週期\





2017年1月31日 星期二

可變電阻控制MeArm機械手臂

學校最近買了雷射切割機,於是將想了很久的MeArm使用木板切了一套,不過雷射強度沒有調整好,結果燒焦造成螺絲孔太大,有點零零落落。





PDF 組裝手冊

這是一個高手的DIY : 袖珍版機械手臂 MeArm
 MeArm V0.4 的零件圖下載點
可變電阻控制伺服馬達
https://goo.gl/SX7y9i
利用電位器控制 meArm https://goo.gl/KqhQqp
MeArm組裝說明(中文) https://goo.gl/sNdVjB
MeArm組裝說明 https://goo.gl/ollblX

Arduino 程式

// by Michal Rinott  
// Used Michal's code but x4 to control the MeArm v0.3 - Ben Gray

#include <Servo.h>

Servo myservo0, myservo1, myservo2, myservo3 ;  // 4個馬達

int potpin0 = 0;  // analog pin used to connect the potentiometer
int potpin1 = 1;  // analog pin used to connect the potentiometer
int potpin2 = 2;  // analog pin used to connect the potentiometer
int potpin3 = 3;  // analog pin used to connect the potentiometer
int val0;    // variable to read the value from the analog pin 
int val1;    // variable to read the value from the analog pin 
int val2;    // variable to read the value from the analog pin 
int val3;    // variable to read the value from the analog pin 

void setup() 
{ 
  Serial.begin(9600);
  //Serial.println("CLEARDATA");
  //Serial.println("LABEL,Time,Timer,val0,val1,val2,val3");
  myservo0.attach(11);  // attaches the servo on pin 11 to the servo object
  myservo1.attach(10);  // attaches the servo on pin 10 to the servo object
  myservo2.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo3.attach(6);  // attaches the servo on pin 6 to the servo object
} 

void loop() 
{ 
  val0 = analogRead(potpin0);// 讀取電位 (value between 0 and 1023) 
  val0 = map(val0, 0, 800,179,0);   // 轉換為servor角度 (value between 0 and 180) 
  myservo0.write(val0);             // 馬達旋轉位置
 // Serial.println(val0);
  delay(40);                           // waits for the servo to get there

  val1 = analogRead(potpin1);            
  val1 = map(val1, 0, 1023, 0, 179);     
  myservo1.write(val1); 
 // Serial.println(val1);  
  delay(40); 
                          
  val2 = analogRead(potpin2);            
  val2 = map(val2, 0, 1023, 0, 179);     
  myservo2.write(val2);                  
  //Serial.println(val2);
  delay(40);                           
  
  val3 = analogRead(potpin3);            
  val3 = map(val3, 0, 1023, 0, 179);     
  myservo3.write(val3);                  
 // Serial.println(val3);
  delay(40);                           
  
 /* Serial.print("DATA,TIME"); 
  Serial.print(",");
  Serial.print("TIMER"); 
  Serial.print(",");
  Serial.print(val0);
  Serial.print(",");
  Serial.print(val1);
  Serial.print(",");
  Serial.print(val2);
  Serial.print(",");
  Serial.println(val3); 
*/
} 

可變電阻控制伺服馬達

Servo library

可變電阻控制伺服馬達(Examples from Libraries ; Servo ; Knob)

  • Arduino uno
  • 伺服馬達 Servo Motor
  • 10k ohm可變電阻 10k ohm potentiometer
  • 單心線 hook-up wires

/*
 Controlling a servo position using a potentiometer (variable resistor)
 by Michal Rinott

 modified on 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Knob
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo 建立一個 Servo 

int potpin = 0;  // analog pin used to connect the potentiometer  可變電阻接中間訊號接在 Analog pin 0
int val;    // variable to read the value from the analog pin  旋轉角度的變數

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object  Servo 接在 pin 9
}
void loop() {
  val = analogRead(potpin);            //讀取可變電阻(數值介於 0 到 1023)
  val = map(val, 0, 1023, 0, 180);     // 把 0 - 1023 的數值按比例轉換為 0 - 180 的數值
  myservo.write(val);                  // Servo 旋轉角度
  delay(15);                           // 等待 Servo 旋轉位置
}


2016年9月18日 星期日

呼吸燈(for)(analogWrite)(~3.5.6.9.10.11)


void setup() {
  pinMode(3, OUTPUT);
}
void loop() {
  for(int a=0;a<=255;a=a+5)
  {
  analogWrite(3, a);
  delay(25);
  }
  for(int b=255;b>=0;b=b-5)
  {
  analogWrite(3, b);
  delay(25);
  }                              
}

2016年9月6日 星期二

hcsr04將距離變聲音

將之前HC-SR04結合PLX-DAQ的code做些修改,接上蜂鳴器將距離變換成聲音,再加個按鈕開關,否則真的很吵。


蜂鳴器接腳8與GND


// HCSR04Ultrasonic/examples/UltrasonicDemo/UltrasonicDemo.pde

#include

#define TRIGGER_PIN  12

#define ECHO_PIN     13

Ultrasonic ultrasonic(TRIGGER_PIN, ECHO_PIN);
void setup()
{
  Serial.begin(9600);
  Serial.println("CLEARDATA");
  Serial.println("LABEL,Time,Timer, D");
}

void loop()
{

 float cmMsec, inMsec;
 long microsec = ultrasonic.timing();

  cmMsec = ultrasonic.convert(microsec, Ultrasonic::CM); // 計算距離,單位: 公分

 //inMsec = ultrasonic.convert(microsec, Ultrasonic::IN); // 計算距離,單位: 英吋
 // Serial.print("MS: ");
  Serial.print("DATA,TIME");
  Serial.print(",");
  Serial.print("TIMER");
  Serial.print(",");
  Serial.println(cmMsec);
  tone(8, cmMsec*40,500); //cmMsec*40音頻,時間500
 // Serial.print(microsec);

 // Serial.print(", CM: ");

 // Serial.println(cmMsec);

  //Serial.print(", IN: ");

 // Serial.println(inMsec);
delay(100);

}

2016年8月9日 星期二

Arduino Bluetooth Android control RGB LED





1  Arduino板

2 藍牙模塊HC-05

HC-05藍芽模組
Arduino Uno Pin
VCC
5V
GND
Gnd
TXD
0
RXD
1

3  RGB LED

    Red LED :Arduino Pin 3.  
    Green LEDArduino Pin 5.  
    Blue LEDArduino Pin 6  ( PWM ~ )



4 Code(下載)



        


     

2016年7月22日 星期五

mBlock與Arduino驅動程式

官方網站  http://www.mblock.cc/
下載mBlock

安裝驅動Arduino程式

安裝驅動Arduino程式
 
選擇控制板



Arduino 編輯


2016年7月7日 星期四

mBlock計分板



個位數的積木程式
十位數的積木程式
馬達的積木程式
led的積木程式
滾珠開關紅色線應該接在下一格(5 v)

2016年6月27日 星期一

空氣砲靶

滾珠開關與伺服馬達(第一代),哈哈可以去夜市擺遊戲攤

滾珠開關 (digital input)






// define the pin numbers names
int inputPin = 2;
int ledPin = 13;

void setup() {
// declare inputPin to be an input
pinMode(inputPin, INPUT);
pinMode(ledPin, OUTPUT);
}

void loop() {
if (digitalRead(inputPin) == HIGH) {
digitalWrite(ledPin, HIGH);//滾珠開關ON,led燈亮
}
else{digitalWrite(ledPin, LOW);}
}

2016年6月25日 星期六

Parking

超音波傳感器結合rgbled

下載程式碼

hc-sr04
    Vcc......5v         紅
    Gnd......GND    黑
    Trig......12         藍
    Echo.....13        綠
 led
    redled = 9
   greenled = 10 
   blueled = 11

2016年5月3日 星期二

HC-SR04結合PLX-DAQ/運動的分析

可以運用在加速度的實驗,講解x-t圖和v-t圖性質與兩者的關聯。
好不好用??????

記得要選擇與arduino相同的連接埠

1.首先下載PLX-DAQ
2.下載程式碼

// HCSR04Ultrasonic/examples/UltrasonicDemo/UltrasonicDemo.pde
#include
#define TRIGGER_PIN  12
#define ECHO_PIN     13

Ultrasonic ultrasonic(TRIGGER_PIN, ECHO_PIN);
void setup()
{
  Serial.begin(9600);

 Serial.println("CLEARDATA");  

 Serial.println("LABEL,Time,Timer,d");//標籤

}

void loop()
{
  float cmMsec, inMsec;
  long microsec = ultrasonic.timing();

  cmMsec = ultrasonic.convert(microsec, Ultrasonic::CM); // 計算距離,單位: 公分
  inMsec = ultrasonic.convert(microsec, Ultrasonic::IN); // 計算距離,單位: 英吋

  Serial.print("DATA,TIME");
  Serial.print(",");
  Serial.print("TIMER");
  Serial.print(",");
  Serial.println(cmMsec);
  // Serial.print("MS: ");
  // Serial.print(microsec);
  // Serial.print(", CM: ");
  //Serial.print(cmMsec);
  // Serial.print(", IN: ");
  //Serial.println(inMsec);
  delay(100);

}

         





2016年5月2日 星期一

HC-SR04超音波測距模組

 下載函式庫


   下載解壓縮之後,資料夾放在arduino的資料夾libraries裡頭,再重新開啟arduino。
在檔案/範例裡頭有看到HCSR04Ultrasonic的資料夾就表示成功了。



   
   Vcc......5v         紅
   Gnd......GND    黑
   Trig......12         藍
   Echo.....13        綠


    開啟UltrasonicDemo後上傳

/*
 * HCSR04Ultrasonic/examples/UltrasonicDemo/UltrasonicDemo.pde
 *
 * SVN Keywords
 * ----------------------------------
 * $Author: cnobile $
 * $Date: 2011-09-17 02:43:12 -0400 (Sat, 17 Sep 2011) $
 * $Revision: 29 $
 * ----------------------------------
 */

#include

#define TRIGGER_PIN  12
#define ECHO_PIN     13

Ultrasonic ultrasonic(TRIGGER_PIN, ECHO_PIN);

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

void loop()
  {
  float cmMsec, inMsec;
  long microsec = ultrasonic.timing();

  cmMsec = ultrasonic.convert(microsec, Ultrasonic::CM);
  inMsec = ultrasonic.convert(microsec, Ultrasonic::IN);
  Serial.print("MS: ");
  Serial.print(microsec);
  Serial.print(", CM: ");
  Serial.print(cmMsec);
  Serial.print(", IN: ");
  Serial.println(inMsec);
  delay(1000);//每一秒測量一次
  }
開啟工具/序列埠監控視窗
開啟工具/序列埠監控視窗

回傳時間/距離(cm)/距離(英吋)

2016年4月22日 星期五

ds18b20溫度感測器

詳細教學可參考阿簡生物筆記
利用防水的溫度感測計可進行有關熱量變化的實驗耶,會考後讓9年級玩玩。

下載函式庫

OneWire(https://goo.gl/DMRdxi)

Arduino-Temperature-Control-Library

解壓縮後分別放到Arduino的sketchbook下的libraries目錄裡。

DS18B20
藍線或黃線接D2
紅線接5V
黑線或灰接GND
還要在紅線藍線之間再加一個4.7k的電阻







{ 
  // call sensors.requestTemperatures() to issue a global temperature 
  // request to all devices on the bus
 // Serial.print("Requesting temperatures...");不列出
  sensors.requestTemperatures(); // Send the command to get temperatures
  //Serial.println("DONE");
  // After we got the temperatures, we can print them here.
  // We use the function ByIndex, and as an example get the temperature from the first sensor only.
 // Serial.print("Temperature for the device 1 (index 0) is: ");
  Serial.println(sensors.getTempCByIndex(0));  

}

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  //Serial.println("Dallas Temperature IC Control Library Demo");
  Serial.println("CLEARDATA");
  Serial.println("LABEL,Time,Timer,Temperature,val,");
  // Start up the library
  sensors.begin();
}
/*
 * Main function, get and show the temperature
 */
void loop(void)
{
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println(sensors.getTempCByIndex(0));
  Serial.print("DATA,TIME");
  Serial.print(",");
  Serial.print("TIMER");
  Serial.print(",");
  Serial.println(sensors.getTempCByIndex(0));
  delay(100);
}

ds18b20並聯8支(第9支就會出現負數)應該是極限
放進溫水中
將2支改放入熱水
抽離也可測氣溫
PLX-DAQ收集數據