commit 9e714fd87ca84cf14ed2a1691a0d381e361d81cc Author: KangHayoon <5843rkdgkdbs@gmail.com> Date: Tue Jun 29 16:13:26 2021 +0900 Arduino OSS code diff --git a/sketch_jun29a.ino b/sketch_jun29a.ino new file mode 100644 index 0000000..bcc4e56 --- /dev/null +++ b/sketch_jun29a.ino @@ -0,0 +1,101 @@ +#include + +#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); + + + +}