In this blog post I talk about how you can use a 801S Wide Range Vibration Detection sensor with a WeMos D1 Mini (ESP8266) using the Arduino IDE.
Summary of the 801S Wide Range Vibration Detection sensor
This vibration sensor works by the sensor changing resistance as motion is detected. This is then translated into an electrical signal that is reported back on the analogue out pin.
This sensor also has a digital pin which will go HIGH when a level of vibration is reached.
When using this with the WeMos (ESP8266) the analogue output will range between 0 and 3.3 volts. Here 0 volts represents there is no motion and 3.3 volts represents a large amount.
Since we have both options we can change whether we use analogue or digital based on the needs of the project. This is very useful for the WeMos (ESP8266) as there is only one analogue pin.
Important differences compared with using the 801S Wide Range Vibration Detection sensor on an Arduino
It is important to remember the the WeMos D1 Mini (ESP8266) has a number of differences to an Arduino.
The Arduino IDE is configured to use the Arduino set of chips which mean the standard pin numbers do not refer to the pins on the WeMos. Instead of using 1 to refer to digital pin 1, you will need to use the constant D1.
I go into more details for this in my blog post Pin numbering for WeMos D1 Mini (ESP8266). If you haven’t read this and are having trouble connecting your 801S Wide Range Vibration Detection sensor properly I recommend having a read.
Wiring it up to a WeMos D1 Mini
The 801S Wide Range Vibration Detection sensor has four pins and for this I will be using the analogue output pin to read the output.
This pin is the leftmost pin, labelled Aout which is connected to the A0 pin on the WeMos.
The second pin, labelled - on the sensor is attached the the GND pin on the WeMos.
The final ping, the rightmost, is labelled + and is attached the the 3.3 volt pin on the WeMos. It is important to not connect this to the 5 volt pin as this may cause damage to the WeMos.
Programming the WeMos to use the vibration sensor
I am going to use the analogue pin to record the level of vibration and print it on the serial line.
Since the WeMos D1 mini only has one analogue pin we have to connect the sensor to analogue pin 0.
Inside the loop method, the analogue pin is read and printed out to the serial connection. At the end of the loop we delay 10 milliseconds to read the next value.
The 801S Wide Range Vibration Detection sensor is a relatively small vibration sensor. One of the major advantages of this sensor is that it has both a digital and analogue output. This allows you to pick which to use depending on the situation. This is especially useful for the WeMos as this only has one analogue pin.
Another advantage is that since this only uses either a digital or analogue pin to read the output no specific ESP8266 libraries are needed. The only important thing to remember is that you must connect the sensor to the 3.3 volt pin to avoid damaging the WeMos.