Interface Accelerometer With NodeMCU

by CodeChamp in Circuits > Sensors

25618 Views, 40 Favorites, 0 Comments

Interface Accelerometer With NodeMCU

Cover.jpg

Hey Makers,

I'm with another simple Instructable. In this Instructable we will learn how to interface ADXL335 / GY-61 called as accelerometer with NodeMCU.

Things Needed

7.jpeg

Hardware Requirement

  • ADXL335 : Accelerometer Sensor
  • NodeMCU
  • Connecting Wires
  • BreadBoard
  • Micro USB Cable

Software Requirements

  • Arduino IDE

Description

5.jpeg
6.jpeg
8.jpeg
2.jpeg
4.jpeg

The ADXL335 / GY-61 is a small, thin, low power, complete 3-axis accelerometer with signal conditioned voltage outputs.

The product measures acceleration with a minimum full-scale range of ±3 g.

It can measure the static acceleration of gravity in tilt-sensing applications, as well as dynamic acceleration resulting from motion, shock, or vibration.

There is no on-board regulation, provided power should be between 1.8 and 3.6VDC.

In general, ADXL335 is 3v3 compatible device, it's powered by a 3.3v source and also generates 3.3v peak outputs. It has three outputs for each axis, i.e. X, Y & Z. These are analog outputs and thus require an ADC in a micro-controller. NodeMCU solves this problem. We will be using the analog pin of NodeMCU.

Circuit Connection

Untitled-1.png
C1.jpg
C2.jpg
C3.jpg

The Accelerometer module has 5 pins i.e.,

VCC - To be connected to NodeMCU +3.3v.

X - To be connected to Analog Pin A0 of the NodeMCU.

Y - NIL

Z - NIL

GND - To be connected to Ground Pin (GND) of the NodeMCU.

Note : Since NodeMCU has only one Analog Pin, you can connect either of X, Y, or Z pin to it.

Before you get started with coding you need Arduino IDE.To download Arduino IDE and for NodeMCU setup, you can check my previous instructacle.

Interfacing Servo Motor With NodeMCU

Let's Begin to Code

Code1.PNG
const int xPin = A0;    //x-axis of the Accelerometer
void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
}
<p>void loop() {  <br>  int x = analogRead(xPin);
  delay(100);
  Serial.print("X-axis : ");
  Serial.println(x);
}</p>

Download the "Accelerometer.ino" file and open it up in the Arduino IDE.

Then Create a new sketch and paste the code below in the Arduino IDE and hit Upload.

You can tinker with it if you like based on the application, or just use it as it is.

Downloads

Upload the Code

Code2.PNG
Code3.PNG
  1. Goto Tools
  2. Board > NodeMCU 1.0 (ESP - 12E Module)
  3. Port ( Choose the right Port )

**Make sure you have your NodeMCU model selected and the correct serial port ticked (see pics). Then just click the Upload button**

After you upload the code, you can see the Output on the Serial Monitor.

Output Demonstration

Output2.PNG
Output1.PNG
Output3.PNG

That's all makers!

I hope it helps you.