# Wifi is not working on Arduino Nano 33 IOT

**URL:** <https://forum.arduino.cc/t/wifi-is-not-working-on-arduino-nano-33-iot/1279904>\
**Category:** Nano 33 IoT\
**Created:** [July 9, 2024, 1:35pm UTC](https://forum.arduino.cc/t/wifi-is-not-working-on-arduino-nano-33-iot/1279904 "2024-07-09T13:35:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kwadlife](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kwadlife/32/1086229_2.png) [@kwadlife](https://forum.arduino.cc/u/kwadlife)\
**Post date:** [July 9, 2024, 1:35pm UTC](https://forum.arduino.cc/t/wifi-is-not-working-on-arduino-nano-33-iot/1279904/1 "2024-07-09T13:35:13Z")

</div>

Dear Arduino Community,

I am reading CO2 values from a CO2 sensor and want to send these files to the Arduino Cloud. Via the MKR NB1500 + sim everything works fine beside frequent break up (the reason why I would like to switch to Nano 33 IOT Wifi Version).

With a simple test code the Arduino Nano 33 IOT is also connecting to Wifi, however once I combine the code (Wifi Application + Sensor readout) the device is simply not establishing a Wifi Connection anymore...

> \*\*\*\*\* Arduino IoT Cloud - configuration info \*\*\*\*\*  
> Device ID: 92a1f313-19b8-4b74-9de5-1adbb544469a  
> MQTT Broker: iot.arduino.cc:8883  
> WiFi.status(): 0  
> Current WiFi Firmware: 1.5.0

Does this might have something to do with the serial communication?  
SSID and PW is definitly correct.

Any help is greatly apprechiated \<3

```arduino
/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  int co2tocloud;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

/*

Pin connections:
Arduino Nano 33 IOT ________ COZIR Sensor
  
GND ------------------- GND
VCC(3.3v) ------------------- VCC(3.3v)  
 TX ------------------- RX
 RX ------------------- TX
*/

int co2 =0;
int CO2Value =0;
double multiplier = 10;// 1 for 2% =20000 PPM, 10 for 20% = 200,000 PPM
uint8_t buffer[25];
uint8_t ind =0;
uint8_t indexi =0;

int fill_buffer(); // function prototypes here
int format_output();

#include "thingProperties.h"

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

  Serial1.begin(9600);
  delay(5000);
  
  Serial1.println("M 6"); // send Mode for Z and z outputs "Z xxxxx z xxxxx" (CO2 filtered and unfiltered)
  Serial1.println("K 1"); // set streaming mode

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 4 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update(); // initialize Arduino Cloud Service

fill_buffer(); // function call that reacds CO2 sensor and fills buffer
 
    for(int j=0; j<ind; j++);
 
  indexi = 8; // In ASCII buffer, filtered value is offset from raw by 8 bytes
  format_output();
    
}

int fill_buffer(void){
// Fill buffer with sensor ascii data
  
ind = 0;
while(buffer[ind-1] != 0x0A){ // Read sensor and fill buffer up to 0XA = CR
  if(Serial1.available()){
    buffer[ind] = Serial1.read();
    ind++;
    } 
  }
  // buffer() now filled with sensor ascii data
  // ind contains the number of characters loaded into buffer up to 0xA = CR
  ind = ind -2; // decrement buffer to exactly match last numerical character
  }

 int format_output(void){ // read buffer, extract 6 ASCII chars, convert to PPM and print

  co2 = buffer[15-indexi]-0x30;
  co2 = co2+((buffer[14-indexi]-0x30)*10);
  co2 +=(buffer[13-indexi]-0x30)*100;
  co2 +=(buffer[12-indexi]-0x30)*1000;
  co2 +=(buffer[11-indexi]-0x30)*10000;

  CO2Value = co2*multiplier;
  
  if (CO2Value >= 0 && CO2Value <= 200000) {
  Serial.println(co2*multiplier,0);
  co2tocloud = co2*multiplier;
  delay(1000);
    } else {
      // Do nothing
 }
 }

```

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [July 9, 2024, 5:02pm UTC](https://forum.arduino.cc/t/wifi-is-not-working-on-arduino-nano-33-iot/1279904/2 "2024-07-09T17:02:29Z")

</div>

> [@kwadlife](#):
>
> ```arduino
> ind = 0;
> while(buffer[ind-1] != 0x0A){ // Read sensor and fill buffer up to 0XA = CR
> 
> ```

what's in `buffer[-1]` ... double check your indexes

* * *

what do you expect from this empty for loop ?

> [@kwadlife](#):
>
> ```arduino
> for(int j=0; j<ind; j++);
> 
> ```

* * *

this is not the right way to read a Serial line.

> [@kwadlife](#):
>
> ```arduino
> while(buffer[ind-1] != 0x0A){ // Read sensor and fill buffer up to 0XA = CR
> if(Serial1.available()){
> buffer[ind] = Serial1.read();
> ind++;
> } 
> }
> // buffer() now filled with sensor ascii data
> // ind contains the number of characters loaded into buffer up to 0xA = CR
> ind = ind -2; // decrement buffer to exactly match last numerical character
> }
> 
> ```

I would suggest to study [Serial Input Basics](http://forum.arduino.cc/index.php?topic=396450.0) to handle this

---

<div class="post-metadata">

**Author:** ![aliarifat794](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@aliarifat794](https://forum.arduino.cc/u/aliarifat794)\
**Post date:** [July 9, 2024, 5:38pm UTC](https://forum.arduino.cc/t/wifi-is-not-working-on-arduino-nano-33-iot/1279904/3 "2024-07-09T17:38:01Z")

</div>

> [@kwadlife](#):
>
> I am reading CO2 values from a CO2 sensor and want to send these files to the Arduino Cloud. Via the MKR NB1500 + sim everything works fine beside frequent break up (the reason why I would like to switch to Nano 33 IOT Wifi Version).
> 
> With a simple test code the Arduino Nano 33 IOT is also connecting to Wifi, however once I combine the code (Wifi Application + Sensor readout) the device is simply not establishing a Wifi Connection anymore...
> 
> > \*\*\*\*\* Arduino IoT Cloud - configuration info \*\*\*\*\*  
> > Device ID: 92a1f313-19b8-4b74-9de5-1adbb544469a  
> > MQTT Broker: iot.arduino.cc:8883  
> > WiFi.status(): 0  
> > Current WiFi Firmware: 1.5.0
> 
> Does this might have something to do with the serial communication?  
> SSID and PW is definitly correct.
> 
> Any help is greatly apprechiated \<3
> 
> ```arduino
> /* 
> Sketch generated by the Arduino IoT Cloud Thing "Untitled"
> 
> Arduino IoT Cloud Variables description
> 
> The following variables are automatically generated and updated when changes are made to the Thing
> 
> int co2tocloud;
> 
> Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
> which are called when their values are changed from the Dashboard.
> These functions are generated with the Thing and added at the end of this sketch.
> */
> 
> /*
> 
> Pin connections:
> Arduino Nano 33 IOT ________ COZIR Sensor
>   
> GND ------------------- GND
> VCC(3.3v) ------------------- VCC(3.3v)  
> TX ------------------- RX
> RX ------------------- TX
> */
> 
> int co2 =0;
> int CO2Value =0;
> double multiplier = 10;// 1 for 2% =20000 PPM, 10 for 20% = 200,000 PPM
> uint8_t buffer[25];
> uint8_t ind =0;
> uint8_t indexi =0;
> 
> int fill_buffer(); // function prototypes here
> int format_output();
> 
> #include "thingProperties.h"
> 
> void setup() {
> Serial.begin(9600);
> delay(5000); 
> 
> Serial1.begin(9600);
> delay(5000);
>   
> Serial1.println("M 6"); // send Mode for Z and z outputs "Z xxxxx z xxxxx" (CO2 filtered and unfiltered)
> Serial1.println("K 1"); // set streaming mode
> 
> // Defined in thingProperties.h
> initProperties();
> 
> // Connect to Arduino IoT Cloud
> ArduinoCloud.begin(ArduinoIoTPreferredConnection);
>   
> /*
> The following function allows you to obtain more information
> related to the state of network and IoT Cloud connection and errors
> the higher number the more granular information you’ll get.
> The default is 4 (only errors).
> Maximum is 4
> */
> setDebugMessageLevel(2);
> ArduinoCloud.printDebugInfo();
> }
> 
> void loop() {
> ArduinoCloud.update(); // initialize Arduino Cloud Service
> 
> fill_buffer(); // function call that reacds CO2 sensor and fills buffer
>  
> for(int j=0; j<ind; j++);
>  
> indexi = 8; // In ASCII buffer, filtered value is offset from raw by 8 bytes
> format_output();
>     
> }
> 
> int fill_buffer(void){
> // Fill buffer with sensor ascii data
>   
> ind = 0;
> while(buffer[ind-1] != 0x0A){ // Read sensor and fill buffer up to 0XA = CR
> if(Serial1.available()){
> buffer[ind] = Serial1.read();
> ind++;
> } 
> }
> // buffer() now filled with sensor ascii data
> // ind contains the number of characters loaded into buffer up to 0xA = CR
> ind = ind -2; // decrement buffer to exactly match last numerical character
> }
> 
> int format_output(void){ // read buffer, extract 6 ASCII chars, convert to PPM and print
> 
> co2 = buffer[15-indexi]-0x30;
> co2 = co2+((buffer[14-indexi]-0x30)*10);
> co2 +=(buffer[13-indexi]-0x30)*100;
> co2 +=(buffer[12-indexi]-0x30)*1000;
> co2 +=(buffer[11-indexi]-0x30)*10000;
> 
> CO2Value = co2*multiplier;
>   
> if (CO2Value >= 0 && CO2Value <= 200000) {
> Serial.println(co2*multiplier,0);
> co2tocloud = co2*multiplier;
> delay(1000);
> } else {
> // Do nothing
> }
> }
> 
> ```

You can add a check to print the WiFi status during setup to see if it gives any specific error messages.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 5, 2025, 5:38pm UTC](https://forum.arduino.cc/t/wifi-is-not-working-on-arduino-nano-33-iot/1279904/4 "2025-01-05T17:38:43Z")

</div>

Closed on January 5, 2025, 5:38pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
