how to send multiple ir sensor data to thingspeak

8 vues (au cours des 30 derniers jours)
Hanumanthu Setty Elluru
Hanumanthu Setty Elluru le 10 Avr 2022
when i was trying to send the data of three IR sensors to the thingspeak, it was taking some time to updated the data in the channel fields. So help me on this.
My code:
#include<IRremote.h>
#include "ThingSpeak.h"
#include "WiFi.h"
//-------Enter your WiFi Details------//
char ssid[] = "GOPAL"; //SSID
char pass[] = "Root@123"; //Password
//-----------------------------------//
//int upload();
WiFiClient client;
//-------------ThingSpeak Details-----------------//
unsigned long myChannelField = 1695129; //Channel ID
const int ChannelField1 = 1; //for Slot1
const int ChannelField2 = 2; //for Slot2
const int ChannelField3 = 3; //for Slot3
const char * myWriteAPIKey = "ID52K7SAKFNHOWW7"; //Your Write API Key
//-----------------------------------------------/
int ledPin1 = 12;// choose pin for the LED
int ledPin2 = 13;
int ledPin3 = 14;
int ir_sensor1 = 18; // choose input pin (for Infrared sensor)
int ir_sensor2 = 19;
int ir_sensor3 = 21;
int S1 = 0,S2=0, S3=0; // variable for reading the pin status
void setup()
{
pinMode(ledPin1, OUTPUT); // declare LED as output
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ir_sensor1, INPUT); // declare Infrared sensor as input
pinMode(ir_sensor2, INPUT);
pinMode(ir_sensor3, INPUT);
Serial.begin(9600);
delay(1000);
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
}
void loop()
{
//-----------------WiFi Setup-------------------//
if(WiFi.status()!= WL_CONNECTED)
{
Serial.print("Attempting to Connect to SSID: ");
Serial.println(ssid);
}
while(WiFi.status()!= WL_CONNECTED)
{
WiFi.begin(ssid,pass);
Serial.print(".");
delay(5000);
}
Serial.println("\nConnected.");
//--------------------------------------------//
//for Ir_sensor1
S1=digitalRead(ir_sensor1);
if (S1 == 0)
{ // check if the input is HIGH
digitalWrite(ledPin1, HIGH); // turn LED OFF
}
else
{
digitalWrite(ledPin1, LOW); // turn LED ON
}
//delay(1000);
//for Ir_sensor2
S2=digitalRead(ir_sensor2);
if (S2 == 0)
{ // check if the input is HIGH
digitalWrite(ledPin2, HIGH); // turn LED OFF
}
else
{
digitalWrite(ledPin2, LOW); // turn LED ON
}
// delay(1000);
//for Ir_sensor3
S3=digitalRead(ir_sensor3);
if (S3 == 0)
{ // check if the input is HIGH
digitalWrite(ledPin3, HIGH); // turn LED OFF
}
else
{
digitalWrite(ledPin3, LOW); // turn LED ON
}
//delay(1000);
upload();
delay(200);
//data send to thingspeak
/* ThingSpeak.writeField(myChannelField,ChannelField1, S1, myWriteAPIKey);
ThingSpeak.writeField(myChannelField,ChannelField2, S2, myWriteAPIKey);
ThingSpeak.writeField(myChannelField,ChannelField3, S3, myWriteAPIKey);*/
}
void upload(){
ThingSpeak.writeField(myChannelField,ChannelField1, S1, myWriteAPIKey);
ThingSpeak.writeField(myChannelField,ChannelField2, S2, myWriteAPIKey);
ThingSpeak.writeField(myChannelField,ChannelField3, S3, myWriteAPIKey);
}

Réponses (1)

yashwanth medishetty
yashwanth medishetty le 15 Nov 2022
can you help me with the code for 2 ir sensors with ESP8266 and thingspeak with count function

Catégories

En savoir plus sur ThingSpeak dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by