Ubidots Community

[SOLVED] Arduino Uno + DS18B20 + pH Meter + Servo. Cant Send Data Sensor to Ubidots?

Hii All,

I have some problem to sending data ubidots with ethernet shield, because added 5 motor servo.
before that, i have try to send data without motor servo and all look good. But when i try add 5 motor servo. Data temperatur & pH sensor cant sent to ubidots.

Here my schematic without pH Meter to Analog 0

https://raw.githubusercontent.com/qalit/eUngkot/master/SKEMA%20RANGKAIAN/Rangkaian%20Prototipe.png

Code Before added Servo :

    #include <SPI.h>
    #include <Ethernet.h>
    #include <UbidotsEthernet.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    // Set the static IP address to use if the DHCP fails to assign
    IPAddress ip(192, 168, 0, 177);
    unsigned long interval=1000; // the time we need to wait
    unsigned long interval1=60000;
    unsigned long previousMillis=0; // millis() returns an unsigned long.
    #define ONE_WIRE_BUS 2
    #define PHSensorPin 0          //pH meter Analog output to Arduino Analog Input 0
    unsigned long int avgValue;  //Store the average value of the sensor feedback
    float b;
    int buf[10],temp;
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensorSuhu(&oneWire);
    float suhuSekarang;
    #define IDSuhu "5829c80d76254214e3f9d3a1"
    #define IDpH "58a9dd0b762542238e7cf8ae"
    #define TOKEN "iGPgAzahoarBndo3RvDDUfln0z1aDK"
    Ubidots client(TOKEN);
    void setup(){
      if (Ethernet.begin(mac) == 0) {
          //Serial.println("Failed to configure Ethernet using DHCP");
          // try to congifure using IP address instead of DHCP:
          Ethernet.begin(mac, ip);
      }
      unsigned long currentMillis = millis();
      if ((unsigned long)(currentMillis - previousMillis) >= interval+4000) {
         delay(5000);
         previousMillis = millis();
      }
    }
    void loop() {
      unsigned long currentMillis = millis();
      
      for(int i=0;i<10;i++){ 
          buf[i]=analogRead(PHSensorPin);
          if ((unsigned long)(currentMillis - previousMillis) >= interval) {
            delay(10);
          }
      }
      for(int i=0;i<9;i++){
        for(int j=i+1;j<10;j++){
          if(buf[i]>buf[j]){
            temp=buf[i];
            buf[i]=buf[j];
            buf[j]=temp;
          }
        }
      }
      avgValue=0;
      for(int i=2;i<8;i++)                      //take the average value of 6 center sample
      avgValue+=buf[i];
      
      float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt
      phValue=3.5*phValue;
      sensorSuhu.requestTemperatures();
      float suhu = sensorSuhu.getTempCByIndex(0);
      if ((unsigned long)(currentMillis - previousMillis) >= interval1) {     
         client.add(IDSuhu, suhu);
         client.add(IDpH, phValue);
         previousMillis = millis();
         client.sendAll();
         delay(60000);
      }
    }

And Here is code with Servo motor implemented :

#include <SPI.h>
#include <Ethernet.h>
#include <UbidotsEthernet.h>
#include <RTClib.h>
#include <Servo.h>
#include <OneWire.h>
#include <DallasTemperature.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 0, 177);
unsigned long interval=1000; // the time we need to wait
unsigned long interval1=60000;
unsigned long previousMillis=0; // millis() returns an unsigned long.
#define ONE_WIRE_BUS 2
#define PHSensorPin 0          //pH meter Analog output to Arduino Analog Input 0
unsigned long int avgValue;  //Store the average value of the sensor feedback
float b;
int buf[10],temp;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensorSuhu(&oneWire);
float suhuSekarang;
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = {"Min", "Sen", "Sel", "Rab", "Kam", "Jum", "Sab"};
int WLvlAtas = 6;
int WLvlBawah = 7;
int servoPin1 = 8;
int servoPin2 = 9;
int servoPin3 = 3;
int servoPin4 = 5;
int srvPinKuras = 12;
Servo myservo1;  // servo pakan 1
Servo myservo2;  // servo pakan 2
Servo myservo3; // servo pakan 3
Servo myservo4; // servo pakan 4
Servo srvKurasAir; // servo kuras air
int servoAngle = 0;
#define IDSuhu "5829c80d76254214e3f9d3a1"
#define IDpH "58a9dd0b762542238e7cf8ae"
#define IDPakan "5829c8a476254218b9f109e7"
#define TOKEN "iGPgAzahoarBndo3RvDDUfln0z1aDK"
Ubidots client(TOKEN);
void setup(){
  unsigned long currentMillis = millis();
    //Serial.begin(9600);
  if (Ethernet.begin(mac) == 0) {
      //Serial.println("Failed to configure Ethernet using DHCP");
      // try to congifure using IP address instead of DHCP:
      Ethernet.begin(mac, ip);
  }
  if ((unsigned long)(currentMillis - previousMillis) >= 5000) {
     delay(5000);
  }
  if (! rtc.begin()) {
    ////Serial.println("RTC Mati");
    while (1);
  }
  if (rtc.lostPower()) {
    //rtc.adjust(DateTime(__DATE__,__TIME__));
    ////Serial.println("RTC lowbat !!");
  
  }
  pinMode(WLvlAtas, INPUT_PULLUP);
  pinMode(WLvlBawah, INPUT_PULLUP);
  myservo1.attach(servoPin1);
  myservo2.attach(servoPin2);
  myservo3.attach(servoPin3);
  myservo4.attach(servoPin4);
  srvKurasAir.attach(srvPinKuras);
  delay(1000);
  myservo1.write(2);
  myservo2.write(2);
  myservo3.write(2);
  myservo4.write(2);
  srvKurasAir.write(2);
  delay(2000);
  srvKurasAir.detach();
    
}
void loop() {
  unsigned long currentMillis = millis();
//  if ((unsigned long)(currentMillis - previousMillis) >= interval) {
//     delay(5000);
//  }
  delay(1000);
  for(int i=0;i<10;i++){ 
      buf[i]=analogRead(PHSensorPin);
      if ((unsigned long)(currentMillis - previousMillis) >= interval) {
        delay(10);
      }
  }
  for(int i=0;i<9;i++){
    for(int j=i+1;j<10;j++){
      if(buf[i]>buf[j]){
        temp=buf[i];
        buf[i]=buf[j];
        buf[j]=temp;
      }
    }
  }
  avgValue=0;
  for(int i=2;i<8;i++)                      //take the average value of 6 center sample
  avgValue+=buf[i];
  
  float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt
  phValue=3.5*phValue;
  sensorSuhu.requestTemperatures();
  float suhu = sensorSuhu.getTempCByIndex(0); 
  
  if ((unsigned long)(currentMillis - previousMillis) >= interval1) {     
     client.add(IDSuhu, suhu);
     client.add(IDpH, phValue);
     previousMillis = millis();
     client.sendAll();
     delay(60000);
  }
}

