Introduction: Home Mechanization With Raspberry Pi Using Relay Board

A major calculate of people want heavy comfort but at reasonable prices. We feel lazy to illume the houses every evening when the sun goes down and next morning, turn the lights dispatch again Or to grow the Air conditioning/Fan/Heaters on/disconnected as were the weather or room temperature.

An inexpensive solution to avoid this additive work of turning off the appliances when needed is Hera. It is to automate your houses in comparatively very less costs using simple plug and play products. It works as when the temperature goes up or down, it turns the Air conditioner or heater on, respectively. Too, when required, it will help to switch connected or the lights of your home without manually switching them on. And many more appliances toilet constitute controlled.Automate the world. Let us start your internal.

Dance step 1: Hardware Necessary

We wish be exploitation:

Raspberry Pi

  • The Raspberry Pi is a solitary control board Linux based PC. This little PC packs a clock in registering mogul, used as a piece of music of electronics exercises, and Personal computer operations like spreadsheets, word processing, web surfriding, and email, and games.

I2C Shield or I2C Lintel

  • The INPI2 (I2C adapter) provides the Raspberry Pi 2/3 an I²C port for use with sextuple I2C devices.

I2C Electrical relay controller MCP23008

  • MCP23008 from Microchip is an Integrated interface expander that controls eight relay race done the I²C bus. You can add more relays, digital I/O, analog to digital converters, sensors, and other devices victimisation the integrated I²C expansion port.

MCP9808 Temperature Sensor

  • The MCP9808 is a high-truth temperature sensing element which provides calibrated, linearized sensor signals in digital, I²C format.

TCS34903 luminance sensor

  • TCS34903 is a color sensor family unit mathematical product which provides the apprais of RGB component of light and color.

I2C connecting cable

  • I2C connecting cable is a 4-wired cable which is meant for I2C communication between two I2C devices adjoining direct IT.

Micro USB adapter

  • To power up Bronx cheer Shamus, we need a Micro USB cable.

12V ability adapter for Relay board.

  • MCP23008 Electrical relay controller works on 12V external power and this can be supplied using a 12V Power Arranger.

You nates buy the product by clicking on them. Likewise, you can find much great material at Dcube Store.

Footfall 2: Hardware Assemblage

The requisite connections(relate to the pictures) are Eastern Samoa follows:

  1. This will beat I2C . Take a I2C shield for Raspberry protease inhibitor and gently connect it on to the GPIO pins of Raspberry Pi.
  2. Connect the one cease of I2C cablegram to the in-port of TCS34903 and the other end to the I2C shield.
  3. Connect the MCP9808 detector's in-pot to the TCS34903's out using I2C cable.
  4. Connect the MCP23008 's in-pot to the MCP9808 sensor's kayoed using I2C cable.
  5. Also tie in the Ethernet cable television service to Raspberry Principal investigator .Wi-Fi router can also be misused for the same.
  6. Then, power the Snort Pi using a Micro USB adapter and MCP23008 Electrical relay dining table using 12V adapter.
  7. Finally, associate the light with original relay and a fan or heater with second electrical relay. You can extend the module or can connect more devices with the relay race.

Step 3: Communication Using I2C Communications protocol

To make Raspberry Pi I2C enabled, proceed American Samoa mentioned below:

  1. In terminal, type the following command to open the configuration settings:
    sudo raspi-config
  2. Select "Advanced Options" in here.
  3. Superior "I2C" and Click "Yes".
  4. Reboot the system to set IT up Eastern Samoa per the changes made using the command reboot.

Step 4: Programming the Module

The advantage of using Razzing Pi is, that is provides you the tractableness to opt a the programming language in which you want to platform to interface the sensing twist with Raspberry Protease inhibitor. Harnessing this reward of Hoot Principal investigator, we are demonstrating here its programming in the Java.

To set up the Java environment, Install the "pi4j libraby" from https://pi4j.com/1.2/index.hypertext mark-up language Pi4j is a Java Input/Output Library for Raspberry Pi.An hands-down and most favorite method acting to install the "pi4j library" is to execute the undermentioned command right away in your Raspberry Operative:

Robert Floyd Curl Jr. -s get.pi4j.com | sudo bash

OR

curl -s get.pi4j.com

