Browse Source

Arduino OSS code

master
KangHayoon 5 years ago
commit
9e714fd87c
  1. 101
      sketch_jun29a.ino

101
sketch_jun29a.ino

@ -0,0 +1,101 @@
#include <Stepper.h>
#define STEPS 4096 // 한바퀴를 이루는 스텝 갯수 입력
Stepper stepper(STEPS, 4, 5, 6, 7); // 고정자 권선 순서 설정
int dust_sensor = A0;
float dust_value=0;
float dustDensityug=0;
int sensor_led =12;
int sampling=280;
int waiting =40;
float stop_time=9680;
void setup(){
Serial.begin(9600);
pinMode(sensor_led,OUTPUT);
pinMode(4,OUTPUT);
stepper.setSpeed(6); // 회전 속도 지정
}
void loop(){
digitalWrite(sensor_led, LOW);
delayMicroseconds(sampling);
dust_value=analogRead(dust_sensor);
delayMicroseconds(waiting);
digitalWrite(sensor_led, HIGH);
delayMicroseconds(stop_time);
dustDensityug =(0.17*(dust_value*(5.0/1024))-0.1)*1000;
Serial.print("Dust Density [ug/m3]: ");
if(dustDensityug <=75.0){
stepper.step(STEPS); // 정방향 회전
delay(1000);
}else if (80.0 < dustDensityug && dustDensityug <=150.0){
stepper.step(-STEPS); // 역방향 회전
delay(1000);
}
delay(2000);
}
Loading…
Cancel
Save