And servo wont stop from buzz/noise
Any idea?

Hello @flinn,

As I can read you should have a problem with servos, may be generating an induction causing noise to the Arduino. So it does not allow the Arduino to work in the right way, thus causing it to fail to send data to Ubidots.

You can send data to Ubidots without any issue at the first time, so we rule out that’s the problem.

Regards.

Hello @mariahernandez
Thanks for reply.

I was revisied my schematic, to reduce jitter/noise for servo i added 3 capacitor for one of them.

http://www.robotshop.com/letsmakerobots/files/userpics/u4570/Arduino_Servo_Filters.jpg

This effective to reduce jitter/noise. But my firstly problem still not solved. Data sensor still can’t sent to Ubidots. Any idea? or my schematics or my code cause in bad routine?
In code with servo, i have no include any action yet for servo, like move 90 degree.(but, i need this too in next step)

Sorry for my bad english.
Thanks for reply and who want read this post

Hi @flinn,

Based on your first code (that works correctly), attach just one servo and test it.

Thanks for reply @mariahernandez
I have try with only one servo attach to pin 12. But problem still cant sent data to ubidots.
Any idea?

@flinn if it’s a noise problem, you should isolate the servo with an optocoupler, maybe it helps you.

Another test is to send only a value with the servo connected, if it is successful add the temperature sensor and repeat the test.

Regards

Hii @jotathebest, thanks for reply, i’ll try that with optocoupler

Thanks for support. Now its WORKED clearly. Don’t use pin 10,11,12 because this pin can’t be used for PWM motor servo.

i use this code

#include <Ethernet.h>
#include <SPI.h>
#include <UbidotsEthernet.h>
#define IDSuhu "5829c80d76254214e3f9d3a1"
#define IDpH "58a9dd0b762542238e7cf8ae"
#define TOKEN "iGPgAzahoarBndo3RvDDUfln0z1aDK"
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensorSuhu(&oneWire);
#define PHSensorPin 0          //pH meter Analog output to Arduino Analog Input 0
unsigned long int avgValue;  //Store the average value of the sensor feedback
float b;
int buf[10],temp;
byte mac[] = { 0x33, 0x33, 0x00, 0x00, 0x00, 0xFB };
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 0, 177);
Ubidots client(TOKEN);
unsigned long interval=1000; // the time we need to wait
unsigned long interval1=60000;
unsigned long previousMillis=0; // millis() returns an unsigned long.
void setup(){
  if (Ethernet.begin(mac) == 0) {
   //Serial.println("Failed to configure Ethernet using DHCP");
  // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  delay(2000);
}
void loop() {
  unsigned long currentMillis = millis();
  
  for(int i=0;i<10;i++){ 
    buf[i]=analogRead(PHSensorPin);
    delay(10);
  }
  for(int i=0;i<9;i++){
    for(int j=i+1;j<10;j++){
      if(buf[i]>buf[j]){
        temp=buf[i];
        buf[i]=buf[j];
        buf[j]=temp;
      }
    }
  }
  
  avgValue=0;
  for(int i=2;i<8;i++){
    avgValue+=buf[i];
  }
  
  float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt
  phValue=3.5*phValue;
  
  sensorSuhu.requestTemperatures();
  float suhu = sensorSuhu.getTempCByIndex(0);
  
  //if ((unsigned long)(currentMillis - previousMillis) >= interval1) {
    client.add(IDSuhu, suhu);
    client.add(IDpH, phValue);
    client.sendAll();
    delay(60000);
    //client.freeRam();
  //}
}