r/ArduinoHelp • • May 24 '25

MKR1010 not communicating with thingspeak channel

1 Upvotes

Hi guys. As my title says I’m having trouble getting my mkr1010 to communicate as intended with my thing speak channel.

Here’s the code I made can you tell me if I’ve missed anything

include <WiFiNINA.h>

include <ThingSpeak.h>

// WiFi credentials

const char* ssid = "";

const char* password = “";

// ThingSpeak credentials

unsigned long myChannelNumber = ;

const char* myWriteAPIKey = "";

WiFiClient client;

// Student ID

const char* studentID = "123456";

// Extract odd and even positioned digits

int sensor1_values[] = {studentID[0] - '0', studentID[2] - '0', studentID[4] - '0'};

int sensor2_values[] = {studentID[1] - '0', studentID[3] - '0', studentID[5] - '0'};

void setup() {

Serial.begin(9600);

// Connect to Wi-Fi

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

Serial.print("Connecting to WiFi: ");

Serial.println(ssid);

delay(1000);

}

Serial.println("Connected to WiFi");

// Initialize ThingSpeak

ThingSpeak.begin(client);

}

void loop() {

// Generate random sensor values

int sensor1_value = sensor1_values[random(0, 3)];

int sensor2_value = sensor2_values[random(0, 3)];

// Print values to Serial Monitor

Serial.print("Sensor 1 Value: ");

Serial.println(sensor1_value);

Serial.print("Sensor 2 Value: ");

Serial.println(sensor2_value);

// Write values to ThingSpeak

ThingSpeak.setField(1, sensor1_value);

ThingSpeak.setField(2, sensor2_value);

// Attempt to write to ThingSpeak

int responseCode = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);

if (responseCode == 200) {

Serial.println("Channel update successful.");

} else {

Serial.println("Problem updating channel. HTTP error code " + String(responseCode));

}

// Wait for 10 seconds

delay(10000);

}