title: Using ADXL345 accelerometer sensor with ESP8266
body: <p>I am extremely new to working with sensors and Arduino and IoT equipment altogether. I am using an Arduino Uno. I need to use an ADXL345 sensor with an ESP8266 Wifi module for a project.  The two devices work on their own just fine. But when I connect them together, with the Generic ESP8266 Module board, the ADXL345 does not get detected.</p>
  <p>I am using the 2.5.0 version of the ESP8266 library as that's the only one that seems to work with both the ESP8266 and the ADXL345 sensor.</p>
  <p>Below is my code -</p>
  <pre><code>#include &lt;Wire.h&gt;
  #include &lt;Adafruit_Sensor.h&gt;
  #include &lt;Adafruit_ADXL345_U.h&gt;
  #include &lt;ESP8266WiFi.h&gt;
  #include &lt;WiFiClient.h&gt;
  
  /* Assign a unique ID to this sensor at the same time */
  Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);
  
  char ssid[] = &quot;ssid&quot;;   // your network SSID (name) 
  char pass[] = &quot;pass&quot;;   // your network password
  int keyIndex = 0;            // your network key Index number (needed only for WEP)
  WiFiClient  client;
  
  void displayDataRate(void)
  {
    Serial.print  (&quot;Data Rate:    &quot;); 
    
    switch(accel.getDataRate())
    {
      case ADXL345_DATARATE_3200_HZ:
        Serial.print  (&quot;3200 &quot;); 
        break;
      case ADXL345_DATARATE_1600_HZ:
        Serial.print  (&quot;1600 &quot;); 
        break;
      case ADXL345_DATARATE_800_HZ:
        Serial.print  (&quot;800 &quot;); 
        break;
      case ADXL345_DATARATE_400_HZ:
        Serial.print  (&quot;400 &quot;); 
        break;
      case ADXL345_DATARATE_200_HZ:
        Serial.print  (&quot;200 &quot;); 
        break;
      case ADXL345_DATARATE_100_HZ:
        Serial.print  (&quot;100 &quot;); 
        break;
      case ADXL345_DATARATE_50_HZ:
        Serial.print  (&quot;50 &quot;); 
        break;
      case ADXL345_DATARATE_25_HZ:
        Serial.print  (&quot;25 &quot;); 
        break;
      case ADXL345_DATARATE_12_5_HZ:
        Serial.print  (&quot;12.5 &quot;); 
        break;
      case ADXL345_DATARATE_6_25HZ:
        Serial.print  (&quot;6.25 &quot;); 
        break;
      case ADXL345_DATARATE_3_13_HZ:
        Serial.print  (&quot;3.13 &quot;); 
        break;
      case ADXL345_DATARATE_1_56_HZ:
        Serial.print  (&quot;1.56 &quot;); 
        break;
      case ADXL345_DATARATE_0_78_HZ:
        Serial.print  (&quot;0.78 &quot;); 
        break;
      case ADXL345_DATARATE_0_39_HZ:
        Serial.print  (&quot;0.39 &quot;); 
        break;
      case ADXL345_DATARATE_0_20_HZ:
        Serial.print  (&quot;0.20 &quot;); 
        break;
      case ADXL345_DATARATE_0_10_HZ:
        Serial.print  (&quot;0.10 &quot;); 
        break;
      default:
        Serial.print  (&quot;???? &quot;); 
        break;
    }  
    Serial.println(&quot; Hz&quot;);  
  }
  
  void displayRange(void)
  {
    Serial.print  (&quot;Range:         +/- &quot;); 
    
    switch(accel.getRange())
    {
      case ADXL345_RANGE_16_G:
        Serial.print  (&quot;16 &quot;); 
        break;
      case ADXL345_RANGE_8_G:
        Serial.print  (&quot;8 &quot;); 
        break;
      case ADXL345_RANGE_4_G:
        Serial.print  (&quot;4 &quot;); 
        break;
      case ADXL345_RANGE_2_G:
        Serial.print  (&quot;2 &quot;); 
        break;
      default:
        Serial.print  (&quot;?? &quot;); 
        break;
    }  
    Serial.println(&quot; g&quot;);  
  }
  
  void setup(void) 
  {
    Serial.begin(115200);
    
    Serial.println(&quot;Accelerometer Test&quot;); Serial.println(&quot;&quot;);
  
     delay(5000);
    
    /* Initialise the sensor */
    if(!accel.begin())
    {
      /* There was a problem detecting the ADXL345 ... check your connections */
      Serial.println(&quot;Ooops, no ADXL345 detected ... Check your wiring!&quot;);
      while(1);
    }
  
    WiFi.mode(WIFI_STA);
  
     delay(5000);
  
    /* Set the range to whatever is appropriate for your project */
    accel.setRange(ADXL345_RANGE_16_G);
    // accel.setRange(ADXL345_RANGE_8_G);
    // accel.setRange(ADXL345_RANGE_4_G);
    // accel.setRange(ADXL345_RANGE_2_G);
    
    /* Display additional settings (outside the scope of sensor_t) */
    displayDataRate();
    displayRange();
    Serial.println(&quot;&quot;);
  }
  
  void loop(void) 
  {
    // Connect or reconnect to WiFi
    if(WiFi.status() != WL_CONNECTED){
      Serial.print(&quot;Attempting to connect to SSID: &quot;);
      Serial.println(ssid);
      while(WiFi.status() != WL_CONNECTED){
        WiFi.begin(ssid, pass);  // Connect to WPA/WPA2 network. Change this line if using open or WEP network
        Serial.print(&quot;.&quot;);
        delay(5000);     
      } 
      Serial.println(&quot;\nConnected.&quot;);
    }
  
    
    /* Get a new sensor event */ 
    sensors_event_t event; 
    accel.getEvent(&amp;event);
   
    /* Display the results (acceleration is measured in m/s^2) */
    Serial.print(&quot;X: &quot;); Serial.print(event.acceleration.x); Serial.print(&quot;  &quot;);
    Serial.print(&quot;Y: &quot;); Serial.print(event.acceleration.y); Serial.print(&quot;  &quot;);
    Serial.print(&quot;Z: &quot;); Serial.print(event.acceleration.z); Serial.print(&quot;  &quot;);Serial.println(&quot;m/s^2 &quot;);
    delay(500);
  }
  </code></pre>
  <p>The circuit connections are as follows -</p>
  <p>ESP8266--</p>
  <ul>
  <li>TX - Arduino TX (D1),</li>
  <li>RX - Arduino RX (D0),</li>
  <li>3.3V - Arduino 3.3V,</li>
  <li>GND - Arduino GND,</li>
  <li>CH_PD - Arduino 3.3V,</li>
  <li>GPIO0 - Arduino GND,</li>
  <li>GPIO2 - No connection,</li>
  <li>RST - No connection</li>
  </ul>
  <p>ADXL345 --</p>
  <ul>
  <li>VCC - Arduino 5V,</li>
  <li>GND - Arduino GND,</li>
  <li>SDA - Arduino SDA,</li>
  <li>SCL - Arduino SCL</li>
  </ul>
  <p>ARDUINO UNO --</p>
  <ul>
  <li>RESET - Arduino GND</li>
  </ul>
  <p>Can someone please, explain to me what I am doing wrong?</p>