This is my FYP project . Topic is smart roof system. i using Ethernet shield which able to transmit the date from arduino uno to server. now i using 2 arduino board doing my project. But the problem i encounter is the limit swicth once contact, the result is not what i expected .
Here is the step n procedure:
Board A
Contain motor, limit switch and a rain sensor.
1)if detect no rain, motor will rotate forward (open roof), once contact limit switch it will stop moving.
2)if detected rain water , motor will rotate reverse (close roof), once contact limit switch it will stop moving .
3) pin 13 is giving the signal to board B to report the weather condition. meanwhile the result output is linking with rain sensor.
Board B
contain humidity sensor, 2 relay and Ethernet shield.
- i add on Ethernet shield just want to display the reading n state in server . it will display humidity n temperature, weather condition and system state condition.
2)another 2 limit switch is just for safety precaution. if actual limit switch no function , this limit switch will backup for respond back . this 2 backup switch connect at digital pin 2 .once contact, the 2 relay will active to cut off the motor supply and warning LED light will on.
Remark: board A digital 13 is linking with Board B digital 6 .
The problems i encounter is Board B limit switch once contact , it don have result. even the relay also not working. another problem is the Board A digital pin 13, i not sure the programming correct or not, seen like don giving any signal to Board B digital 6, because no respond.
Please someone guide me , i still fresh and zero knowledge about it , especially the programming part .
below part is the coding what i using .
Board A
int rainsensor=1;
int rainvalue=0;
int rain_sensitivity=800;
int buttonPin0 = 0;
int buttonPin1 = 0;
int E1 = 6;
int M1 = 7;
void setup()
{
pinMode(buttonPin0,INPUT);
pinMode(buttonPin1,INPUT);
digitalWrite(2,HIGH );
digitalWrite(3,HIGH );
pinMode(13, OUTPUT);
pinMode(M1, OUTPUT);
pinMode(E1, OUTPUT);
Serial.begin(9600);
}
void loop()
{
buttonPin0 = digitalRead(2);
buttonPin1 = digitalRead(3);
rainvalue = analogRead(rainsensor);
Serial.println(rainvalue);
if (rainvalue > rain_sensitivity){
motorFwd();
digitalWrite(13,HIGH);
}
else {
motorRev();
digitalWrite(13,LOW);
}
}
void motorFwd(){
if (buttonPin0 == HIGH ){
digitalWrite(M1,HIGH );
analogWrite(E1, 150);
delay(10);
}
else {
analogWrite(E1, 0);
delay(10);
}
}
void motorRev(){
if (buttonPin1 == HIGH){
digitalWrite(M1,LOW );
analogWrite(E1, 150);
delay(10);
}
else {
analogWrite(E1, 0);
delay(10);
}
}
Board B
#include <SPI.h>
#include <Ethernet.h>
#include "DHT.h"
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);
EthernetServer server(8080);
int humidity= 0;
int temperature=0;
int tempValue=0;
#define RELAY1 3
#define RELAY2 4
DHT dht;
int emergencypin0 =0;
int Raining_c= 0 ;
void setup()
{
Ethernet.begin(mac, ip);
server.begin();
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
digitalWrite(2,HIGH );
digitalWrite(6,HIGH );
dht.setup(8); // data pin 2
pinMode(emergencypin0,INPUT);
pinMode(Raining_c,INPUT);
Serial.begin(9600);
}
void loop()
{
delay(dht.getMinimumSamplingPeriod());
float humidity = dht.getHumidity();
float temperature = dht.getTemperature();
EthernetClient client = server.available();
// detect if current is the first line
boolean current_line_is_first = true;
emergencypin0 = digitalRead(2);
Raining_c = digitalRead(6);
if (client) {
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if we've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (c == '\n' && current_line_is_blank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// auto reload webpage every 5 second
client.println("<META HTTP-EQUIV=REFRESH CONTENT=5 URL=>");
// webpage title
client.println("<center><p><h1>Home application</h1></p><center><hr>
");
client.print("<p><h2>State = <font color=indigo>");
if (emergencypin0==HIGH)
{
client.println("<p><h2><font color=green>GOOD</font></h2></p>");
}
else
{
client.println("<p><h2><font color=red>ERROR!</font></h2></p>");
digitalWrite(RELAY1,HIGH);
delay (10);
digitalWrite(RELAY2,HIGH);
delay (10);
}
client.print("<p><h2>Weather condition = <font color=indigo>");
if (Raining_c==HIGH)
{
client.println("<p><h2><font color=green>RAINING!</font></h2></p>");
}
else
{
client.println("<p><h2><font color=red>NO RAIN</font></h2></p>");
}
client.println("</font></h2></p>");
client.print("<p><h2>HUMIDITY = <font color=indigo>");
client.println(humidity, 1);
client.println("</font></h2></p>");
client.print("<p><h2>TEMPERATURE = <font color=indigo>");
client.println(temperature, 1);
client.println("</font></h2></p>");
// webpage footer
client.println("<p> Remark: This page will automatically refresh every 5 seconds.</p></center>");
break;
}
if (c == '\n') {
// we're starting a new line
current_line_is_first = false;
current_line_is_blank = true;
}
else if (c != '\r') {
// we've gotten a character on the current line
current_line_is_blank = false;
}
// get the first http request
}
}
}
// give the web browser time to receive the data
delay(1);
client.stop();
}