Electric Solenoid Valve

solenoid

http://www.ebay.com/itm/400422235090

Control mode: DC 12V.
Use of media: liquid water, such as other liquid suitable for the product.
Medium temperature is about: 1 ~ 100 °C.
Connection: is exceptionally thread.
Solenoid valve Material: Body part of the plastic connector for copper.
Voltage range: ± 10% of rated voltage.
Water pressure range: 0.02 ~ 0.8Mpa.
Filtering capabilities:removable cleaning filtration devices.
Action characteristics:no abnormality 100000.
Return function: Possess.

Size:8cm x 8.8cm x 5cm – 3.15inch x 3.46inchx 1.97inch.

 

How can a solenoid valve be used with an arduino?

You can use it with RTC module to schedule watering plants, Smoke sensors and many other uses.

solenoid arduino

This a simple project just to test the valve. (arduino is communicating serial)

Advertisements
Posted in Arduino Microcontrollers | Tagged , , , , | Leave a comment

Cheap 12v 2A Power Supply for simple projects

psu 2A

I recieved this little psu today. It’s a 100-240 to 12v 2A regulated.

Size:L86 x W60 x D34 mm.

For $6.66 it’s a good deal.

http://www.ebay.com/itm/330936337307

Posted in Arduino Microcontrollers | Tagged , , , | Leave a comment

ETHERNET ENC28J60 + 4 Relay Modules (simple sketch)

web4relay

Ok so this is the easiest way to control 4 relays on a webserver controlled by ENC28J60.

You can download the library here

https://docs.google.com/file/d/0B4qM0hq-OmC1RHhEcXRNSmZ1YW8/

 

// A simple web server that turn a Relay on or off”

#include “etherShield.h”
#include “ETHER_28J60.h”
#define RELAY1  22 //Digital Pin 22
#define RELAY2  23
#define RELAY3  24
#define RELAY4  25
#define RELAY5  26
#define RELAY6  27

static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24};   // this just needs to be unique for your network,

static uint8_t ip[4] = {192, 168, 1, 3}; // IP address for the webserver

static uint16_t port = 240; // Use port 80 – the standard for HTTP – MAX 240port

ETHER_28J60 e;

void setup()
{
e.setup(mac, ip, port);
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
pinMode(RELAY4, OUTPUT);
digitalWrite(RELAY1,HIGH);
digitalWrite(RELAY2,HIGH);
digitalWrite(RELAY3,HIGH);
digitalWrite(RELAY4,HIGH);
}

void loop()

