안녕하세요 코딩 고수분들 아두이노에 대해 여쭤보고 싶은게 있어서 이렇게 작성해봅니다.

이번에 졸작을 진행하면서 제어쪽을 진행하는데 제어 관련 코딩을 인수인계받았는데 내용 정리가 하나도 되있지 않아서 이해가 어려워 이렇게 작성해봅니다.
파일은 간단하게 이렇게 되어있습니다.
#include <Stepper.h>
#include <Servo.h>
#include “DHT.h”
#include “Nextion.h”
#define DHTPIN A8 //온습도 센서 data핀 연결 핀 번호
#define DHTTYPE DHT22 // DHT타입
DHT dht(DHTPIN, DHTTYPE); //DHT 선언
Servo servo;
Servo maingate;
Stepper stepper(2048, 2, 4, 3, 5); //(IN4,2,3,1)
int stepsPerRev = 2048;
extern volatile unsigned long timer=0,timer2=0;
int flag = 0, first=1,past= 0,past_control=0;

short control_fan = 10; //팬 출력 조절 pwm 핀 번호
short control_fan2 = 9;
short servo_pin = 7; //////servo핀 번호
short maingate_pin = 6;
short switch_pin = 12;
short play = 0;
short control = 0;
short frontcontrol = 0;
short state = 1;

int fan_power1=100;
int fan_power2=100;
int fan_powerC1=100;
int fan_powerC2=100;
int horizontal_angle = 90;
int record_horizontal_angle = 90;
int uporfront=0;
int ufstate=0;
int need_move = 0;

int temp_sensor_mainbody;
int humidity_sensor_mainbody;

int humi,temp,co2,pm1,pm2,pm10,tvoc,Position,number; //Stores humidity value

float Td1,Td2,Tdh1,Tdh2,ice,ic;
unsigned long Tim;

String buff;
String ssid = “CAPSTONE”;
String PASSWORD = “01010101”;
String host = “123.456.78.90”;

NexText t11 = NexText(0,2,“t0”);

NexButton b21 = NexButton(1,5,“b3”);

NexText t31 = NexText(2,4,“t0”);
NexText t32 = NexText(2,12,“t1”);
NexText t33 = NexText(2,5,“t2”);
NexText t34 = NexText(2,6,“t3”);
NexText t35 = NexText(2,7,“t4”);
NexText t36 = NexText(2,13,“t5”);
NexText t37 = NexText(2,8,“t6”);
NexText t38 = NexText(2,9,“t7”);
NexText t39 = NexText(2,10,“t8”);
NexButton b31 = NexButton(2,11,“b1”);

NexButton b41 = NexButton(3,3,“b1”);
NexButton b42 = NexButton(3,4,“b2”);
NexButton b43 = NexButton(3,5,“b3”);

NexButton b51 = NexButton(4,3,“b1”);
NexButton b52 = NexButton(4,4,“b2”);
NexButton b53 = NexButton(4,5,“b3”);
NexButton b54 = NexButton(4,6,“b4”);
NexButton b55 = NexButton(4,7,“b5”);
NexSlider h51 = NexSlider(4,8,“h0”);
NexSlider h52 = NexSlider(4,15,“h1”);
NexSlider h53 = NexSlider(4,14,“h2”);

NexTouch *nex_event_list[]={
&b21,&b31,&b41,&b42,&b43,&b51,&b52,&b53,&b54,&b55,&h51,&h52,&h53,NULL
};

