Reg no: 19BEC1402 Lab_Experiment_3
Name: Vivekanandan V Date: 27/08/2021
Light Intensity Monitor using WebAPI
Aim:
To monitor the Intensity of Light and plot the data as a Graph in webAPI or Thinkspeak.
Components:
Arduino Uno R3
Multimeter
Wifi Module ESP-8266
Photoresistor
Resistors x3
Wires
Procedure:
Open Tinkercad online and create account using Email
Select circuits under the side panel
Change file name
Open the Components library and draw the required components into the Workspace
Connect them properly
Open code in txt format and give the appropriate code.
Open Thinkspace Webpage
Create a Channel
Copy the Unique API key and Paste it in the code
Stimulate
Circuit:
Code:
String ssid = "Simulator Wifi";
String password = ""; // Our virtual wifi has no password (so dont do your banking stuff on this network)
String host = "api.thingspeak.com";
const int httpPort = 80;
// provide your API key below in between thr '=' sign and '&' sign
String uri = "/update?api_key=9W0UVIKCXZWTNDFO&field1=";
int setupESP8266(void)
{
// Start our ESP8266 Serial Communication
Serial.begin(115200); // Serial connection over USB to computer
Serial.println("AT"); // Serial connection on Tx / Rx port to ESP8266
delay(10); //Wait a little for the ESP to respond
if (!Serial.find("OK"))
return 1;
// Connect to 123D Circuits Simulator Wifi
Serial.println("AT+CWJAP=\"" + ssid + "\",\"" + password + "\"");
delay(10); // Wait a little for the ESP to respond
if (!Serial.find("OK")) return 2;
// Open TCP connection to the host:
Serial.println("AT+CIPSTART=\"TCP\",\"" + host + "\"," + httpPort);
delay(50); // Wait a little for the ESP to respond
if (!Serial.find("OK"))
return 3;
return 0;
}
int anydata(void)
{
int temp = map(analogRead(A0),20,358,-40,125);
// Construct our HTTP call
String httpPacket = "GET " + uri + String(temp) + " HTTP/1.1\r\nHost: " + host +"\r\n\r\n";
int length = httpPacket.length();
// Send our message length
Serial.print("AT+CIPSEND=");
Serial.println(length);
delay(10); // Wait a little for the ESP to respond
if (!Serial.find(">"))
return -1;
// Send our http request
Serial.print(httpPacket);
delay(10); // Wait a little for the ESP to respond
if(!Serial.find("SEND OK\r\n"))
return 0;
}
void setup()
{
setupESP8266();
int pin= 7;
pinMode(pin,OUTPUT);
}
void loop()
{
anydata();
delay(100);
Output:
Graph:
Inference:
We can infer that the graph keeps on varying for different light intensity adjusted in the photoresistor,
also this adjustment voltage can be measured in the multimeter connected to it.
Result:
Hence the output has been obtained and verified. The graph has been plotted in WebAPI or thinkspeak.