PLEASE HELP | Arduino | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
PLEASE HELP
No permission to create posts
October 11, 2018
1:53 am
Avatar
KingVic
New Member
Members
Forum Posts: 2
Member Since:
October 11, 2018
sp_UserOfflineSmall Offline

Hi guys,

I'm completely noob to arduino (apologies in advance) and I am trying to get multiple fields for sound, temperature, humidity, UV, but i can only seem to get a real time visual at temperature field in ThingSpeak.

Here is my code for the gateway:

#include
#include
#include
#include
RH_RF95 rf95;

//If you use Dragino IoT Mesh Firmware, uncomment below lines.
//For product: LG01.
#define BAUDRATE 115200

String myWriteAPIString = "E0IVWK90F2EXPTBA";
uint16_t crcdata = 0;
uint16_t recCRCData = 0;
float frequency = 860.0;
String dataString = "";

void uploadData(); // Upload Data to ThingSpeak.

void setup()
{
Bridge.begin(BAUDRATE);
Console.begin();
// while(!Console);
if (!rf95.init())
Console.println("init failed");
;
// Setup ISM frequency
rf95.setFrequency(frequency);
// Setup Power,dBm
rf95.setTxPower(13);

Console.println("LoRa Gateway Example --");
Console.println(" Upload Single Data to ThinkSpeak");
}

uint16_t calcByte(uint16_t crc, uint8_t b)
{
uint32_t i;
crc = crc ^ (uint32_t)b << 8;

for ( i = 0; i < 8; i++)
{
if ((crc & 0x8000) == 0x8000)
crc = crc << 1 ^ 0x1021;
else
crc = crc << 1;
}
return crc & 0xffff;
}

uint16_t CRC16(uint8_t *pBuffer, uint32_t length)
{
uint16_t wCRC16 = 0;
uint32_t i;
if (( pBuffer == 0 ) || ( length == 0 ))
{
return 0;
}
for ( i = 0; i < length; i++)
{
wCRC16 = calcByte(wCRC16, pBuffer[i]);
}
return wCRC16;
}

