我试图将声音传感器数据上传到Thingspeak。连接到Wifi时无法获取数据。
Arduino应该拾取声音,点亮LED并将数据发送到Thingspeak,但是一旦输入了Thingspeak的代码并且它没有发送任何数据,LED就不会响应Thingspeak。
任何帮助都将不胜感激。
#include <Wire.h>
#include "ThingSpeak.h"
#include <SPI.h>
#include <WiFi101.h>
// Create instance of WiFi client
WiFiClient client;
char ssid[] = "Arduino"; // your network SSID (name)
// Add yourThingSpeak channel information here
unsigned long myChannelNumber = 365995;
const char * myWriteAPIKey = "30Y94U59QGRL5OEJ";
const int ledPin = 6; //pin 13 built-in led
const int soundPin = A0; //sound sensor attach to A0
int threshold = 1000; //Set minimum threshold for LED lit
void setup()
{
pinMode(ledPin,OUTPUT);//set pin13 as OUTPUT
Serial.begin(9600); //initialize serial
ThingSpeak.begin(client);
WiFi.begin(ssid);
// Print WiFi strength information
printCurrentNet();
}
void loop()
{
int value = analogRead(soundPin);//read the value of A0
Serial.println(value);//print the value
if(value > threshold) //if the value is greater than 600
{
digitalWrite(ledPin,LOW);//turn off the led
//delay(1000);
}
else
{
digitalWrite(ledPin,HIGH);//turn on the led
ThingSpeak.setField(1, value);
}
}
void printCurrentNet() {
// Print the WiFi signal strength:
long rssi = WiFi.RSSI();
Serial.print("Signal strength (RSSI): ");
Serial.print(rssi);
Serial.println(" dBm");
}