Alternative Temparature sensor / Code problem

Good Day,

I have used Arduino and ESP8266 in this project. I am able to control the GPIO thru internet. I am also able to monitor my room temperature using a LM35 sensor but there are some spikes in the graph. I dont know if the problem is in the LM35 sensor itself or in the code.

Here is the Web Generated code for the Arduiono and ESP8266.

//-- For ESP8266 Lua code.

–visit www.iot-ph.com for more info
–for tutorials http://thinkingparts.blogspot.com/2015/08/home-automation-diy-version-internet_23.html
–This code is for your ESP8266 WIFI Module
–Use Lualoader in uploading your code
–Values to be changed
------------------------------------
ssid=“Your WIFI Name” --you wifi name
sspwd=“Your WIFI Password” --your wifi password
------------------------------------
–Also replace “YOURDEVICEIDHERE” below with your device ID
–Variables
count=0
–set the WIFI Mode
wifi.setmode(wifi.STATIONAP)
wifi.setmode(wifi.STATION)
wifi.sta.config(ssid,sspwd)
function internet()
uart.on(“data”, “\r”,

  • function(data)*

  • print(data)*

  • if (data==nil) then*

  • data=“s1=9&s2=9&s3=9&a1=999&a2=999&a3=999 HTTP/1.1\r\n”*

  • end*

  • count=count+1*

  • if count==250 then*

  • count = 0*

  • end*

  • s1=(string.sub(data,string.find(data,“s1=”)+0,string.find(data," ")+0)) *

  • conn=net.createConnection(net.TCP, 0)*

  • conn:on(“connection”,function(conn, payload)*

  • conn:send(“GET /account/diy_cmd_sts.php?id=YOURDEVICEIDHERE&uid=242&c1=1&c2=1&c3=1&”…(s1)…*

  • “HTTP/1.1\r\n”…*

  • “Host: iot-ph.com\r\n”…*
    _ “Accept: /\r\n”…_

  • “User-Agent: Mozilla/4.0 (compatible; esp8266 Lua;)”…*

  • “\r\n\r\n”)*

  • end)*

  • conn:on(“receive”, function(conn, payload)*

  • conn:close()*

  • payload1=(string.sub(payload,string.find(payload,“cmd1=”)+0,string.find(payload,“cmd1=”)+18))*

  • print(“X”…payload1…“Y”) *

  • –print(“s1”…s1) *

  • end)*

  • conn:connect(80,‘iot-ph.com’)*

  • if data==“quit\r” then*

  • uart.on(“data”)*

  • end*

  • end, 0)*

  • tmr.delay(1000000)*

  • data=0*

  • tmr.alarm(1,4000,1,internet)*
    end
    internet()

//–For Arduino Code
// —THIS IS FOR ARDUINO
// —THIS IS FOR ARDUINO
//For more details visit www.iot-ph.com
//For tutorials visit http://thinkingparts.blogspot.com/2015/08/home-automation-diy-version-internet_23.html
#include <SoftwareSerial.h>
String inData="";
int count=0;
String cmd1, cmd2, cmd3;
String d;
String s1, s2, s3;
String a1, a2, a3;
int sen1, sen2, sen3;
int pinA = 2;
int pinB = 4;
int pinC = 6;
int read1 = 3;
int read2 = 5;
int read3 = 7;
SoftwareSerial mySerial(10, 11); // RX, TX
*void setup() *
{

  • pinMode(pinA,OUTPUT);*

  • pinMode(pinB,OUTPUT);*

  • pinMode(pinC,OUTPUT);*

  • pinMode(read1,INPUT);*

  • pinMode(read2,INPUT);*

  • pinMode(read3,INPUT);*

  • Serial.begin(9600);// Open serial communications and wait for port to open:*

  • while (!Serial) {// wait for serial port to connect. Needed for Leonardo only*

  • ;*

  • }*

  • Serial.println(“www.iot-ph.com Arduino-ESP8266-01!”);*

  • mySerial.begin(9600);// set the data rate for the SoftwareSerial port*
    }
    void loop() // run over and over
    {

  • int count=0;*

  • int ok=0;*

  • if (mySerial.available())*

  • {*

  • while (mySerial.available() > 0)*

  • {*

  • count++;*

  • char received = mySerial.read();*

  • inData += received;*

  • if (received == ‘X’){*

  • inData = “”;*

  • count=0;*

  • ok=1;*

  • }*

  • if ((count==18) && (ok==1))*

  • {*

  • processString();*

  • processStatus();*

  • processSensors();*

  • processSend();*

  • }*

  • }*

  • }*

  • if(!mySerial.available())*

  • {*

  • if (d==""){//initialization value*

  • d=("s1=9&s2=9&s3=9&a1=1024&a2=1024&a3=1024 ");*

  • Serial.println(d);*

  • }*

  • mySerial.println(d);//send data to ESP*

  • delay(5000);*

  • }*
    }
    void processString(){

  • cmd1=inData.substring(5,6);*

  • cmd2=inData.substring(11,12);*

  • cmd3=inData.substring(17,18); *

  • if(cmd1==“2”){*

  • digitalWrite(pinA,HIGH);*

  • }*

  • else if(cmd1==“1”){*

  • digitalWrite(pinA,LOW);*

  • }*

  • if(cmd2==“2”){*

  • digitalWrite(pinB,HIGH);*

  • }*

  • else if(cmd2==“1”){*

  • digitalWrite(pinB,LOW);*

  • }*

  • if(cmd3==“2”){*

  • digitalWrite(pinC,HIGH);*

  • }*

  • else if(cmd3==“1”){*

  • digitalWrite(pinC,LOW);*

  • }*
    }
    void processStatus(){

  • if(digitalRead(read1) == HIGH){*

  • s1=“2”;*

  • }*

  • else{*

  • s1=“1”;*

  • }*

  • if(digitalRead(read2) == HIGH){*

  • s2=“2”;*

  • }*

  • else{*

  • s2=“1”;*

  • }*

  • if(digitalRead(read3) == HIGH){*

  • s3=“2”;*

  • }*

  • else{*

  • s3=“1”;*

  • }*
    }
    void processSensors(){

  • sen1=analogRead(A1);*

  • sen2=analogRead(A2);*

  • sen3=analogRead(A3);*

  • a1 = String(sen1);*

  • a2 = String(sen2);*

  • a3 = String(sen3);*
    }
    void processSend(){

  • d = “s1=” + s1;*

  • d += “&s2=” + s2;*

  • d += “&s3=” + s3;*

  • d += “&a1=” + a1;*

  • d += “&a2=” + a2;*

  • d += “&a3=” + a3;*

  • d += " ";*

  • Serial.println(d);*
    }

the spike you are looking for is the value at 38° in the first picture ??? … that’s not an awfull spike !!

try to do a moving average … it will smooth you data