void connectWifi(){
digitalWrite(12,LOW);
delay(300);
digitalWrite(12,HIGH);
int is_connect = 1;
String join =“AT+CWJAP=”"+ssid+"",""+PASSWORD+""";
Serial.print(“Connect Wifi”);
t11.setText(“wifi loading…”);
while(is_connect){
Serial.print("…");
Serial3.println(join);
delay(1000);
if(Serial3.find(“OK”)){
Serial.println("!");
Serial.println(“WIFI connect”);
is_connect = 0;
}
}
}
int download(){
Serial3.println(“AT+CIPMUX=0”);
Serial.println(“connect TCP…”);
Serial3.println(“AT+CIPSTART=“TCP”,”"+host+"",8787");
delay(500);
if(Serial3.find(“ERROR”)){
Serial.println(“connect time out”);
return 0;
}
Serial.println(“Send data…”);
String cmd=“GET /getvalue.php? HTTP/1.0\r\n\r\n”;
Serial3.print(“AT+CIPSEND=”);
Serial3.println(cmd.length());
Serial.print(“AT+CIPSEND=”);
Serial.println(cmd.length());
delay(200);
if(Serial3.find(">"))
{
Serial.print(">");
}
else
{
//Serial3.println(“AT+CIPCLOSE”);
Serial.println(“connect timeout”);
//connectWifi();
return 0;
}
delay(500);
Serial3.println(cmd);
Serial.println(“GET /getvalue.php? HTTP/1.0”);
delay(100);
while(Serial3.available()){
if(Serial3.find("
")){
buff = Serial3.readStringUntil(’\n’);
Serial.println(buff); //buff에 서버에 있는 정보가 문자열로 들어옴.
}
}
Serial.println("--------------------------------");
if(Serial.find(“ERROR”)){
Serial.println(“error”);
return 0;
}
//Serial3.println(“AT+CIPCLOSE”);
return 1;
}
void get_value_from_server()
{

  int flag=0;
  do{
    flag = download();
  }while(!flag);

  int index1 = buff.indexOf('/');
  int index2 = buff.indexOf('/',index1 + 1);
  int index3 = buff.indexOf('/',index2 + 1);
  int index4 = buff.indexOf('/',index3 + 1);
  int index5 = buff.indexOf('/',index4 + 1);
  int index6 = buff.indexOf('/',index5 + 1);
  int index7 = buff.indexOf('/',index6 + 1);
  int index8 = buff.indexOf('/',index7 + 1);
  int index9 = buff.length();

  temp = buff.substring(0,index1).toFloat();
  humi = buff.substring(index1+1,index2).toFloat();
  co2 = buff.substring(index2+1,index3).toFloat();
  pm1 = buff.substring(index3+1,index4).toFloat();   //표시용
  pm2 = buff.substring(index4+1,index5).toFloat();   //표시용
  pm10 = buff.substring(index5+1,index6).toFloat();   //표시용
  tvoc = buff.substring(index6+1,index7).toFloat();  
  Position = buff.substring(index7+1,index8).toFloat();  //제어용
  number = buff.substring(index8+1,index9).toFloat();  //측정기 넘버 

}
void get_value_from_sensor()
{
humidity_sensor_mainbody = dht.readHumidity();
temp_sensor_mainbody = dht.readTemperature();
}
void produce_value_for_gatecontrol()
{ //Td1내부온도 Td2 외부온도
Tdh1 = humi / 100;
Tdh2 = humidity_sensor_mainbody / 100;

Td1 = pow(Tdh1, 0.125) * (122+0.9temp) + (0.1temp)-112;
Td2 = pow(Tdh2, 0.125) * (122+0.9temp_sensor_mainbody) + (0.1temp_sensor_mainbody)-112;

if( temp_sensor_mainbody < -16) {ice = 15000;}
else if (temp_sensor_mainbody < -10)
{
ic = -(temp_sensor_mainbody) -10;
ice = (ic) * 2500;
}
float Tdo = abs(Td1-Td2); //이거 Td1, Td2 뭔지 알고 대입하는 과정있어야된다.
float T = 0;
if ( Tdo > 15) {T = 30000;}
else { T = Tdo * 1000;}
if (co2>1000) {co2 = 1000;}
float Rco2 = (co2-(co2%100)-400)*100;
Tim = 60000+Rco2-T-ice;
}
void auto_direction() //이 함수를 실행시키면 서버로부터 위치값을 받아와서 풍향및 풍속을 자동으로 조정
{
if(Position == 2)
{
horizontal_angle = 77.5;
control_direction();
front();
}
else if(Position == 3)
{
horizontal_angle = 90;
control_direction();
front();
}
else if(Position == 4)
{
horizontal_angle = 102.5;
control_direction();
front();
}
else
{
horizontal_angle = 90;
control_direction();
up();
}
}
void control_direction() //수동용 // 수동 방향 조절
{
need_move = horizontal_angle - record_horizontal_angle;

if (need_move < 0 )
{
for (int i = 0 ; i < (-need_move / 22.5) ; i = i+1)
{
stepper.step(-(stepsPerRev / 8)); // 스텝모터가 8분의 1바퀴를 돌면(45도) 기어비가 2:1 이여서 22.5도 회전
}
}
if ( need_move > 0)
{
for (int i = 0 ; i < (need_move / 22.5) ; i = i+1)
{
stepper.step(stepsPerRev / 8); // 스텝모터가 8분의 1바퀴를 돌면(45도) 기어비가 2:1 이여서 22.5도 회전
}
}
record_horizontal_angle = horizontal_angle;
}
void zero() //영점 잡는거
{
stepper.step(stepsPerRev);
while(digitalRead(switch_pin == HIGH)) // HIGH 상태가 스위치가 열려있는 상태
{
stepper.step(-30);
}
stepper.step(100);
horizontal_angle = 0;
}
void up() //풍향 방향 조절
{
if(ufstate){
servo.attach(servo_pin);
delay(100);
servo.write(60);
delay(100);
servo.detach();
ufstate=0;
}
}
void front() //풍향 전방
{
if(!ufstate){
servo.attach(servo_pin);
delay(100);
servo.write(10);
delay(100);
servo.detach();
ufstate=1;
}
}

void b21_Callback(void ptr){
if(play ==1){
play=0;
analogWrite(control_fan, 255);
analogWrite(control_fan2, 255);
maingate.write(95);
horizontal_angle = 90;
control_direction();
up();
frontcontrol = past_control;
//zero();
}
else if(play ==0){
play=1;
first = 1;
Position=0;
if(frontcontrol == 2){
analogWrite(control_fan, 255);
analogWrite(control_fan2, 255);
}
else{
analogWrite(control_fan, fan_power1
(1-control)+fan_powerC1control);
analogWrite(control_fan2, fan_power2
(1-control)+fan_powerC2control);
maingate.write(40);
}
control_direction();
if(control){
if(uporfront) front();
else up();
}
}
}
void b31_Callback(void ptr){
char Humi[10] = {0};
utoa(humi, Humi, 10);
t35.setText(Humi);
char Temp[10] = {0};
utoa(temp, Temp, 10);
t31.setText(Temp);
char CO2[10] = {0};
utoa(co2, CO2, 10);
t33.setText(CO2);
char TVOC[10] = {0};
utoa(tvoc, TVOC, 10);
t34.setText(TVOC);
char PM1[10] = {0};
utoa(pm1, PM1, 10);
t39.setText(PM1);
char PM2[10] = {0};
utoa(pm2, PM2, 10);
t38.setText(PM2);
char PM10[10] = {0};
utoa(pm10, PM10, 10);
t37.setText(PM10);
char Humi_Out[10] = {0};
utoa(humidity_sensor_mainbody, Humi_Out, 10);
t36.setText(Humi_Out);
char Temp_Out[10] = {0};
utoa(temp_sensor_mainbody, Temp_Out, 10);
t32.setText(Temp_Out);
}
void b41_Callback(void ptr){
if(Position){
past_control = 0;
}
else{
frontcontrol=0;
first=1;state=1;
if(play){
analogWrite(control_fan, fan_power1
(1-control)+fan_powerC1
control);
analogWrite(control_fan2, fan_power2
(1-control)+fan_powerC2control);
}
}
}
void b42_Callback(void ptr){
if(Position){
past_control = 1;
}
else{
frontcontrol=1;
first=1;state=1;
if(play){
maingate.write(40);
analogWrite(control_fan, fan_power1
(1-control)+fan_powerC1
control);
analogWrite(control_fan2, fan_power2*(1-control)+fan_powerC2*control);
}
}
}
void b43_Callback(void *ptr){
if(Position){
past_control = 2;
}
else{
frontcontrol=2;
first=1;state=1;
if(play){
maingate.write(95);
analogWrite(control_fan, 255);
analogWrite(control_fan2, 255);
}
}
}
void b51_Callback(void *ptr){
control=0;
fan_power1 = 100, fan_power2 = 100;
if(play){
if(frontcontrol ==2){
analogWrite(control_fan, 255);
analogWrite(control_fan2, 255);
}
else{
if(state){
analogWrite(control_fan, fan_power1);
analogWrite(control_fan2, fan_power2);
}
}
auto_direction();
}
}
void b52_Callback(void *ptr){
control=0;
fan_power1 = 0, fan_power2 = 0;
if(play){
if(frontcontrol ==2){
analogWrite(control_fan, 255);
analogWrite(control_fan2, 255);
}
else{
if(state){
analogWrite(control_fan, fan_power1);
analogWrite(control_fan2, fan_power2);
}
}
auto_direction();
}
}
void b53_Callback(void *ptr){
control=1;
uint32_t f1=0,f2=0,ang=0;
h51.getValue(&f1);
h52.getValue(&f2);
h53.getValue(&ang);
fan_powerC1=255-f1;
fan_powerC2=255-f2;
horizontal_angle = ang;
if(play){
if(frontcontrol ==2){
analogWrite(control_fan, 255);
analogWrite(control_fan2, 255);
}
else{
analogWrite(control_fan, fan_powerC1);
analogWrite(control_fan2, fan_powerC2);
}
control_direction();
if(uporfront) front();
else up();
}
}
void h51_Callback(void *ptr){
control = 1;
uint32_t f1=0;
h51.getValue(&f1);
fan_powerC1=255-f1;
if(play){
if(frontcontrol ==2){
analogWrite(control_fan, 255);
analogWrite(control_fan2, 255);
}
else{
analogWrite(control_fan, fan_powerC1);
analogWrite(control_fan2, fan_powerC2);
}
control_direction();
if(uporfront) front();
else up();
}
}
void h52_Callback(void *ptr){
control = 1;
uint32_t f2=0;
h52.getValue(&f2);
fan_powerC2=255-f2;
if(play){
if(frontcontrol ==2){
analogWrite(control_fan, 255);
analogWrite(control_fan2, 255);
}
else{
analogWrite(control_fan, fan_powerC1);
analogWrite(control_fan2, fan_powerC2);
}
control_direction();
if(uporfront) front();
else up();
}
}
void h53_Callback(void *ptr){
control = 1;
uint32_t ang=0;
h53.getValue(&ang);
horizontal_angle = ang;
if(play){
if(frontcontrol ==2){
analogWrite(control_fan, 255);
analogWrite(control_fan2, 255);
}
else{
analogWrite(control_fan, fan_powerC1);
analogWrite(control_fan2, fan_powerC2);
}
control_direction();
if(uporfront) front();
else up();
}
}
void b54_Callback(void *ptr){
up();
uporfront = 0;
}
void b55_Callback(void *ptr){
front();
uporfront = 1;
}
void setup() {
pinMode(12, OUTPUT);
digitalWrite(12,HIGH);
pinMode(control_fan, OUTPUT);
pinMode(control_fan2, OUTPUT);
pinMode(switch_pin, INPUT_PULLUP);
analogWrite(control_fan, 255);
analogWrite(control_fan2, 255);
Serial.begin(9600);
Serial3.begin(9600); //wifi 14,15
nexInit();
connectWifi();
t11.setText(“complete”);
b21.attachPop(b21_Callback, &b21);
b31.attachPop(b31_Callback, &b31);
b41.attachPop(b41_Callback, &b41);
b42.attachPop(b42_Callback, &b42);
b43.attachPop(b43_Callback, &b43);
b51.attachPop(b51_Callback, &b51);
b52.attachPop(b52_Callback, &b52);
b53.attachPop(b53_Callback, &b53);
b54.attachPop(b54_Callback, &b54);
b55.attachPop(b55_Callback, &b55);
h51.attachPop(h51_Callback, &h51);
h52.attachPop(h52_Callback, &h52);
h53.attachPop(h53_Callback, &h53);
maingate.attach(maingate_pin);
stepper.setSpeed(10);
servo.attach(servo_pin);
delay(200);
servo.write(60);
delay(200);
servo.detach();
maingate.write(95);
control_direction();
//zero();
}

void loop() {

nexLoop(nex_event_list);
get_value_from_sensor();
if(millis()-timer2>10000){
get_value_from_server();
timer2=millis();
}
if(play == 1)//ON
{
if(control == 0)//자동 //수동일때 방향을 자동으로 제어.
{
if(past!=Position){
auto_direction();
if(Position){
maingate.write(40);
analogWrite(control_fan, 0);
analogWrite(control_fan2, 0);
if(Positionpast==0){
past_control = frontcontrol;
frontcontrol=3;
}
first = 1;
}
else{
frontcontrol = past_control;
if(frontcontrol==2){
maingate.write(95);
analogWrite(control_fan, 255);
analogWrite(control_fan2, 255);
}
else if(frontcontrol==1){
maingate.write(40);
analogWrite(control_fan, fan_power1);
analogWrite(control_fan2, fan_power2);
}
}
past = Position;
}
}
if(frontcontrol == 0) //자동
{
produce_value_for_gatecontrol();
if(first||(millis()/1000 - timer >= 120)){
timer = millis()/1000;
maingate.write(40);
Serial.println(Tim);
flag=1; first=0;state=1;
analogWrite(control_fan, fan_power1
(1-control)+fan_powerC1control);
analogWrite(control_fan2, fan_power2
(1-control)+fan_powerC2*control);
}
if(flag &&( millis()/1000 - timer >= Tim/1000)){
maingate.write(95);
analogWrite(control_fan, 255);
analogWrite(control_fan2, 255);
flag = 0;state=0;
}
}
}
}
현재 공기청정장치를 가동하는데 있어서 작동시키는데 와이파이 자체가 연결이 안되더라구요,
너무 긴 내용이지만 아무리 검색하고 해봐도 잘 몰라서 염치없이 여기다가 질문 올려봅니다
도와주신다면 정말 감사할 것 같습니다.

이란 내용을 보니까 추상화된 라이브러리를 쓰는게 아니라 WiFi모듈에 직접 커맨드를 보내는형태인가 보네여.
2가지를 봐보세염.

  1. WiFi 모듈이 정상동작 하는지. 아두이노라고 하는거 보니 브레드보드에 연결된거 같은데, WiFi모듈만 따로 떼어내서 정상동작하는지 확인해보세여

  2. 통과되면, 브레드보드에 제대로 결선이 되어 있는지 보세여

  3. 통과되면, 주는 명령어가 올바른지 보세여

코드가 넘모 길어욤
백틱 ` 세개로 감싸주세욤

```
코드
```