{

char* params;
if (params = e.serviceRequest())
{
e.print(“<h1><a href=’/?led1=off&led2=off’>Relay Control Panel</a></h1>”);
e.print(“<h1><a href=’/?rele3=off&rele4=off’>Relay Control Panel 2</a></h1>”);

if (strcmp(params, “?led1=on&led2=off”) == 0)
{
pinMode(RELAY1, HIGH);
pinMode(RELAY2, LOW);
e.print(“<a href=’?led1=off&led2=off’><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 1 IS ON</button></a><a href=’?led1=on&led2=on’><br/><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 2 IS OFF</button></a>”);
}
else if (strcmp(params, “?led1=off&led2=on”) == 0)
{
pinMode(RELAY1, LOW);
pinMode(RELAY2, HIGH);
e.print(“<a href=’?led1=on&led2=on’><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 1 IS OFF</button></a><a href=’?led1=off&led2=off’><br/><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 2 IS ON</button></a>”);
}
else if (strcmp(params, “?led1=off&led2=off”) == 0)
{
pinMode(RELAY1, LOW);
pinMode(RELAY2, LOW);
e.print(“<a href=’?led1=on&led2=off’><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 1 IS OFF</button></a><a href=’?led1=off&led2=on’><br/><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 2 IS OFF</button></a>”);
}
else if (strcmp(params, “?led1=on&led2=on”) == 0)
{
pinMode(RELAY1, HIGH);
pinMode(RELAY2, HIGH);
e.print(“<a href=’?led1=off&led2=on’><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 1 IS ON</button></a><a href=’?led1=on&led2=off’><br/><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 2 IS ON</button></a>”);
}
else if (strcmp(params, “?rele3=on&rele4=off”) == 0)
{
pinMode(RELAY3, HIGH);
pinMode(RELAY4, LOW);
e.print(“<a href=’?rele3=off&rele4=off’><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 3 IS ON</button></a><a href=’?rele3=on&rele4=on’><br/><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 4 IS OFF</button></a>”);
}
else if (strcmp(params, “?rele3=off&rele4=on”) == 0)
{
pinMode(RELAY3, LOW);
pinMode(RELAY4, HIGH);
e.print(“<a href=’?rele3=on&rele4=on’><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 3 IS OFF</button></a><a href=’?rele3=off&rele4=off’><br/><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 4 IS ON</button></a>”);
}
else if (strcmp(params, “?rele3=off&rele4=off”) == 0)
{
pinMode(RELAY3, LOW);
pinMode(RELAY4, LOW);
e.print(“<a href=’?rele3=on&rele4=off’><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 3 IS OFF</button></a><a href=’?rele3=off&rele4=on’><br/><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 4 IS OFF</button></a>”);
}
else if (strcmp(params, “?rele3=on&rele4=on”) == 0)
{
pinMode(RELAY3, HIGH);
pinMode(RELAY4, HIGH);
e.print(“<a href=’?rele3=off&rele4=on’><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 3 IS ON</button></a><a href=’?rele3=on&rele4=off’><br/><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 4 IS ON</button></a>”);
}

e.respond();
}
}

Posted in Arduino Project | Tagged , , , | Leave a comment

bh1750fvi (GY-302) Light Sensor Module

bh1750fvi

Signaling Type I2C

This sketch requires BH1750.h library.

You can download the library here

https://docs.google.com/file/d/0B4qM0hq-OmC1RHhEcXRNSmZ1YW8/

/*

Example of BH1750 library usage.

This example initalises the BH1750 object using the default
high resolution mode and then makes a light level reading every second.

Connection:
VCC-5v
GND-GND
SCL-SCL(analog pin 5)
SDA-SDA(analog pin 4)
ADD-NC or GND

*/

#include <Wire.h>
#include <BH1750.h>

BH1750 lightMeter;

void setup(){
Serial.begin(9600);
lightMeter.begin();
Serial.println(“Running…”);
}

void loop() {
uint16_t lux = lightMeter.readLightLevel();
Serial.print(“Light: “);
Serial.print(lux);
Serial.println(” lx”);
delay(1000);
}

Posted in Arduino Project | Tagged , , , , | 7 Comments

ENC28J60 Stand-Alone Ethernet Controller with SPI Interface

ENC28J60

Documentation about this chip:

http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en022889

Library:

https://docs.google.com/file/d/0B4qM0hq-OmC1RHhEcXRNSmZ1YW8/

Wiring with MEGA 2560:

ENC28J60  pin  —  MEGA 2560 pin

SO — 50

SI — 51

SCK — 52

CS —  53

GND — GND

VCC — 3.3v

Posted in Arduino Microcontrollers | Tagged , , , | Leave a comment

Water Flow Sensor

flowsensor_LRG
Wiring up the Water Flow Sensor is pretty simple. There are 3 wires: Black, Red, and Yellow. 

Black to the Seeeduino's ground pin
Red to Seeeduino's 5v pin
The yellow wire will need to be connected to a 10k pull up resistor.and then to pin 2 on the Seeeduino.

Here is a fritzing diagram I made to show you how to wire it all up.
 water_flow
// reading liquid flow rate using Seeeduino and Water Flow Sensor from Seeedstudio.com
// Code adapted by Charles Gantt from PC Fan RPM code written by Crenn @thebestcasescenario.com
// http:/themakersworkbench.com http://thebestcasescenario.com http://seeedstudio.com

volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;                               
int hallsensor = 2;    //The pin location of the sensor

void rpm ()     //This is the function that the interupt calls 
{ 
  NbTopsFan++;  //This function measures the rising and falling edge of the 

hall effect sensors signal
} 
// The setup() method runs once, when the sketch starts
void setup() //
{ 
  pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
  Serial.begin(9600); //This is the setup function where the serial port is 

initialised,
  attachInterrupt(0, rpm, RISING); //and the interrupt is attached
} 
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop ()    
{
  NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
  sei();            //Enables interrupts
  delay (1000);      //Wait 1 second
  cli();            //Disable interrupts
  Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate 

in L/hour 
  Serial.print (Calc, DEC); //Prints the number calculated above
  Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a  new line
}
Posted in Arduino Project | Leave a comment

ETHERNET ENC28J60 + 5 Relay Modules (1 Relay on Temperature Sensor)

This sketch requires etherShield, ETHER_28J60 and OneWire library.

You can download the library here

https://docs.google.com/file/d/0B4qM0hq-OmC1RHhEcXRNSmZ1YW8/

// A simple web server that turn a Relay on or off”

#include “etherShield.h”
#include “ETHER_28J60.h”
#define RELAY1  22
#define RELAY2  23
#define RELAY3  24
#define RELAY4  25
#define RELAY5  26
#include <OneWire.h>
int DS18S20_Pin = 2;
OneWire ds(DS18S20_Pin);

static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24};   // this just needs to be unique for your network,

static uint8_t ip[4] = {192, 168, 1, 3}; // IP address for the webserver

static uint16_t port = 240; // Use port 80 – the standard for HTTP

ETHER_28J60 e;

float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius

byte data[12];
byte addr[8];

if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}

if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println(“CRC is not valid!”);
return -1000;
}

if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print(“Device is not recognized”);
return -1000;
}

ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end

byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad

for (int i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}

ds.reset_search();

byte MSB = data[1];
byte LSB = data[0];

float tempRead = ((MSB << 8) | LSB); //using two’s compliment
float TemperatureSum = tempRead / 16;

return TemperatureSum;

}

void setup()
{
e.setup(mac, ip, port);
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
pinMode(RELAY4, OUTPUT);
pinMode(RELAY5, OUTPUT);
digitalWrite(RELAY1,HIGH);
digitalWrite(RELAY2,HIGH);
digitalWrite(RELAY3,HIGH);
digitalWrite(RELAY4,HIGH);
digitalWrite(RELAY5,HIGH);

}

void loop()

