Alternative Temparature sensor / Code problem


good day,

i have used arduino , esp8266 in project. able control gpio thru internet. able monitor room temperature using lm35 sensor there spikes in graph. dont know if problem in lm35 sensor or in code.



here web generated code arduiono , esp8266.


//-- for esp8266 lua code.

--visit www.iot-ph.com more info
--for tutorials http://thinkingparts.blogspot.com/2015/08/home-automation-diy-version-internet_23.html



--this code esp8266 wifi module
--use lualoader in uploading code


--values changed
------------------------------------
ssid="your wifi name"      --you wifi name
sspwd="your wifi password"   --your wifi password
------------------------------------
--also replace "yourdeviceidhere" below device id


--variables
count=0

--set 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 arduino
//   ---this 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 , wait port open:
  while (!serial) {// wait serial port connect. needed leonardo only
    ;
  }
  serial.println("www.iot-ph.com arduino-esp8266-01!");
  myserial.begin(9600);// set data rate softwareserial port
}

void loop() // run on , 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 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 looking value @ 38° in first picture ??? ... that's not awfull spike !!

try moving average ... smooth data


Arduino Forum > Topics > Home Automation and Networked Objects > Alternative Temparature sensor / Code problem


arduino

Comments