

零件:
- XGZP6847 真空傳感器
- L-293D 電機驅動擴展板 https://www.eclife.com.tw/led/moreinfo_83732.htm
- 真空泵 -12V http://goods.ruten.com.tw/item/show?21407137501135
- BasicTest:找出電壓與真空關係
- SkinElasticity: 速度設定約 75%-95%
- 開機真空泵以設定速度運轉,到達Max真空值。(Max值設定約 50-70mpa)
- 真空泵停止,顯示真空值。
--- 程式碼 Code 1 BasicTest ---
/*
* 設計:potPin控制 relayPin 調整真空泵速度
* vacuumPin偵測真空度 到達目標值既關閉真空泵
*
*/
//int relayPin= 3 ;
//int potPin = A0; // analog pin used to connect the potentiometer
int vacuumPin= A0 ;
int vaccumValue = 0 ;
//int potValue = 0 ;
int a = 0 ;
void setup() {
//pinMode(relayPin, OUTPUT);
// potValue = analogRead( potPin) ;
// analogWrite(relayPin,potValue);
Serial.begin(9600);
Serial.println("LABEL,NO,VACCUM");
}
void loop() {
vaccumValue = analogRead( vacuumPin) ;
/*if ( vaccumValue >= 80 ) {
analogWrite(relayPin, 0);
}
if (vaccumValue <= 0 ) {
analogWrite(relayPin, potValue);
}
*/
a = a + 1 ;
Serial.print("DATA");
Serial.print(",");
Serial.print(a);
Serial.print(",");
Serial.println(vaccumValue);
delay(100) ;
}
--- 程式碼 Code 2 SkinElasticity ----
/*
* 由elasticity-tryVaccumSensor-8 修改名
* 真空senser
* 真空泵 压力范围:-460mmHg~1200mmhg
* 先測出真空泵壓力(真空)值 如下
* 4.5v,0.5v ; 0kpa,-100kpa
* 914/1023*5v = 4.46v, 482/1023*5v = 2.35v sersorVlue
* = 0kpa = 70.5kpa*
* 最大真空:>-65kpa
* 充气时间:<10S(500cc tank 0 to 300mmHg)
* -------------------------------------------
* 改真空泵控速 L293D 驅動器
http://ee543.blogspot.tw/2016/04/arduino-uno452l293d.html
*------------------------------------------
* 原 Elasticity-tryVaccumSensor-4 可設定真空泵速度
* 增加最大 真空泵壓力值可設定
* -----------------------------------------------------
* potSpValue 值由 從0~1023映射到 0~100
* potMaxValue 值由 從0~1023映射到 0~70.5
* potMaxValue設定 kpaValue2 >= potMaxValue2 ,kpaValue2 <= 0 真空泵才工作
* -------------------------------------------------------
* 增加真空值 V 第一行^^^啟動speed設成95較好,若需要再降
* maxValue 45
* ---------------------------------------------------------------------------------
* Serial.println("LABEL,TIME,Vaccum");修改成 Serial.println("LABEL,NO.,Vaccum");
*/
#include <liquidcrystal_i2c.h>
LiquidCrystal_I2C lcd(0x3F,20,4);
#define kpaPin A0 // 讀 真空泵 壓力(真空)值
#define potSpPin A1 // 讀 potPin A1 值 供 ENAPin 輸出 pwm 速度
#define potMaxPin A2 // 讀 potPin A2 值 設定最大 真空泵 壓力(真空)值
#include <afmotor.h>
AF_DCMotor motor(2, MOTOR12_8KHZ); //接L293D 驅動器腳座 1 及頻率
int potSpValue = 0 ;
int potMaxValue = 0 ;
int kpaValue = 0 ;
int kpaValue2 = 0 ;
int a = 0 ;
void setup()
{
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Hello, world!");
lcd.setCursor(2,1);
lcd.print("ToppyBio.Com. Hi");
delay (1200);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Spd: ");
lcd.setCursor(8, 0);
lcd.print("V: ");
lcd.setCursor(0, 1);
lcd.print("MaxP Value:");
//motor.setSpeed(65); //可調轉速約 0-100
// motor.run(FORWARD);
Serial.begin(9600);
Serial.println("LABEL,NO.,Vaccum");
}
void loop()
{
lcd.setCursor(4, 0);//必須有這4行,調整 LCD 數字亂碼
lcd.print(" ");
lcd.setCursor(11, 1);
lcd.print(" ");
lcd.setCursor(11, 1);
lcd.print(" ");
int potSpValue = analogRead(potSpPin);
int potSpValue2 = map(potSpValue, 0, 1023, 0, 100); // 從0~1023映射到 0~100
int potMaxValue = analogRead(potMaxPin);
int potMaxValue2 = map(potMaxValue, 0, 1023, 0, 70.5); // 從0~1023映射到 0~70.5
// motor.setSpeed(potSpValue2); //可調轉速約 0-100
//motor.run(FORWARD); //正轉
int kpaValue = analogRead(kpaPin); // 讀取FSR
int kpaValue2 = map(kpaValue, 914, 482, 0, 70.5);
//int led_value = map(fsr_value, 0, 1023, 100, 0); // 從0~1023映射到0~255
if (kpaValue2 >= potMaxValue2 ) {
motor.setSpeed(potSpValue); //可調轉速約 0~到 100
motor.run(RELEASE); //停止
}
if (kpaValue2 <= 0 ) {
motor.setSpeed(potSpValue); //可調轉速約 0~到 100
motor.run(FORWARD); //正轉
}
a = a+1 ;
lcd.setCursor(4, 0);
lcd.print(potSpValue2);
lcd.setCursor(11, 0);
lcd.print(kpaValue2);
lcd.setCursor(11, 1);
lcd.print(potMaxValue2);
Serial.print("DATA");
Serial.print(",");
Serial.print(a);
Serial.print(",");
Serial.println(kpaValue2);
//Serial.println(led_value);
delay(100);
}
對此儀器很感興趣
回覆刪除多謝發明者的開發
是否有承接外銷歐洲訂單