IOT based temperature data logger using esp8266 and pic microcontroller: Hi everyone I hope you are learning about embedded systems and working on embedded systems based projects. Internet of things is a very popular topic now a days among engineering students and professionals. Many Engineering students works on IOT based projects.In today’s project based on pic microcontroller, you will learn how to make IOT based temperature data logger using pic microcontroller and esp8266 wifi module. ThingSpeak will be used as a live monitoring server of data. You will learn how to send data to a server like thingspeak.com. In this project, we will measure temperature with LM35 temperature sensor using pic microcontroller and we will interface esp8266 wifi module with pic microcontroller. Wifi module is used to send data to server thingspeak. We will plot temperature in the form of graph on thingspeak.
Working OF IOT based temperature data logger using esp8266
In this project we will monitor temperature value using temperature sensor on ThingSpeak. We will display the temperature sensor data over internet using ThingSpeak server. We can access this data from anywhere in the world. So lets first start with how to make account with ThingSpeak.
- First of all go to this website: https://thingspeak.com/users/sign_up and signup for ThingSpeak account. After you signup just login to your account and create your channel. When you login yo your account, you will see this window:
- Now click on New channel. When login to your ThingSpeak server account first time, you will need see any thing like temperature and LM35 as these are the channels created by me. So you will create your first channel by clicking on new channel. When you click on new channel, you will find this window as shown below:
- Now you need to fill the information in this forum. For example we are creating this channel for IOT based temperature data logger, so we will write “temperature” in name option and you can give any description to your project. In field you will select how many graphs you want to plot. So in our case we are using temperature sensor only so will select only one label and give it a name temperature. There is also one option “Make pubic”. You can click this option also if you want to make your sever available to public. Now click on save your channel will be created.
- Now we need to get API keys which we will be using in our code to send and receive data from thingSpeak server. But in this project we are only sending data to server using pic microcontroller and esp8266 wifi module, so we will need only write API key. Now click on API keys options as shown below and copy write API key we will use it later in our program to upload data to server.
- Now click on Data Import / Export option and you will need to copy the URL Update Channel Feed – GET. we will use this URL to upload data to ThingSpeak server. In my case URL is GET https://api.thingspeak.com/update?api_key=6VG8AGD8BXH1ZVC6&field1=0 but in your care it could be different. In this URL you need to post temperature value at the end of field1. For example if you are more than one sensor, you should get more than one fields like field1 and field2.
- Further I will explain in video lecture how we will use this URL to upload temperature value to ThingSpeak. So lets check the circuit diagram and working of IOT based temperature data logger using esp8266 and pic microcontroller. I have upload temperature values of server check the diagram below:
IOT based temperature data logger circuit diagram
Circuit diagram of IOT based temperature data logger is given below:
In above circuit diagram of IOT based temperature data logger using esp8266 and pic microcontroller, we are using PIC18F46K22 microcontroller. PIC18F46K22 measures temperature from LM35 temperature sensor using analog to digital converter. PIC1846K22 has built in 29 channels of analog to digital converters. Its mean we can connect 28 sensors with this pic microcontroller. But we are using only one sensor, so we will use only one channel of PIC18F46K22. LM35 temperature sensor is connect with analog channel zero of PIC16F46K22 microcontroller. Esp8266 wifi module communicate with microcontroller through serial communication and AT commands. you will send AT commands from pic microcontroller to wifi module and esp8266 wifi module will respond to these AT commands accordingly. I will explain these AT commands in later part of this article. you should know how to use serial communication of PIC18F46K22 to send AT commands to WI-FI module. Interfacing circuit is used between PIC18F46K22 and WI-FI module due in difference in operating voltages of both. Operating voltage of PIC18F46K22 is 5 volt and operating voltage of ESP8266 module is 3.3V. WI-FI module will receive data from microcontroller with AT commands and send this data to ThingSpeak server using import URL which I specified earlier.
Video lecture on IOT based temperature data logger
Code explanation for IOT based temperature data logger
First of all ADC module of pic microcontroller is initialize to read value of temperature sensor. LM35 temperature sensor gives output in the form of voltage. This voltage is measured and converted back into voltage using following commands:
adc_val=adc_read(0) // It will read digital value of voltage
adc_val=adc_val x 0.488 // It will convert the digital value into temperature
Following AT commands are you to configure ESP8266 module and used to send data to ThingSpeak server.
- “AT” it is used to check response of module
- “ATE0\r\n” It is used to stop Echo back from WI-FI module
- AT+CWMODE=3 : it is used to configure WI-FI module both as a station and client
- AT+CWQAP : It is used to disconnect WI-FI module from current network
- AT+CWJAP=\”PTCL-BB\”,\”F4C0A9AB\”” : This command will connect with WI-FI module with internet connect name “PTCL-BB” and password “F4C0A9AB” . you should use your own WI-FI name and password.
- “AT+CIPSTART=4,\”TCP\”,\”18.104.22.168\”,80″: This command is used to set the port connection and address of port. Where 22.214.171.124 is IP address of ThingSpeak.com
- AT+CIPSEND=4,46 : This commands tells the WI-FI module how many bytes we want to send to server
- GET /update?key=8W4TM1V37CI3MZI5&field1=value : This command will send the value to server.