{

char* params;
if (params = e.serviceRequest())
{

float temperature = getTemp();
e.print(“TEMP: “);
e.print(temperature); e.print(“C”);
e.print(“<h1><a href=’/?led1=off&led2=off’>Relay Control Panel</a></h1>”);
e.print(“<h1><a href=’/?rele3=off&rele4=off’>Relay Control Panel 2</a></h1>”);

if (strcmp(params, “?led1=on&led2=off”) == 0)
{
pinMode(RELAY1, HIGH);
pinMode(RELAY2, LOW);
e.print(“<a href=’?led1=off&led2=off’><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 1 IS ON</button></a><a href=’?led1=on&led2=on’><br/><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 2 IS OFF</button></a>”);
}
else if (strcmp(params, “?led1=off&led2=on”) == 0)
{
pinMode(RELAY1, LOW);
pinMode(RELAY2, HIGH);
e.print(“<a href=’?led1=on&led2=on’><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 1 IS OFF</button></a><a href=’?led1=off&led2=off’><br/><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 2 IS ON</button></a>”);
}
else if (strcmp(params, “?led1=off&led2=off”) == 0)
{
pinMode(RELAY1, LOW);
pinMode(RELAY2, LOW);
e.print(“<a href=’?led1=on&led2=off’><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 1 IS OFF</button></a><a href=’?led1=off&led2=on’><br/><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 2 IS OFF</button></a>”);
}
else if (strcmp(params, “?led1=on&led2=on”) == 0)
{
pinMode(RELAY1, HIGH);
pinMode(RELAY2, HIGH);
e.print(“<a href=’?led1=off&led2=on’><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 1 IS ON</button></a><a href=’?led1=on&led2=off’><br/><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 2 IS ON</button></a>”);
}
else if (strcmp(params, “?rele3=on&rele4=off”) == 0)
{
pinMode(RELAY3, HIGH);
pinMode(RELAY4, LOW);
e.print(“<a href=’?rele3=off&rele4=off’><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 3 IS ON</button></a><a href=’?rele3=on&rele4=on’><br/><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 4 IS OFF</button></a>”);
}
else if (strcmp(params, “?rele3=off&rele4=on”) == 0)
{
pinMode(RELAY3, LOW);
pinMode(RELAY4, HIGH);
e.print(“<a href=’?rele3=on&rele4=on’><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 3 IS OFF</button></a><a href=’?rele3=off&rele4=off’><br/><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 4 IS ON</button></a>”);
}
else if (strcmp(params, “?rele3=off&rele4=off”) == 0)
{
pinMode(RELAY3, LOW);
pinMode(RELAY4, LOW);
e.print(“<a href=’?rele3=on&rele4=off’><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 3 IS OFF</button></a><a href=’?rele3=off&rele4=on’><br/><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 4 IS OFF</button></a>”);
}
else if (strcmp(params, “?rele3=on&rele4=on”) == 0)
{
pinMode(RELAY3, HIGH);
pinMode(RELAY4, HIGH);
e.print(“<a href=’?rele3=off&rele4=on’><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 3 IS ON</button></a><a href=’?rele3=on&rele4=off’><br/><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 4 IS ON</button></a>”);
}

e.respond();
}
float temperature = getTemp();
if (temperature >32) {
digitalWrite(26,LOW);
} else {
digitalWrite(26,HIGH);
}
}

Posted in Arduino Project | Leave a comment

ETHERNET ENC28J60 + 5 Relay Modules (1 Relay on Light Sensor)

This sketch requires etherShield, ETHER_28J60, BH1750 and OneWire library.

You can download the library here

https://docs.google.com/file/d/0B4qM0hq-OmC1RHhEcXRNSmZ1YW8/

 

#include <Wire.h>
#include <BH1750.h>
#include “etherShield.h”
#include “ETHER_28J60.h”
#define RELAY1  22
#define RELAY2  23
#define RELAY3  24
#define RELAY4  25
#define RELAY5  26
#define RELAY6  27
#include <OneWire.h>
int DS18S20_Pin = 2;
OneWire ds(DS18S20_Pin);

static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24};   // this just needs to be unique for your network,

static uint8_t ip[4] = {192, 168, 1, 3}; // IP address for the webserver

static uint16_t port = 240; // Use port 80 – the standard for HTTP

ETHER_28J60 e;
BH1750 lightMeter;

float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius

byte data[12];
byte addr[8];

if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}

if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println(“CRC is not valid!”);
return -1000;
}

if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print(“Device is not recognized”);
return -1000;
}

ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end

byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad

for (int i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}

ds.reset_search();

byte MSB = data[1];
byte LSB = data[0];

float tempRead = ((MSB << 8) | LSB); //using two’s compliment
float TemperatureSum = tempRead / 16;

return TemperatureSum;

}

void setup()
{
e.setup(mac, ip, port);
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
pinMode(RELAY4, OUTPUT);
pinMode(RELAY5, OUTPUT);
pinMode(RELAY6, OUTPUT);
digitalWrite(RELAY1,HIGH);
digitalWrite(RELAY2,HIGH);
digitalWrite(RELAY3,HIGH);
digitalWrite(RELAY4,HIGH);
digitalWrite(RELAY5,HIGH);
lightMeter.begin();
}

void loop()

