LoginSignup
0
0

More than 1 year has passed since last update.

Arduinoでスプレイヤーの自動調圧を作る

Last updated at Posted at 2021-06-04

まえがき

注意:実装テスト前です。
数値が出てきてリレーが動くまでは確認しています。しかし実機による動作チェックはしていません。

IMG_7473.png

材料

・北海道の農業者のご家庭にごく一般的にある、自動調圧がなく、電動調圧が付いているスプレイヤー
・Arduino uno
・電気の知識
・可変抵抗 10kオーム(2個あるとテストが捗ります)
・圧力センサー
https://www.amazon.co.jp/gp/product/B08D6L82ZD/
耐久性等も考えると、ちゃんとした圧力センサーのほうが良さそうです。
https://www.monotaro.com/g/01985014/
・センサーに分岐する配管材料
センサーのネジは一般的にNPTネジですが、スプレイヤー側は国産のものだとPTネジ(Gネジ)の場合が多いので、注意して買わないと使わない部品だらけになります。
参考資料:https://www.torque-system.jp/items/pdf/mm_NPT-PT.pdf

・i2c接続のLCD
今回はたまたま転がっていたこちらを使いましたが、本来はIO電圧3.3v用なので、IO5v対応したものを買う事をおすすめ。表示サイズも大きいですし。
・リレーモジュール
https://www.amazon.co.jp/gp/product/B00L11KL10/
・配線

配線

A0-圧力センサー
A1-可変抵抗
リレーA-8
リレーB-9
その他、電源とGNDを繋ぎます。

ソース

・toleranceで誤差範囲を決めています。
初期設定は±100ですが、調圧モータ速度、圧力のかかり具合、実際の圧力の反映速度にタイムラグがあると思うので、実機により要調整。

ソース
#include <MsTimer2.h>
#include <Wire.h>
#include <FaBoLCDmini_AQM0802A.h>

// initialize LCD
FaBoLCDmini_AQM0802A lcd;

int tolerance=100;

int sensorPin=A0;
int resistorPin=A1;
int upPin=8;
int downPin=9;

int sensorValue=0;
int pressureValue=0;
int pointValue=0;
int pos=0;

void setup() {
  pinMode(upPin,OUTPUT);
  digitalWrite(upPin,LOW);
  pinMode(downPin,OUTPUT);
  digitalWrite(downPin,LOW);
  Serial.begin(115200);

  MsTimer2::set(500,flash);
  MsTimer2::start();

  lcd.begin();
  //lcd.print("hello");

}

void loop() {
  Serial.println(pressureValue);
  Serial.println(pointValue);
  lcd.setCursor(0, 0);
  lcd.print("Set:");
  lcd.print(pointValue);
  lcd.setCursor(0, 1);
  lcd.print("P:");
  lcd.print(pressureValue);

  if (pressureValue<=(pointValue-tolerance)){
    digitalWrite(downPin,HIGH);
    digitalWrite(upPin,LOW);
    lcd.print("UP");
    delay(500);
    pos=1;
  }
  if (pressureValue>=(pointValue+tolerance)){
    digitalWrite(upPin,HIGH);
    digitalWrite(downPin,LOW);
    lcd.print("do");
    delay(500);
    pos=1;
  }
  if (pressureValue>=(pointValue-tolerance) or pressureValue<=(pointValue+tolerance)){
    digitalWrite(upPin,HIGH);
    digitalWrite(downPin,HIGH);
    if(pos==1){
    lcd.setCursor(0, 0);
    lcd.print("Set:");
    lcd.print(pointValue);
    lcd.setCursor(0, 1);
    lcd.print("Newtral ");
    delay(10);
    pos=0;
    }
  }
}

void flash(){
  sensorValue=analogRead(sensorPin);
  pressureValue=5000.0*sensorValue/1024;
  pointValue=5000.0*analogRead(resistorPin)/1024;
}


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0