Control Lights With Pressure Sensor & ESP8266 : 6 Steps - josephboung1960
Introduction: Control Lights With Insistence Sensor & ESP8266
On occasion, we come across an article about "Life Hacks That Will Change Your Life" or "Life Hacks Tips". Of course, they give us some very useful tips about sprightliness and miniscule things by which we can make our life history simpler and convenient. So, we definite to hand down a half-size but a very assistive technology hack for you.
We all enjoy reading our favorite books on our chairs. Everyone is so hot that we blank out sometimes to switch Unofficially lamps. And then, we give birth to get up from our chair and switch it ON. We sleep with, IT's precise frustrating. What if, when we seat and side lamps hinge upon mechanically and IT turns Murder once again when we get dormie. IT leave be the best hack ever. Sounds very breathtaking and useful. Proper !! Countenance's make it then.
Whole tone 1: Equipment We Need
1. MPL115A2 Pressure Sensing element
The MPL115A2 employs a MEMS pressure sensor with a conditioning IC to render true coerce measurements from 50 to 115 kPa. It will act your linking part between your movement and side lamp.
2. MCP23008 Relay Comptroller
MCP23008 from Microchip is an United port wine expander that controls eight relays through the I²C bus. You can sum up more relays, digital I/O, linear to digital converters, sensors, and other devices using the integrated I²C expansion port.
3. Adafruit Huzzah ESP8266
The ESP8266 is an incredible platform for IoT application development. The ESP8266 processor from Espressif is an 80 MHz microcontroller with a full WiFi front-end and TCP/IP stack with DNS support as well. The ESP8266 provides a mature platform for monitoring and control applications exploitation the Arduino Cable Language and the Arduino IDE.
4. ESP8266 USB Programmer
This ESP8266 host adapter was created specifically by Contol Everything for the Adafruit Huzzah version of the ESP8266, allowing I²C communicating connections.
5. I²C Connecting Cable
Contol Everything likewise designed the I²C connection overseas telegram which is available at the higher up link.
6. Mini USB Cable
The mini USB cable power supply is a cold choice for powering the Adafruit Huzzah ESP8266.
7. 12V Power Transcriber
MCP23008 Relay controller ideally works on 12V and this can be simply given by a 12V Power Adaptor.
Step 2: Computer hardware Connections
In general, making connections is the simplest part of this project. Play along the instructions and images, and you should make no problems.
1. Connecter of Adafruit Huzzah ESP8266 and USB Programmer
First, select the Adafruit Huzzah ESP8266 and place IT on the USB Programmer (with Inward Facing I²C Larboard). Press the ESP8266 mildly into the USB Programmer and we are done with this step (See characterization #1).
2. Connection of the Sensing element and Adafruit Huzzah ESP8266
Take an I²C Cable and connect it to the Input larboard of the Sensor. For proper procedure of this cable, please retrieve I²C Output Forever connects to the I²C Input. Now, connect the otherwise close of the same I²C Cable to the USB Programmer with Adafruit Huzzah ESP8266 adorned over it (See see #2).
Note: The brown wire should always follow the Ground (GND) connection between the output of one gimmick and the input of another device.
3. Association of the Sensor and MCP23008 Relay Restrainer
Take another I²C Cable, connect one end to the Output port of the Detector and another end on the Input port of the MCP23008 Relay Controller.
4. Powering of the Circuit
Plug in the Mini USB cable into the power jack of Adafruit Huzzah ESP8266. As wel, don't bury to mogul up the Relay Controller with 12V Power Adapter. Jade it in and we are good to go. The concluding connections will look like picture #3.
5. Connecting Your Side Lamp to MCP23008 Relay Controller
Touch base your root lamp that you will to control on the relay part of the MCP23008 Relay Control. Make sure you take all the precautions before doing this step.
Now, just place the sensor below the seat on your chair and we are done we the connections part.
Step 3: Code
The encipher for the MCP23008 Relay Controller and Pressure Sensor is obtainable on our GitHub repository.
Before exit happening to the code, make sure you read the instructions surrendered in the Readme file out and setup your Adafruit Huzzah ESP8266 consequently. It will aim just 5 minutes to pitch the ESP.
For your convenience, you can copy the working ESP code for this sensor from here also:
// Straggly with a free-will license.
// Use it any way you want, profit or free, provided it fits in the licenses of its associated works. // Control Lights with ESP8266 // This encipher is planned to work with the MPL115A2_I2CS I2C Miniskirt Mental faculty available from Dcubestore.com. // http://dcubestore.com/product/mpl115a2/ // hypertext transfer protocol://dcubestore.com/product/i%C2%B2c-relay-controller-8-channel-spdt-10-amp/#include <ESP8266WiFi.h> #admit <WiFiClient.h> #include <ESP8266WebServer.h> #include <Wire.h>
// MPL115A2 I2C address is 0x60(96) #define Addr_Sensor 0x60 // MCP23008_I2CR8G5LE I2C address is 0x20(32) #define Addr_Relay 0x20
const char* ssid = "your ssid network"; const blacken* password = "your password";
unsigned int information[8]; float a1 = 0.0, b1 = 0.0, b2 = 0.0, c12 = 0.0;
ESP8266WebServer server(80);
void handleroot() { // Start I2C Transmittance Wire.beginTransmission(Addr_Relay); // Select IODIR register Wire.write(0x00); // All pins are configured as output Wire.write(0x00); // Stop I2C transmission Wire.endTransmission(); delay(500);
for (int i = 0; i < 8; i++) { // Start I2C Transmission system Wire.beginTransmission(Addr_Sensor); // Select information register Telegram.indite(4 + i); // Stop I2C Transmission Conducting wire.endTransmission();
// Petition 1 byte of data Wire.requestFrom(Addr_Sensor, 1);
// Read 1 byte of information // A10 mutual savings bank, A10 lsb, Bb1 msb, Bb1 lsb, B2 mutual savings bank, B2 lsb, C12 msb, C12 lsb if (Wire.available() == 1) { data[i] = Wire.take(); } }
// Convert the information to natation points a1 = ((data[0] * 256.0) + information[1]) / 8.0; b1 = ((data[2] * 256) + data[3]); if (b1 > 32767) { b1 -= 65536; } b1 = b1 / 8192.0; b2 = ((information[4] * 256) + information[5]); if (b2 > 32767) { b2 -= 65536; } b2 = b2 / 16384.0; c12 = ((data[6] * 256.0 + data[7]) / 4.0) / 4194304.0; delay(300);
// Start I2C Transmission Electrify.beginTransmission(Addr_Sensor); // Mail Pressure measurement command Wire.write(0x12); // Offse conversion Wire.pen(0x00); // Stop I2C Transmission Wire.endTransmission(); check(300);
// Start I2C Transmission Cable.beginTransmission(Addr_Sensor); // Select data register Wire.write(0x00); // Arrest I2C Transmission Wire.endTransmission();
// Request 4 bytes of data Wire.requestFrom(Addr_Sensor, 4);
// Read 4 bytes of data // pres mutual savings bank, pres lsb, temp msb, temp lsb if (Wire.available() == 4) { data[0] = Electrify.read(); information[1] = Wire.read(); data[2] = Telegraph.read(); information[3] = Conducting wire.read(); }
// Convert the data to 10-bits int pres = (information[0] * 256 + (data[1] &A; 0xC0)) / 64; int temp = (data[2] * 256 + (data[3] & 0xC0)) / 64;
// Cipher pressure compensation float presComp = a1 + (b1 + c12 * temp) * pres + b2 * temp;
// Commute the data float imperativeness = (65.0 / 1023.0) * presComp + 50.0; float cTemp = (temp - 498) / (-5.35) + 25.0; float fTemp = cTemp * 1.8 + 32.0;
// Output data to successive monitor Serial.print("Pres : "); Ordination.impress(pressure); Serial.println(" kPa"); Serial.print("Temperature in Celsius : "); Music.print(cTemp); Serial.println(" C"); Serial.black and white("Temperature in Fahrenheit : "); Serial.print(fTemp); Serial.println(" F"); delay(500);
// Output information to Web Server server.sendContent ("<html><head><meta http-equiv='refresh' content='2'</meta>" "<h1 style=text-align:center;font-size:300%;color:dejected;font-family:britannic bold;>CONTROL EVERYTHING</h1>" "<h3 stylus=text edition-align:center;baptismal font-family:messenger new;><a href=http://www.controleverything.com/ aim=_blank>www.controleverything.com</a></h3><hr>" "<h2 style=schoolbook-adjust:center;font-category:tahoma;><a href=https://www.controleverything.com/content/Barometer?sku=MPL115A2_I2CS#tabs-0-product_tabset-2 \n" "target=_blank>MPL115A2 Detector I2C Mini Module</a></h2>"); server.sendContent ("<h3 style=textbook-align:focus on;fount-family:tahoma;>Pressure : " + String(hale) + " kPa"); server.sendContent ("<h3 elan=text-array:center;font-family:tahoma;>Temperature in Celsius = " + Drawing string(cTemp) + " C"); server.sendContent ("<h3 style=text-line up:center;font-family:tahoma;>Temperature in Fahrenheit = " + String(fTemp) + " F");
if (pressure > 136) { // Start I2C Transmission Wire.beginTransmission(Addr_Relay); // Superior GPIO register Wire.write(0x09); // Realy-1 set to logic High Wire.write(0x01); // Stop I2C transmission Wire.endTransmission();
// Output data to serial monitor Serial.println("Side Lamp : ON");
// Output information to WWW Waiter server.sendContent ("<h3 style=text-array:essence;font-kinsperson:tahoma;> Side lamp : ON"); } else { // Start I2C Transmission Wire.beginTransmission(Addr_Relay); // Select GPIO file Wire.write(0x09); // Relay-1 set to logic Low Wire.write(0x00); // End I2C transmission Electrify.endTransmission();
// Output data to consecutive monitor Serial.println("Side Lamp : OFF");
// Output information to World Wide Web Host waiter.sendContent ("<h3 style=schoolbook-ordinate:center;font-family unit:tahoma;> Side Lamp : OFF"); } }
void setup() { // Initialise I2C communication as MASTER Wire.begin(2, 14); // Format serial communicating, set baud = 115200 Ordering.begin(115200);
// Connect to WiFi network WiFi.begin(ssid, password);
// Wait for connective spell (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Successive.println(""); Sequential.mark("Connected to "); In series.println(ssid);
// Get the Information processing address of ESP8266 Asynchronous.print("IP address: "); Serial.println(WiF.localIP());
// Start the server waiter.on("/", handleroot); server.begin(); Serial publication.println("HTTP server started"); }
avoid loop() { waiter.handleClient(); }
Step 4: Practical
Download (git pull off) or copy the code and open IT in the Arduino IDE.
Compose and Upload the encrypt and see the output connected your Serial Monitor.
Bank bill: Before uploading, make sure you enter your SSID network and password in the code.
Straight off, copy the IP cover of ESP8266 from the Music Monitor and paste it in your web browser. You testament run across a web page with pressure reading and status of your side lamp. Ahead moving to the final testing, you have to correct the squeeze value according to your requirements in the if-else shape in the code. When you will sit on your chair, the imperativeness testament increase and it will automatically turn ON your side lamp. Similarly, when you will let-up, it testament turn OFF the side lamp.
The output of the detector on the Serial Monitor and Web Server are shown in a higher place.
Step 5: Applications and Upgrading
With this, you can control your side lamp automatically. None need of going near to the power buttons and turn them on/polish off every time when you need it.
But sometimes, you just need your lights off when you sit on the chair. For that, you can upgrade this project away adding an ON/OFF button on the web page. Now, you give notice control the lights automatically and manually as wel. You have to just pick up your phone, case in the IP address of your ESP and fair-minded bout on/off according to your requirement.
As the sensor can too read temperature and humidity, you can besides control your Alternating current/Heater according to your want. Just unite your Actinium/Heater with Relay Controller, modify the same code and you are done.
Life is to a greater extent simple now, right !!
Step 6: Resources for Releas Further
For more information about MPL115A2, MCP23008 Relay Controller and ESP8266, check up on the links below:
- MPL115A2 Sensor Datasheet
- MCP23008 Relay Controller Datasheet
- ESP8266 Datasheet
Also, you can check our blog happening Base Automation with Light Sensor and ESP8266.
Be the First to Share
Recommendations
-
Anything Goes Contest 2022
Source: https://www.instructables.com/Automatic-Side-Lamp-With-ESP-Pressure-Sensor/
Posted by: josephboung1960.blogspot.com

0 Response to "Control Lights With Pressure Sensor & ESP8266 : 6 Steps - josephboung1960"
Post a Comment