Go Down

Topic: Ethernet Shield UTP connection block HC-06 function (Read 158 times) previous topic - next topic

artorux

Hi, i am very new into microcontroller. I am on my way to finishing my project which is tollgate paid by android app simulation. I am using Servo, IR Sensor, HC-06, and Ethernet shield (to show how many car had passed from the database into local server ). I had done with the android, arduino, and localserver part. The only thing i am failed at is combining these feature. Here are my code.

The first code is the part where arduino sending and receive data to android app that i created

Code: [Select]
#include<Servo.h>
#include<SoftwareSerial.h>
Servo servo;
//SoftwareSerial mySerial(8, 9); // RX, TX
int angle=90;
int LED = 13;
int var;

void setup()
{
  Serial.begin(9600);
  //mySerial.begin(9600);
  pinMode(LED, OUTPUT);
  pinMode(A0,INPUT);
  servo.attach(7);
  servo.write(angle);
 
}
 
void loop(){
  var = analogRead(A0);
  if(var<200){
    //delay(500);
    //Serial.println("Detected");
   
    if (Serial.available()){
    int value = Serial.read();
      if (value == '0') {
      Serial.println("Gate:01 | Enter | IDR 11000");     
    }                                 //entering
      if (value == '1') {
      digitalWrite(LED, HIGH);
      servo.write(180);
      //Serial.println(gate);
      //Serial.println("Gate:01 | Enter | IDR 5000");     
    }
   }
   }else if (var>200){
      delay(2000);
      digitalWrite(LED, LOW);
      servo.write(90);
     // Serial.println("No Detection");
     
   
   
  }
}



and the second code is the part where i store data into local mySQL.
Code: [Select]
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte server[]={192,168,137,1};
//IPAddress server(192,168,1,105);  // numeric IP for Google (no DNS)
byte ip[]={192,168,137,2};
EthernetClient client;
void setup() {
 
  Serial.begin(9600);
  pinMode(A0,INPUT);
  delay(1000);
  Ethernet.begin(mac, ip);
  Serial.print("IP Address: ");
  Serial.println(Ethernet.localIP());  //Get the right IP

  Serial.println("connecting...");
  delay(10000);  // Seen that sometimes there could be a delay issue so added a rather large delay here


  }

  void loop(){
    if (client.connect(server,80)){
       
           delay(500);
           client.print("GET /web-server/history_insert.php?gate=gate:01\r\nHost: 192.168.137.1\r\n\r\n");
           Serial.println("OK");
           client.stop();
           client.print("Closing Connection");
       
  }
  else {
    Serial.println("NO");
    delay(250);
  }
 }


i am trying to use softwareserial.h before but i can't find my way, that's why i am creating this topic.
Thank you in advance

Juraj

Uno? pin 13 is SPI SCK pin. Ethernet shield uses SPI. don't use pin 13 in sketch

Go Up