{

char* params;
if (params = e.serviceRequest())
{
uint16_t lux = lightMeter.readLightLevel();
e.print(” Light:”);
e.print(lux);
e.print(“<h1><a href=’/?led1=off&led2=off’>Relay Control Panel</a></h1>”);
e.print(“<h1><a href=’/?rele3=off&rele4=off’>Relay Control Panel 2</a></h1>”);

if (strcmp(params, “?led1=on&led2=off”) == 0)
{
pinMode(RELAY1, HIGH);
pinMode(RELAY2, LOW);
e.print(“<a href=’?led1=off&led2=off’><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 1 IS ON</button></a><a href=’?led1=on&led2=on’><br/><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 2 IS OFF</button></a>”);
}
else if (strcmp(params, “?led1=off&led2=on”) == 0)
{
pinMode(RELAY1, LOW);
pinMode(RELAY2, HIGH);
e.print(“<a href=’?led1=on&led2=on’><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 1 IS OFF</button></a><a href=’?led1=off&led2=off’><br/><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 2 IS ON</button></a>”);
}
else if (strcmp(params, “?led1=off&led2=off”) == 0)
{
pinMode(RELAY1, LOW);
pinMode(RELAY2, LOW);
e.print(“<a href=’?led1=on&led2=off’><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 1 IS OFF</button></a><a href=’?led1=off&led2=on’><br/><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 2 IS OFF</button></a>”);
}
else if (strcmp(params, “?led1=on&led2=on”) == 0)
{
pinMode(RELAY1, HIGH);
pinMode(RELAY2, HIGH);
e.print(“<a href=’?led1=off&led2=on’><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 1 IS ON</button></a><a href=’?led1=on&led2=off’><br/><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 2 IS ON</button></a>”);
}
else if (strcmp(params, “?rele3=on&rele4=off”) == 0)
{
pinMode(RELAY3, HIGH);
pinMode(RELAY4, LOW);
e.print(“<a href=’?rele3=off&rele4=off’><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 3 IS ON</button></a><a href=’?rele3=on&rele4=on’><br/><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 4 IS OFF</button></a>”);
}
else if (strcmp(params, “?rele3=off&rele4=on”) == 0)
{
pinMode(RELAY3, LOW);
pinMode(RELAY4, HIGH);
e.print(“<a href=’?rele3=on&rele4=on’><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 3 IS OFF</button></a><a href=’?rele3=off&rele4=off’><br/><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 4 IS ON</button></a>”);
}
else if (strcmp(params, “?rele3=off&rele4=off”) == 0)
{
pinMode(RELAY3, LOW);
pinMode(RELAY4, LOW);
e.print(“<a href=’?rele3=on&rele4=off’><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 3 IS OFF</button></a><a href=’?rele3=off&rele4=on’><br/><button style=’border: 1px solid #FF0000; border-left: 10px solid #FF0000′ type=’button’>RELAY 4 IS OFF</button></a>”);
}
else if (strcmp(params, “?rele3=on&rele4=on”) == 0)
{
pinMode(RELAY3, HIGH);
pinMode(RELAY4, HIGH);
e.print(“<a href=’?rele3=off&rele4=on’><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 3 IS ON</button></a><a href=’?rele3=on&rele4=off’><br/><button style=’border: 1px solid #00FF00; border-left: 10px solid #00FF00′ type=’button’>RELAY 4 IS ON</button></a>”);
}

e.respond();
}
float temperature = getTemp();

uint16_t lux = lightMeter.readLightLevel();
if (lux >32) {
digitalWrite(27,LOW);
} else {
digitalWrite(27,HIGH);
}
}

Posted in Arduino Project | Leave a comment

ETHERNET ENC28J60 + 2 Relay Modules

IMG_1377Arduino-Mega-2560-wiring-enc28j60

This sketch requires etherShield and ETHER_28J60 library.

You can download the library here

https://docs.google.com/file/d/0B4qM0hq-OmC1RHhEcXRNSmZ1YW8/

// A simple web server that turn a relay on or off”

#include “etherShield.h”
#include “ETHER_28J60.h”
#define RELAY1  22
#define RELAY2  23

static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24};   // this just needs to be unique for your network,

static uint8_t ip[4] = {192, 168, 1, 3}; // IP address for the webserver

static uint16_t port = 240; // Use port 80 – the standard for HTTP  MAX port is 240.

ETHER_28J60 e;

void setup()
{
e.setup(mac, ip, port);
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
digitalWrite(RELAY1,HIGH);
digitalWrite(RELAY2,HIGH);
}

void loop()
{
char* params;
if (params = e.serviceRequest())
{
e.print(“<h1><a href=’/?led1=off&led2=off’>cmos tjet</a></h1>”);
if (strcmp(params, “?led1=on&led2=off”) == 0)
{
pinMode(RELAY1, HIGH);
pinMode(RELAY2, LOW);
e.print(“<a href=’?led1=off&led2=off’><button style=’border: 1px solid #ff0000; border-left: 10px solid #ff0000′ type=’button’>RELAY 1 IS ON</button></a><a href=’?led1=on&led2=on’><br/><button style=’border: 1px solid #000; border-left: 10px solid #000′ type=’button’>RELAY 2 IS OFF</button></a>”);
}
else if (strcmp(params, “?led1=off&led2=on”) == 0)
{
pinMode(RELAY1, LOW);
pinMode(RELAY2, HIGH);
e.print(“<a href=’?led1=on&led2=on’><button style=’border: 1px solid #000; border-left: 10px solid #000′ type=’button’>RELAY 1 IS OFF</button></a><a href=’?led1=off&led2=off’><br/><button style=’border: 1px solid #ff0000; border-left: 10px solid #ff0000′ type=’button’>RELAY 2 IS ON</button></a>”);
}
else if (strcmp(params, “?led1=off&led2=off”) == 0)
{
pinMode(RELAY1, LOW);
pinMode(RELAY2, LOW);
e.print(“<a href=’?led1=on&led2=off’><button style=’border: 1px solid #000; border-left: 10px solid #000′ type=’button’>RELAY 1 IS OFF</button></a><a href=’?led1=off&led2=on’><br/><button style=’border: 1px solid #000; border-left: 10px solid #000′ type=’button’>RELAY 2 IS OFF</button></a>”);
}
else if (strcmp(params, “?led1=on&led2=on”) == 0)
{
pinMode(RELAY1, HIGH);
pinMode(RELAY2, HIGH);
e.print(“<a href=’?led1=off&led2=on’><button style=’border: 1px solid #ff0000; border-left: 10px solid #ff0000′ type=’button’>RELAY 1 IS ON</button></a><a href=’?led1=on&led2=off’><br/><button style=’border: 1px solid #ff0000; border-left: 10px solid #ff0000′ type=’button’>RELAY 2 IS ON</button></a>”);
}
e.respond();
}
}

Posted in Arduino Project | Leave a comment

DHT11 Humidity Sensor

DHT11Sensor1

This sketch requires DHT library.

You can download the library here

https://docs.google.com/file/d/0B4qM0hq-OmC1RHhEcXRNSmZ1YW8/

#include “DHT.h”

DHT dht;

void setup()
{
Serial.begin(9600);
Serial.println();
Serial.println(“Status\tHumidity (%)\tTemperature (C)\t(F)”);

dht.setup(2); // data pin 2
}

void loop()
{
delay(dht.getMinimumSamplingPeriod());

float humidity = dht.getHumidity();
float temperature = dht.getTemperature();

Serial.print(dht.getStatusString());
Serial.print(“\t”);
Serial.print(humidity, 1);
Serial.print(“\t\t”);
Serial.print(temperature, 1);
Serial.print(“\t\t”);
Serial.println(dht.toFahrenheit(temperature), 1);
}

Posted in Arduino Project | Leave a comment