[SOLVED] Smarthome using arduino mega +ethernet shield+android studio

turn on/off led + arduino mega +ethernet shield + ubidots

@d4vsanchez please help me to resolve this problem

@NicoCloud have you solution to send and recive data from ubidots ?

Dear @nihel,

To start with the Arduino + Ethernet Shield and Ubidots refer to the Ubidots Arduino Ethernet Library. The library provide the basic examples to start posting and getting data to/from the Ubidots platform.

I hope this would help you!

All the best,
Maria C.

I know that but the code didn’t work there is error

I want to turn on/off the led from ubidots

Greetings @nihel , please be more specific about your issue in order to get help from the community, what have you tried to do? What error are you getting? How have you tried to fix it?

Anyone can give you assistance if you do not post properly what issues are you experiencing.

All the best

I resolve the problem thank you very much

@jotathebest when I upload the code arduino and I I click in the Button control in ubidots any value was recevie

Dear @nihel,

Can you let us know the response of the server received?

All the best,
Maria C.

I receive the @IP 192.168.1.8 I can visualiate the courbe of temperature… but I can receive any thing

Dear @nihel,

Make sure that you are printing the value obtained in the loop code, for example:

  /* Getting the last value from a variable */
  float value = client.getValue(DEVICE_LABEL, VARIABLE_LABEL);
  /* Print the value obtained */
  Serial.print("the value received is:  ");
  Serial.println(value);

I just made a test running the getValue example provided in the library and everything is working properly by my side as you can see in the image below:

Selection_011

All the best,
Maria C.

The is working
But now I would to make an android application to this code do you can help me
this is the code:

#include <UbidotsEthernet.h>
#include<dht.h>
#include <Ethernet.h>
#include <SPI.h>
#define DHTPIN 50
//#define DHTTYPE DHT
#define ID "temperature"
#define ID1 "humidity"
#define ID2 "gaz"
#define ID3 "led"
#define ID4 "fer"
#define ID5 "pir"
#define ID_LABEL "controller"
#define TOKEN "A1E-BSznpyf1uZbNQWD559wJlwkIIo9AmH"
byte mac[]={0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,12);
Ubidots client(TOKEN);
float temo=0;
int LED1=8;
int LED2=53;
int buzzer=34;
dht DHT;
//DHT dht(DHTPIN,DHTTYPE);
void setup(){
  Serial.begin(9600);
  if (Ethernet.begin(mac)==0){
    Serial.println("failed to configurate Ethernet using DHCP");
    Ethernet.begin(mac,ip);
  }
  delay(1000);
}
void loop(){
  int chk=DHT.read11(DHTPIN);
float value =DHT.temperature;
  Serial.print("value is");
  Serial.println(value);
  client.add(ID,value);
  float value_1 =DHT.humidity;
  Serial.print("value_1 is");
  Serial.println(value_1);
  client.add(ID1,value_1);
   float value_2 =analogRead(A2);
  Serial.print("value_2 is");
  Serial.println(value_2);
  client.add(ID2,value_2);
  client.sendAll();
  float value_6 =analogRead(A1);
  Serial.print("value_6 is");
  Serial.println(value_6);
  client.add(ID5,value_6);
  client.sendAll();
   
  if (value_2 >= 400){
    digitalWrite(buzzer,HIGH);
  }
  else{
    digitalWrite(buzzer,LOW);
  }
  ////////get value from ubidots///////////////
  float value_4=client.getValue(ID_LABEL,ID3);
  if (value_4==1.0){
    digitalWrite(LED1,HIGH);
  }
  else{
    digitalWrite(LED1,LOW);
  }
  Serial.print("the value_4 received is:  ");
  Serial.println(value_4);
 float value_5=client.getValue(ID_LABEL,ID4);
  if (value_5==1.0){
    digitalWrite(LED2,HIGH);
  }
  else{
    digitalWrite(LED2,LOW);
  }
  Serial.print("the value_5 received is:  ");
  Serial.println(value_5);
}

@mariahernandez

@d4vsanchez
The is working
But now I would to make an android application to this code do you can help me
this is the code:

#include <UbidotsEthernet.h>
#include<dht.h>
#include <Ethernet.h>
#include <SPI.h>
#define DHTPIN 50
//#define DHTTYPE DHT
#define ID “temperature”
#define ID1 “humidity”
#define ID2 “gaz”
#define ID3 “led”
#define ID4 “fer”
#define ID5 “pir”
#define ID_LABEL “controller”
#define TOKEN “A1E-BSznpyf1uZbNQWD559wJlwkIIo9AmH”
byte mac[]={0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,12);
Ubidots client(TOKEN);
float temo=0;
int LED1=8;
int LED2=53;
int buzzer=34;
dht DHT;
//DHT dht(DHTPIN,DHTTYPE);
void setup(){
Serial.begin(9600);
if (Ethernet.begin(mac)==0){
Serial.println(“failed to configurate Ethernet using DHCP”);
Ethernet.begin(mac,ip);
}
delay(1000);
}
void loop(){
int chk=DHT.read11(DHTPIN);
float value =DHT.temperature;
Serial.print(“value is”);
Serial.println(value);
client.add(ID,value);
float value_1 =DHT.humidity;
Serial.print(“value_1 is”);
Serial.println(value_1);
client.add(ID1,value_1);
float value_2 =analogRead(A2);
Serial.print(“value_2 is”);
Serial.println(value_2);
client.add(ID2,value_2);
client.sendAll();
float value_6 =analogRead(A1);
Serial.print(“value_6 is”);
Serial.println(value_6);
client.add(ID5,value_6);
client.sendAll();

if (value_2 >= 400){
digitalWrite(buzzer,HIGH);
}
else{
digitalWrite(buzzer,LOW);
}
////////get value from ubidots///////////////
float value_4=client.getValue(ID_LABEL,ID3);
if (value_4==1.0){
digitalWrite(LED1,HIGH);
}
else{
digitalWrite(LED1,LOW);
}
Serial.print("the value_4 received is: ");
Serial.println(value_4);
float value_5=client.getValue(ID_LABEL,ID4);
if (value_5==1.0){
digitalWrite(LED2,HIGH);
}
else{
digitalWrite(LED2,LOW);
}
Serial.print("the value_5 received is: ");
Serial.println(value_5);
}

Dear user,

I’m glad to read that you make your code working properly using your Arduino MEGA and Ethernet Shield using Ubidots. Now to learn how to build your Android application you should refer to internet where you can find many and different kind of options to start.

I hope this would help you. :grinning:

All the best,
Maria C.