Tag Archives: analog

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.

Seg 4: Experimental principle of LM35

  1. Experiment and code
    1. Experimental principle

The principle of such experiment is very simple. The voltage data is sensed by the temperature sensor LM35, which would be sent to the analog port (A0 is used in this experiment) on the Arduino board. Then the Celsius (Centigrade) temperature can be output by the linear relationship between the voltage and temperature. For example, in this experiment, we know the linear relationship for the temperature LM35 by one Celsius temperature/10mV. Thus, we can get the voltage value n from the analog port A0 connected LM35 on the Arduino board. Not that, the data n is discrete and located on the range of 0~1024. So, we should change the discrete data n into a continuous voltage to get the Celsius temperature. In fact, the computation is simple. We know that, as for the analog ports A0~A5, the value range is 0~1024, and 1024 is corresponding to 5V. Therefore, if we know the value in A0 port, then we can obtain the discrete voltage value within 0~1024; i.e., the value is n. Then, we can compute the Celsius temperature. Assume that the continue voltage in port A0 on Arduino board is denoted by U. Then, we have the following compute formula by the principle A0 and the linear relationship between Celsius temperature and the continuous voltage.


where vol is the Celsius temperature we should compute, n can be achieved from analog port A0 on the Arduino. Therefore, we can compute the continuous voltage in A0 by equation (1). Then, we substitute the U into equation (2), the Celsius temperature can thus be obtained. In addition, the value of vol (i.e., Celsius temperature) could display on the serial monitor on the Arduino software platform.

Seg 2: Relevant Concepts

4.3 Experimental principle

Before presenting the experiment principle, some relevant concepts should be given out firstly.

Digital signal: its means that its amplitude is discrete, and limited into a range, like binary code used widely in computer science. The digital signal has a strong anti-interference ability, and can be easily processed by digital signal processing. Nowadays, there are many digital signals, such as mobile signal, information handling by computer, and so on.

Analog signal: its ware changes continuously. Theoretically, we can get any of the value from the analog signal. Since it is interfered easily by the other signals, it is difficult to handling. Thus, generally, the analog signal should firstly be transformed into the digital signal for the convenient signal processing. The difference could be shown in Figure 4-1.

Figure 4-1 Difference of digital and analog signals

PWM is the abbreviation of Pulse Width Modulation. It means that we can equivalently get the required signal wave on the basis of a series pulse width, as shown in Figure 4-2. We can achieve a sine signal wave by a series of pulse signal by the different width. In fact, this principle can be illustrated by the equivalent area from mathematical integral. For example, the area of the first pulse is equivalent to the area surrounded by sine signal wave. So, we can change the duty cycle to get the voltage signal wave. Please image it. If we want to get a direct current voltage wave, the width of each pulse should be equal. In addition, PWM technique has been widely applied to the motor speed control, valve control, and so on. For example, PWM has been used to electronic cars.

Figure 4-2 Sine wave by PWM