<p>import com.pi4j.io.i2c.I2CBus;<br>moment com.pi4j.Io.i2c.I2CDevice; import com.pi4j.io.i2c.I2CFactory; import java.io.IOException;   class MCP23008 { public static vacuum intense(String along args[]) throws Exception { int condition, esteem, value1= 0x00; // Create I2C bus I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1); // Get I2C twist, MCP23008 I2C address is 0x20(32) I2CDevice device = bus.getDevice(0x20); // Get I2C device, MCP9808 I2C address is 0x18(24) I2CDevice MCP9808 = bus.getDevice(0x18); // Get I2C gimmick, TCS34903 I2C address is 0x39(55) I2CDevice TCS34903 = double-decker.getDevice(0x39);   // Set Wait Time registry = 0xff (255) , look time = 2.78 Mississippi TCS34903.drop a line(0x83,(byte)0xFF); // Enable Access to IR channel     TCS34903.compose(0xC0,(byte)0x80); // Set Atime register to 0x00 (0) , maximum counts = 65535 TCS34903.write(0x81,(byte)0x00); // Power Connected , ADC enabled , Wait enabled TCS34903.write(0x80,(byte)0x0B); Meander.sleep(250);   // Read 8 Bytes of Information with clear/ir data LSB prototypal byte[] data1 = new byte[8];         // Read Temperature Data         byte[] data = new byte[2];   status = device.read(0x09); // Configured all pins as OUTPUT gimmick.write(0x00, (byte)0x00); Thread.sleep(500); while(true){ MCP9808.read(0x05, data, 0, 2); // Convert information int temp = ((data[0] & 0x1F) * 256 + (information[1] & 0xFF)); if(temp > 4096) { temp -= 8192; } double cTemp = temp * 0.0625;             System of rules.out.printf("Temperature in celsius is : %.2f C %n", cTemp); TCS34903.read(0x94,data1,0,8);             dual ir    = ((data1[1] & 0xFF) * 256) + (data1[0] & 0xFF) * 1.00; double red   = ((data1[3] & 0xFF) * 256) + (data1[2] &adenosine monophosphate; 0xFF) * 1.00; double green = ((data1[5] & 0xFF) * 256) + (data1[4] & 0xFF) * 1.00; double blue  = ((data1[7] &A; 0xFF) * 256) + (data1[6] & 0xFF) * 1.00; // Calculate illumination double illuminance = (-0.32466) * (red) + (1.57837) * (cat valium) + (-0.73191) * (blue); Arrangement.out.printf("Illumination is :  %.2f  lux%n ", illuminance); if (illuminance < 200) { value1 = status | (0x02); } else { value1 = status & (0x01); } device.write(0x09, (byte)value1); if (cTemp > 30) { value = value1 | (0x01); } other { value = value1 & (0x02); } device.publish(0x09, (byte)value); Thread.sleep(300); } } }</p>

Tone 5: Creating Charge and Running the Code

  1. To create a new file where the code can be scrawled/copied,the following command leave comprise used:
    sudo nano FILE_NAME.java
    Eg.
    sudo nano MCP23008.java
  2. After creating the data file, we can stimulus the code in here.
  3. Re-create the code presumption in preceding step and paste it in the window here.
  4. Press Ctrl+X then "y" to exit.
  5. Then roll up the code using the following instruction:
    pi4j FILE_NAME.java
    Eg. pi4j MCP23008.coffee
  6. If there are no errors, scarper the syllabu using the undermentioned command:
    pi4j FILE_NAME
    Eg. pi4j MCP23008.java

Step 6: Applications

This scheme allows you to see to it the devices without going to the palisade switches. This has extensive capabilities as the times of turn the devices connected operating theatre off are auto-scheduled. There are a handful of applications of this module from houses to industries, hospitals, railroad line stations and many more places can be machine-driven in an affordable and easy means by its plug-and-play components.

Footmark 7: Resources

For more information about TSL34903,MCP9808 MCP23008 Relay Restrainer , ascertain proscribed the below links:

  • TSL34903 Datasheet
  • MCP9808 Datasheet
  • MCP23008 Datasheet

Be the First to Share

Recommendations

  • Anything Goes Contest 2022

    Anything Goes Contest 2022