ysw's blog

    Arduino Code Example

    22 Jan 2019 |

    포스팅

    Arduino 센서 Example

    구성된 Arduino 회로의 각 센서들을 값을 주기적으로 읽어오고 시리얼 통신으로 값을 노내기 위해 다음과 같은 코드를 작성하였다. 아두이노쪽 코드는 다음과 같다.

    온도 센서 Example

    Thermistor : NTC-10KD-5J
    Resistor : 10K 옴
    $$ \dfrac{1}T = A + B\ln(x+1)+C(\ln(x+1))^3$$


    <내용>




    
    #define R0 10000
    #define T0 25 //room temperature
    #define B 4200 //the coefficient of the thermistor
    #define SERISR 10000 //seris resistor 10K
    //float thermistorRValue = 0.0f;
    
    void setup() {
    	Serial.begin(9600);
    }
    
    void loop() {
    	float thermistorRValue;
    	thermistorRValue = 1023.0 / analogRead(0) - 1;
    	thermistorRValue = SERISR / thermistorRValue;
    	
    	float temperature;
    	temperature = thermistorRValue / R0; // R/R0
    	temperature = log(temperature);
    	temperature = temperature / B;
    	temperature = temperature + 1.0 / (T0 + 273.15);
    	temperature = 1.0 / temperature;
    	temperature -= 273.15 ;// kelvins to C
    
    	Serial.println(temperature);
    	delay(1000);
    }
    



    조도 센서 Example

    Light Sensor : CDS(GL10537-1)
    Resistor : 10K 옴


    <내용>




    
    void setup() {
        Serial.begin(9600);
    }
    
    void loop() {
        int data = analogRead(A0);
        Serial.println(data);
        delay(1000);
    }
    
    



    알코올 MQ-3 센서 & 일산화탄소 MQ-7 센서 Example

    Alcohol Sensor : MQ-3 + Breakout Board
    Carbon monoxide Sensor : MQ-7 + Breakout Board
    Resistor : 10K 옴


    <내용>




    
    int mq3_analogPin = A0; // connected to the output pin of MQ3
    // int mq7_analogPin = A0;  connected to the output pin of MQ7
    void setup(){
    Serial.begin(9600); // open serial at 9600 bps
    }
    
    void loop()
    {
    // give ample warmup time for readings to stabilize
    int mq3_value = analogRead(mq3_analogPin);
    //int mq7_value = analogRead(mq7_analogPin);
    
    Serial.println(mq3_value); //mq7_value
    delay(1000); //Just here to slow down the output.
    }
    


    가져온곳: URL