Tag Archives: define

Seg 5: Arduino code

(6) Arduino code

void setup()


Serial.begin(115200);//set baud value


void loop()


int n=analogRead(A0);//define A0 as the received port

float vol=n*(5.0/1023*100);//voltage signal to temperature




void upload_sensor(float vol)


// send the HTTP PUT request:

char buf[200];


int ret;

ret=sprintf(buf,”GET /upload.php?uid=ycf&ps=ycf&sensor_name=arduino&data=”);


Serial.print(buf); //stored at buf temporally

Serial.print(vol);//use temperature data vol

Serial.println(” HTTP/1.1″); //HTTP protocol name

Serial.println(“Host: api.cduino.com”);//set server website

Serial.println(“Connection: close”);//data transmission is finished, and connection is closed.



Then you can download the above code to the Arduino control board. Note that, there is a switch. You should let the switch on the outside (O) when downloading the Arduino code. This is because the serial connection may affect the data download. At the same time, you can track the data transmission on the monitor at the Arduino soft-platform, which is shown in the red label. The temperature is 25.90, and this data has been transmitted to the remote server cloud by wifi networks.