uint16_t recdata( unsigned char* recbuf, int Length)
{
crcdata = CRC16(recbuf, Length - 2); //Get CRC code
recCRCData = recbuf[Length - 1]; //Calculate CRC Data
recCRCData = recCRCData << 8; //
recCRCData |= recbuf[Length - 2];
}
void loop()
{
if (rf95.waitAvailableTimeout(2000))// Listen Data from LoRa Node
{
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];//receive data buffer
uint8_t len = sizeof(buf);//data buffer length
if (rf95.recv(buf, &len))//Check if there is incoming data
{
recdata( buf, len);
Console.print("Get LoRa Packet: ");
for (int i = 0; i < len; i++)
{
Console.print(buf[i],HEX);
Console.print(" ");
}
Console.println();
if(crcdata == recCRCData) //Check if CRC is correct
{
if(buf[0] == 1||buf[1] == 1||buf[2] ==1) //Check if the ID match the LoRa Node ID
{
uint8_t data[] = " Server ACK";//Reply
data[0] = buf[0];
data[1] = buf[1];
data[2] = buf[2];
rf95.send(data, sizeof(data));// Send Reply to LoRa Node
rf95.waitPacketSent();
int newData[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; //Store Sensor Data here<<<<<<<<<<<<<Might need to change here
for (int i = 0; i 0)
{
char c = p.read();
Console.write(c);
}
Console.println("");
Console.println("Call Finished");
Console.println("####################################");
Console.println("");
}

Here is the code for client:

/*
Upload Data to IoT Server ThingSpeak (https://thingspeak.com/):
Support Devices: LoRa Shield + Arduino

Example sketch showing how to read Temperature and Humidity from DHT11 sensor,
Then send the value to LoRa Gateway, the LoRa Gateway will send the value to the
IoT server
It is designed to work with the other sketch dht11_server.
modified 24 11 2016
by Edwin Chen
Dragino Technology Co., Limited
*/

#include
#include

RH_RF95 rf95;

#define dht_dpin A0 // Use A0 pin as Data pin for DHT11.
//S = signal analog; V = 5V; G = GND
byte bGlobalErr;
char dht_dat[5]; // Store Sensor Data
char node_id[3] = {1,1,1}; //LoRa End Node ID
float frequency = 860.0;
unsigned int count = 1;

//SDM (Sound Detection Module)
#include

const int soundPin = A1; //sound sensor attach to A1
//int LED_pin = 0;
int sPin = 2;
char db_str[4]; //Store (dB) Sensor data

//For Internal Temperature Sensor and Servof
//#include
//#include

const int sensePin = A2; //This is the Arduino Pin that will read the sensor output attach to A2
int sensorInput = 0; //The variable we will use to store the sensor input
//double Voltage = 0;
double temp; //The variable we will use to store temperature in degrees.

int servoPin = 3;
//ServoTimer2 servo1;

//UV Parts
const int UVPin = A3; // UV
float sensorVoltageUV;
float sensorValueUV;
char uv_str[4];

//////////>>>>>STOP HERE_*_*_*_*_CHECK PIN CONNECTION AGAIN AND AGAIN<<<<<<<<<<////////

void setup()
{
InitDHT();
Serial.begin(9600);
// servo1.attach(servoPin);// Define the servo pin

if (!rf95.init())
Serial.println("init failed");
// Setup ISM frequency
rf95.setFrequency(frequency);
// Setup Power,dBm
rf95.setTxPower(13);

Serial.println("LoRa End Node Example --");
Serial.println(" DHT11 Temperature and Humidity Sensor
");
Serial.print("LoRa End Node ID: ");

for(int i = 0;i 18ms so DHT11 can get the start signal

digitalWrite(dht_dpin,HIGH);
delayMicroseconds(40);//Check the high level time to see if the data is 0 or 1
pinMode(dht_dpin,INPUT);
// delayMicroseconds(40);
dht_in=digitalRead(dht_dpin);//Get A0 Status

// Serial.println(dht_in,DEC);
if(dht_in)
{
bGlobalErr=1;
return;
}
delayMicroseconds(80);//DggHT11 send response, pull low A0 80us
dht_in=digitalRead(dht_dpin);

if(!dht_in)
{
bGlobalErr=2;
return;
}
delayMicroseconds(80);//DHT11 send response, pull low A0 80us
for (i=0; i<5; i++)//Get sensor data
dht_dat[i] = read_dht_dat();
pinMode(dht_dpin,OUTPUT);
digitalWrite(dht_dpin,HIGH);//release signal and wait for next signal
byte dht_check_sum = dht_dat[0]+dht_dat[1]+dht_dat[2]+dht_dat[3];//calculate check sum
if(dht_dat[4]!= dht_check_sum)//check sum mismatch
{bGlobalErr=3;}
}

byte read_dht_dat()
{
byte i = 0;
byte result=0;
for(i=0; i< 8; i++)
{
while(digitalRead(dht_dpin)==LOW);//wait 50us
delayMicroseconds(30);//Check the high level time to see if the data is 0 or 1
if (digitalRead(dht_dpin)==HIGH)
result |=(1<<(7-i));//
while (digitalRead(dht_dpin)==HIGH);//Get High, Wait for next data sampleing.
}
return result;
}
uint16_t calcByte(uint16_t crc, uint8_t b)
{
uint32_t i;
crc = crc ^ (uint32_t)b << 8;

for ( i = 0; i < 8; i++)
{
if ((crc & 0x8000) == 0x8000)
crc = crc << 1 ^ 0x1021;
else
crc = crc << 1;
}
return crc & 0xffff;
}

uint16_t CRC16(uint8_t *pBuffer,uint32_t length)
{
uint16_t wCRC16=0;
uint32_t i;
if (( pBuffer==0 )||( length==0 ))
{
return 0;
}
for ( i = 0; i < length; i++)
{
wCRC16 = calcByte(wCRC16, pBuffer[i]);
}
return wCRC16;
}

//###@@***//
//###@@***//
void loop()
{

MeasuredSound();
readVcc();
TEMP();
Upload_To_Gateway();
// servo();
}

void Upload_To_Gateway()
{
Serial.print("########### ");
Serial.print("COUNT=");
Serial.print(count);
Serial.println(" ###########");
count++;
ReadDHT();
MeasuredSound();
char data[100] = {0} ;
int dataLength = 9; // Payload Length
// Use data[0], data[1],data[2] as Node ID
data[0] = node_id[0] ;
data[1] = node_id[1] ;
data[2] = node_id[2] ;
data[3] = dht_dat[0];//Get Humidity Integer Part
data[4] = dht_dat[1];//Get Humidity Decimal Part
data[5] = dht_dat[2];//Get Temperature Integer Part
data[6] = dht_dat[3];//Get Temperature Decimal Part

//SDM Parts
data[7] = db_str[0];
//data[8] = db_str[3];

//UV Parts
data[8] = uv_str[0];
//data[11] = uv_str[3];

switch (bGlobalErr)
{
case 0:
Serial.print("Current humidity = ");
Serial.print(data[3], DEC);//Show humidity
Serial.print(".");
Serial.print(data[4], DEC);//Show humidity
Serial.println(" % ");

Serial.print("temperature = ");
Serial.print(data[5], DEC);//Show temperature
Serial.print(".");
Serial.print(data[6], DEC);//Show temperature
Serial.println(" C ");

//SDM Parts
Serial.print("Current Sound (dB) = ");
Serial.print(data[7],DEC);
//Serial.print(".");
//Serial.print(data[9]);
Serial.println(" dB ");

//UV Parts
Serial.print("UV = ");
Serial.print(data[11],DEC);//Show UV
//Serial.print(data[12]);
//Serial.print(".");
//Serial.print(data[13]);//Show UV
//Serial.print(data[14]);
Serial.println(" UV");

break;
case 1:
Serial.println("Error 1: DHT start condition 1 not met.");
break;
case 2:
Serial.println("Error 2: DHT start condition 2 not met.");
break;
case 3:
Serial.println("Error 3: DHT checksum error.");
break;
default:
Serial.println("Error: Unrecognized code encountered.");
break;
}

uint16_t crcData = CRC16((unsigned char*)data,dataLength);//get CRC DATA
//Serial.println(crcData,HEX);

Serial.print("Data to be sent(without CRC): ");

int i;
for(i = 0;i < dataLength; i++)
{
Serial.print(data[i],HEX);
Serial.print(" ");
}
Serial.println();

unsigned char sendBuf[50]={0};

for(i = 0;i >14); // Add CRC to LoRa Data

Serial.print("Data to be sent(with CRC): ");
for(i = 0;i >>>>>>New Function Start HERE<<<<<<<###//
// From this part is SDM
void MeasuredSound()
{
int value = analogRead(soundPin);//read the value of A0
float ref_volt = float(readVcc())/1000.0;//read ref voltage

float dbValue;

dbValue = (analogRead(soundPin)/1024.0)*ref_volt*50.0;

db_str[0] = dbValue;

//Serial.print("Recorded Sound = ");
//Serial.print(DB_str[0],DEC);
//Serial.println(" dB");
//delay(1000);

}

long readVcc()
{
// Read 1.1V reference against AVcc
// set the reference to Vcc and the measurement to the internal 1.1V reference
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ADMUX = _BV(MUX5) | _BV(MUX0);
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
ADMUX = _BV(MUX3) | _BV(MUX2);
#else
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#endif

delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Start conversion
while (bit_is_set(ADCSRA,ADSC)); // measuring

uint8_t low = ADCL; // must read ADCL first - it then locks ADCH
uint8_t high = ADCH; // unlocks both

long result = (high<>>>>>>New Function Start HERE<<<<<<= 22)
{
servo1.write(170);
}
else if(temp <= 20)
{
servo1.write(5);
}
}
*/
void UV()
{
sensorValueUV = analogRead(UVPin);
sensorVoltageUV = sensorValueUV/(1024*3.3);
Serial.print("UV sensor reading = ");
Serial.print(sensorValueUV);
Serial.println("");
Serial.print("UV sensor voltage = ");
Serial.print(sensorVoltageUV);
Serial.println(" V");
delay(1000);

uv_str[0] = sensorVoltageUV;

}

October 11, 2018
2:06 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 442
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

Can you describe the desired result, and what you are seeing presently that you don't want to see?
For a new user, I reccomend spending a few minutes on the Get started tutorial. It will save you a lot of confusion later and it shouldn't take too long.
https://www.mathworks.com/help/thingspeak/getting-started-with-thingspeak.html

October 16, 2018
1:14 am
Avatar
KingVic
New Member
Members
Forum Posts: 2
Member Since:
October 11, 2018
sp_UserOfflineSmall Offline

Sorry about my confusing post,

I am still stuck but made some progress...
Basically I want to get a real time feed for temperature humidity, sound, and UV to show on my ThingSpeak channel (under seperate fields e.g. Field 1 for temperature, Field 2 for humidity etc...), where the data is sent from a Node to a Gateway, and then the Gateway uploads it to ThingSpeak. (The Client is the Arduino with all the sensors which needs to transmit data to another Arduino (THE GATEWAY).)

Currently, It seems that the transmitted data is received and im getting accurate numbers for temperature, humidity, and sound however my code only uploads the data into the temperature field and does not upload any data to other fields. I cant seem to find a solution. PLEASE HELP

MY NEW CODE: Gateway code:
------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include
#include
#include
#include
#include
RH_RF95 rf95;

//If you use Dragino IoT Mesh Firmware, uncomment below lines.
//For product: LG01.
#define BAUDRATE 115200

String myWriteAPIString = "E0IVWK90F2EXPTBA";
float frequency = 868.0;
String dataString = "";

void uploadData(); // Upload Data to ThingSpeak.

void setup()
{
Bridge.begin(BAUDRATE);
Console.begin();
// while(!Console);
if (!rf95.init())
Console.println("init failed");
;
// Setup ISM frequency
rf95.setFrequency(frequency);
// Setup Power,dBm
rf95.setTxPower(13);

Console.println("LoRa Gateway Example --");
Console.println(" Upload Single Data to ThinkSpeak");
}

void loop()
{
uploadData();
if (rf95.waitAvailableTimeout(2000))// Listen Data from LoRa Node
{
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];//receive data buffer
uint8_t len = sizeof(buf);//data buffer length

if (rf95.recv(buf, &len))//Check if there is incoming data
{ /*
recdata( buf, len);
Console.print("Get LoRa Packet: ");
for (int i = 0; i < len; i++)
{
Console.print(buf[i],HEX);
Console.print(" ");
}*/
Console.println();
if(buf[0] == 1||buf[1] == 2||buf[2] == 6) //Check if the ID match the LoRa Node ID
{
uint8_t data[] = " Server ACK";//Reply
data[0] = buf[0];
data[1] = buf[1];
data[2] = buf[2];
rf95.send(data, sizeof(data));// Send Reply to LoRa Node
rf95.waitPacketSent();
int newData[6] = {0, 0, 0, 0, 0, 0}; //Store Sensor Data here<<<<<<<<<<<<<Might need to change here
for (int i = 0; i < 6; i++)
{
newData[i] = buf[i + 3];
}
int Tem = newData[0];
int hum = newData[1];
int sou = newData[2];
int s_d = newData[3];
int u_v = newData[4];
int uvd = newData[5];

//Show Temperature
Console.print("Get Temperature: ");
Console.println(float(Tem),DEC);
//Show Humidity
Console.print("Get Humidity: ");
Console.println(float(hum),DEC);
//Show Sound
Console.print("Get Sound: ");
Console.print(sou);
Console.print(".");
Console.println(s_d);
Console.print("Get UV: ");
Console.print(u_v);
Console.print(".");
Console.print(uvd);
Console.println(" mV");

dataString ="Field1=";
dataString += Tem;
dataString +="Field2=";
dataString += hum;
dataString +="Field3=";
dataString += sou;
dataString +=".";
dataString += s_d;
dataString +="Field4=";
dataString += u_v;
dataString +=".";
dataString += uvd;

uploadData();
dataString="";
}
}
}
else
{
Console.println("recv failed");
}
}

void uploadData() //Upload Data to ThingSpeak
{
// form the string for the URL parameter, be careful about the required "
String upload_url = "https://api.thingspeak.com/update?api_key=&quot;;
upload_url += myWriteAPIString;
upload_url += "&";
upload_url += dataString;

// Console.println("");
// Console.println("Call Finished");
// Console.println("####################################");
// Console.println("");
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NEW CLIENT CODE:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include
#include
#include
#include
//#include
#include
#define MINUTE_VALUE 1

//#include

RH_RF95 rf95;

dht DHT_data;

//#### PIR ####
int PIR1 = 2;
int PIR2 = 3;
int PIR3 = 4;
int state = LOW; // by default, no motion detected
int sam, isam;
int state1 = LOW, state2 = LOW;

int i = 0; // variable to store the sensor status (value)
int counter = 0, backup = 0;
int second = 0, minute = 0;
int flag_status = 0;

//#### DHT ####
#define DHT_Pin A0
byte Err = 0;
char node_ID[3] = {1,2,5};
float frequency = 868.0;
unsigned int count = 1;
float read_DHT;
char dht_data[4];

//#### SDM ####
const int soundPin = A1;
//int DPin = 2;
float dbValue;
char db_data[2];

//#### For Internal Temperature Sensor and Servo ####
const int sensePin = A2;
int sensorInput = 0; //The variable we will use to store the sensor input
double Temp; //The variable we will use to store temperature in degrees.

int servoPin1 = 3;
int servoPin2 = 5;

//#### UV ####
const int UVPin = A3;
float sensorValue_UV;
float UV_index;
char uv_data[2];

void setup()
{
Serial.begin(9600);

}
void loop()
{
Inital();
Read_DHT();
Upload_to_Gateway();
MeasuredSound();
readVcc();
internal_Temp();
// long int getDecimal();
// servo();
sensor_UV();
// sensor1();
// sensor2();
// sensor3();

}
void Inital()
{
if(!rf95.init())
{
Serial.println("Initial Failed");
}
rf95.setFrequency(frequency); //Setup ISM Frequency
rf95.setTxPower(13); //Setup for Power (dBm)

Serial.println("##### Sai and Vichai Project #####");
Serial.println("LoRa End Node ID: ");
for(int i = 0; i<3; i++)
{
Serial.print(node_ID[i], HEX);
}
Serial.println();
}

void Upload_to_Gateway()
{
Read_DHT();
MeasuredSound();
Serial.print("########### ");
Serial.print("COUNT= ");
Serial.print(count);
Serial.println(" ###########");
count++;

char send_Data[50] = {0};
int datalength = 9;

send_Data[0] = node_ID[0];
send_Data[1] = node_ID[1];
send_Data[2] = node_ID[2];

send_Data[3] = dht_data[0];
send_Data[4] = dht_data[1];

send_Data[5] = db_data[0];
send_Data[6] = db_data[1];

send_Data[7] = uv_data[0];
send_Data[8] = uv_data[1];

switch(Err)
{
case 0:
Serial.print("Temperature = ");
Serial.print(send_Data[3], DEC);//Show humidity
Serial.println(" % ");
Serial.print("Humidity = ");
Serial.print(send_Data[4], DEC);//Show temperature
Serial.println(" C ");
Serial.print("Sound = ");
Serial.print(send_Data[5], DEC);//Show humidity
Serial.print(".");
Serial.print(send_Data[6], DEC);//Show humidity
Serial.println(" dB ");
Serial.print("UV = ");
Serial.print(send_Data[7], DEC);//Show temperature
Serial.print(".");
Serial.print(send_Data[8], DEC);//Show temperature
Serial.println(" mV ");
break;
case 1:
Serial.println("Error 1: DHT start condition 1 not met.");
break;
case 2:
Serial.println("Error 2: DHT start condition 2 not met.");
break;
case 3:
Serial.println("Error 3: DHT checksum error.");
break;
default:
Serial.println("Error: Unrecognized code encountered.");
break;
}

unsigned char send_Buf[50];
for(int i = 0; i 18ms so DHT11 can get the start signal

digitalWrite(DHT_Pin,HIGH);
delayMicroseconds(40); //Check the high level time to see if the data is 0 or 1
pinMode(DHT_Pin,INPUT);

delayMicroseconds(40);
dht_in=digitalRead(DHT_Pin); //Get A0 Status
//Serial.println(dht_in,DEC);
if(dht_in)
{
Err = 1;
return;
}
delayMicroseconds(80);//DHT11 send response, pull low A0 80us
dht_in=digitalRead(DHT_Pin);

if(!dht_in)
{
Err = 2;
return;
}*/
delayMicroseconds(80);
read_DHT = DHT_data.read11(DHT_Pin);
float read_Tem = DHT_data.temperature;
float read_Hum = DHT_data.humidity;

dht_data[0] = read_Tem;
dht_data[1] = read_Hum;
/*
byte dht_check_sum = dht_data[0]+dht_data[1];//calculate check sum
if(dht_data[2]!= dht_check_sum)//check sum mismatch
{
Err = 3;
}

Serial.print("read_Tem = ");
Serial.println(read_Tem);
Serial.print("read_Hum = ");
Serial.println(read_Hum);
Serial.print("Tem = ");
Serial.println(dht_data[0],DEC);
Serial.print("Hum = ");
Serial.println(dht_data[1],DEC); // Get Decimal part
Serial.println("#############");
delay(1000);
*/
}
void MeasuredSound()
{
int value = analogRead(soundPin);//read the value of A0
float ref_volt = float(readVcc())/1000.0;//read ref voltage

dbValue = (analogRead(soundPin)/1024.0)*ref_volt*50.0; // read and convert analog data to dB

db_data[0] = int(dbValue);
db_data[1] = getDecimal(dbValue);
/*
Serial.print("dbValue = ");
Serial.println(dbValue);
Serial.print("db int = ");
Serial.println(db_data[0],DEC);
Serial.print("db dec= ");
Serial.println(db_data[1],DEC); // Get Decimal part
Serial.println("#############");
delay(1000);
*/
}

long getDecimal(float val)
{
int intPart = int(val);
long decPart = 100*(val-intPart); //I am multiplying by 100 assuming that the foat values will have a maximum of 3 decimal places.
//Change to match the number of decimal places you need
if(decPart>0)return(decPart); //return the decimal part of float number if it is available
else if(decPart<0)return((-1)*decPart); //if negative, multiply by -1
else if(decPart=0)return(00); //return 0 if decimal part of float number is not available
}

void sensor_UV()
{
sensorValue_UV = analogRead(UVPin);
UV_index = sensorValue_UV/1024*5;

uv_data[0] = int(UV_index);
uv_data[1] = getDecimal(UV_index);
/*
Serial.print("UV_index = ");
Serial.println(UV_index);
Serial.print("uv int = ");
Serial.println(uv_data[0],DEC);
Serial.print("uv dec= ");
Serial.println(uv_data[1],DEC); // Get Decimal part
Serial.println("#############");
delay(1000);
*/
}

long readVcc()
{
// Read 1.1V reference against AVcc
// set the reference to Vcc and the measurement to the internal 1.1V reference
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ADMUX = _BV(MUX5) | _BV(MUX0);
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
ADMUX = _BV(MUX3) | _BV(MUX2);
#else
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#endif

delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Start conversion
while (bit_is_set(ADCSRA,ADSC)); // measuring

uint8_t low = ADCL; // must read ADCL first - it then locks ADCH
uint8_t high = ADCH; // unlocks both

long result = (high<= 22)
{
//servo1.write(170);
}
else if(Temp <= 20)
{
//servo1.write(5);
}
}

void sensor1()
{
i = digitalRead(PIR1); // read sensor value
if (i == HIGH)
{ // check if the sensor is HIGH

delay(100); // delay 100 milliseconds

if (state == LOW)
{
Serial.println("SENSOR 111 is detected!");
state = HIGH; // update variable state to HIGH
counter++;

}
}
else
{
delay(200); // delay 200 milliseconds

if (state == HIGH)
{
Serial.println("SENSOR 111 is stopped!");
state = LOW; // update variable state to LOW
}
}
}

void sensor2()
{
sam = digitalRead(PIR2); // read sensor value
if (sam == HIGH)
{ // check if the sensor is HIGH
delay(100); // delay 100 milliseconds

if (state1 == LOW)
{
Serial.println("SENSOR 222 is detected!");
state1 = HIGH; // update variable state to HIGH
counter++;
}
}
else
{
delay(200); // delay 200 milliseconds

if (state1 == HIGH)
{
Serial.println("SENSOR 222 is stopped!");
state1 = LOW; // update variable state to LOW
}
}
}

void sensor3()
{
isam = digitalRead(PIR3); // read sensor value
if (isam == HIGH)
{ // check if the sensor is HIGH
delay(100);

if (state2 == LOW)
{
Serial.println("SENSOR 333 is detected!");
state2 = HIGH; // update variable state to HIGH
counter++;
}
}
else
{
delay(200); // delay 200 milliseconds

if (state2 == HIGH)
{
Serial.println("SENSOR 333 is stopped!");
state2 = LOW; // update variable state to LOW
}
}

}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

October 16, 2018
11:32 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 442
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

You need '&' between each parameter. When you build the datastring, add it between each one (see below). The first one gets a '?'
but you have that already before API_key:
String upload_url = "https://api.thingspeak.com/update?api_key=";

dataString ="&Field1=";
dataString += Tem;
dataString +="&Field2=";
dataString += hum;
dataString +="&Field3=";
dataString += sou;
dataString +=".";
dataString += s_d;
dataString +="&Field4=";
dataString += u_v;
dataString +=".";
etc...

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
40 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

ouktsr, Williampes, esmeraldagx11, lilacs16, loriexo60, ThomasHut

Administrators: Hans: 387, lee: 457