Jade Perreault
Published © CC BY-SA

WIZnet Interior Sensor Board

Board for sensing voltage /current air temperature and motion via I2C and being sent to Librato for monitoring.

BeginnerFull instructions provided10 hours1,398
WIZnet Interior Sensor Board

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
WIZ750SR
WIZnet WIZ750SR
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Tarantula

Story

Read more

Custom parts and enclosures

Ultimaker Cura

Download and install Cura

Ultimaker Cura

Download and Install Cura Save to SD Card and Print

Schematics

Arduino Hookup For Serial

Code

Simple TX RX Code with DS181 TEmperature Sensor

Clojure
/*
  Software serial multple serial test

 Receives from the hardware serial, sends to software serial.
 Receives from software serial, sends to hardware serial.

 The circuit:
 * RX is digital pin 10 (connect to TX of other device)
 * TX is digital pin 11 (connect to RX of other device)

 Note:
 Not all pins on the Mega and Mega 2560 support change interrupts,
 so only the following can be used for RX:
 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69

 Not all pins on the Leonardo and Micro support change interrupts,
 so only the following can be used for RX:
 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

 created back in the mists of time
 modified 25 May 2012
 by Tom Igoe
 based on Mikal Hart's example

 This example code is in the public domain.

 */
#include <SoftwareSerial.h>
#include <OneWire.h>
#include <DS18B20.h>
SoftwareSerial mySerial(10, 11); // RX, TX
// 1-Wire devices connected to digital pin 2 on the Arduino.
DS18B20 ds(2);
int temp;
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // Print number of devices on the bus.
  Serial.print("Devices: ");
  Serial.println(ds.getNumberOfDevices());
  Serial.println();
  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(115200);
 // mySerial.println("Hello, world?");
}

void loop() { // run over and over
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
     // Iterate through all devices.
  while(ds.selectNext())
  {
    // Print family name.
    switch(ds.getFamilyCode())
    {
      case MODEL_DS18S20:
        Serial.println("Model: DS18S20");
        break;
      case MODEL_DS1820:
        Serial.println("Model: DS1820");
        break;
      case MODEL_DS18B20:
        Serial.println("Model: DS18B20");
        break;
      default:
        Serial.println("Unrecognized Device");
        break;
    }
    
    // Print address.
    uint8_t address[8];
    
    ds.getAddress(address);
    
    Serial.print("Address:");
    
    for(uint8_t i = 0; i < 8; i++)
    {
      Serial.print(" ");
      Serial.print(address[i]);
      
    }
    
    Serial.println();
    
    // Print resolution.
    Serial.print("Resolution: ");
    Serial.println(ds.getResolution());
    
    // Print power mode.
    Serial.print("Power Mode: ");
    
    if(ds.getPowerMode())
    {
      Serial.println("External");
    }
    else
    {
      Serial.println("Parasite");
    }
    
    // Print temperature in degrees Celcius and degrees Fahrenheit.
    Serial.print("Temperature: ");
    Serial.print(ds.getTempC());
    Serial.print(" C / ");
    Serial.print(ds.getTempF());
    Serial.println(" F");
    mySerial.print(":");
    mySerial.print(ds.getTempC());
    
    // Print an empty line.
    Serial.println();
  }
  
  // Wait 10 seconds.
  delay(1000);
}

Complicated Arduino Code with I2C

C/C++
/*
   LTC2945 Test Code // Part of this code is from
  http://www.kevindarrah.com/wiki/index.php?title=Power_Monitor [[Please give Kevin Darrah a big thumbs up]]

   Copyright 2017, Helium Systems, Inc.
   All Rights Reserved. See LICENCE.txt for license information
   Install the following libraries through Sketch->Manage Libraries:
       - ArduinoJson
       - Helium
*/
#include <OneWire.h>
#include "I2Cdev.h"//(MPU6050)
#include "MPU6050_6Axis_MotionApps20.h"
#include <DS18B20.h>//(Temperature Sensor)
#include<stdio.h>
#define BUFSIZE 9
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include "Wire.h"
#endif
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
//=================POWER SENSOR================================
#define LTCADDR B1101111//Table 1 both LOW (7bit address)
byte ADCvinMSB, ADCvinLSB, curSenseMSB, curSenseLSB, AinVMSB, AinVLSB;
unsigned int ADCvin, ADCcur, AinV;
float inputVoltage, ADCvoltage, current10, current1, current0p1, current0p01;
//=============//Declare the relay Pins and Values//=============
const int Relay1 = 5;
const int Relay2 = 6;
int sensorValue = 0;
int sensorValue2 = 0;
int sensorValue3 = 0;
//===========Temperature Sensor======================
DS18B20 ds(7);
uint8_t address[] = {40, 250, 31, 218, 4, 0, 0, 52};
uint8_t selected;
//================//Gyroscope
MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;
#define OUTPUT_READABLE_ACCELGYRO
#define LED_PIN 13
bool blinkState = false;

//====================
int32_t send_interval;
#define LED_PIN 13

void setup() {
  Serial.begin(9600);
  //=======================
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  mySerial.begin(4800);
  mySerial.println("Hello, world?");
  Serial.println("Starting");
  Wire.begin();
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
  Wire.begin();
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
  Fastwire::setup(400, true);
#endif
  Serial.println("Initializing I2C devices...");
  accelgyro.initialize();
  // verify connection
  Serial.println("Testing device connections...");
  Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
  //==================
  Serial.print("Devices: ");
  Serial.println(ds.getNumberOfDevices());
  Serial.println();
  //=================
  // configure Arduino LED pin for output
  pinMode(LED_PIN, OUTPUT);
  pinMode (Relay1, OUTPUT);
  pinMode (Relay2, OUTPUT);
  digitalWrite(LED_PIN, HIGH);
  digitalWrite(Relay1, LOW);
  digitalWrite(Relay2, LOW);
  //==========================


}

void loop() {
  const char data;
  size_t data_used;
  char message[56];
  char msg[56];
  int sensorValue;
  int message1;
  int    status;
  int8_t result;
  int v = (inputVoltage);
  int c = (current0p01);
  int t = (ds.getTempC());
  int m1 = (ax);
  int m2 = (ay);
  int m3 = (az);
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
  //============================================================
  //*************POWER SENSOR***********************
  //===========================================================
  Wire.beginTransmission(LTCADDR);//first get Input Voltage - 30V max
  Wire.write(0x1E);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR, 2, true);
  delay(1);
  ADCvinMSB = Wire.read();
  ADCvinLSB = Wire.read();
  ADCvin = ((unsigned int)(ADCvinMSB) << 4) + ((ADCvinLSB >> 4) & 0x0F);//formats into 12bit integer
  inputVoltage = ADCvin * 0.025; //25mV resolution
  Wire.beginTransmission(LTCADDR);//get ADC Input 2V max
  Wire.write(0x28);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR, 2, true);
  delay(1);
  AinVMSB = Wire.read();
  AinVLSB = Wire.read();
  AinV = ((unsigned int)(AinVMSB) << 4) + ((AinVLSB >> 4) & 0x0F);//12 bit format
  ADCvoltage = AinV * 0.5E-3; //500uV resolution
  Wire.beginTransmission(LTCADDR);//get sense current
  Wire.write(0x14);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR, 2, true);
  delay(1);
  curSenseMSB = Wire.read();
  curSenseLSB = Wire.read();
  ADCcur = ((unsigned int)(curSenseMSB) << 4) + ((curSenseLSB >> 4) & 0x0F);//12 bit format
  current0p1 = ADCcur * (25E-3) / 0.1; //1A max, unit is mA
  Serial.print("Volts_");
  Serial.println(inputVoltage);
  mySerial.write("V %2f",inputVoltage);
  Serial.print("Amps_");
  Serial.println(current0p01, 2);
  mySerial.write("A %2f",current0p01);
  delay(1000);
  //======================================
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
    // display tab-separated accel/gyro x/y/z values
#ifdef OUTPUT_READABLE_ACCELGYRO
  Serial.print("a/g:\t");
  Serial.print(ax); Serial.print("\t");
  mySerial.write("X %2f",(ax));
  Serial.print(ay); Serial.print("\t");
  Serial.println(az); Serial.print("\t");

#endif
  delay(5000);
  //==========================================
  while (ds.selectNext())
  {
    switch (ds.getFamilyCode())
      // Print address.
      uint8_t address[8];
    ds.getAddress(address);
    for (uint8_t i = 0; i < 8; i++)
      (ds.getResolution());
    Serial.print(ds.getTempC());
    mySerial.write("T %2f",ds.getTempC());
    Serial.print(" C / ");
    Serial.print(ds.getTempF()); 
    Serial.println(" F");
    sensorValue = ds.getTempC();
    //==================
    sprintf(data, 75, "V %d:A %d:T %d:X %d:Y %d:Z %d", v, c, t, m1, m2, m3); //NOTE: The values V,A,T,X,Y,Z are needed for the next step
    Serial.println(data);
    mySerial.write(data);
    delay(5000);

  }
  //==================================
  //*************RELAY CONTROL******************
  //=================================
int reading1; 
  reading1 = (ds.getTempC());

  if ( reading1 <= "25") {
    digitalWrite(Relay1, LOW);
    Serial.println("FAN_ON");
  }
  else {
    digitalWrite(Relay1, HIGH);
    Serial.println("FAN_Off");
    delay(1);// delay in between reads for stability
  }

}

Credits

Jade Perreault

Jade Perreault

32 projects • 59 followers
27 Years as a Journeyman Electrician , 4 Years as a PCB design engineer for Penteon Corporation Out of New York ..

Comments