Show Posts
Pages: [1] 2 3 ... 244
1  Using Arduino / Project Guidance / Re: explaining of delay() please on: July 18, 2014, 03:01:26 am
It means do nothing for one second. In this context it may simply be there to ensure that the servos complete whatever move they were asked to do before more instructions are given.

In quadcopter code though, use of delay makes little sense unless it's in the startup code. Ignoring your sensors while actually flying sounds like a great recipe for a crash.
2  Using Arduino / Programming Questions / Re: DH22 & DS18B20 on: July 15, 2014, 03:49:19 pm
Compiles fine for me under 1.0.4. Do you have other errors, possibly relating to missing libraries?
3  Using Arduino / Programming Questions / Re: Programme stuck in setup on: July 15, 2014, 12:40:09 pm
You can save yourself some RAM by pushing constant serial printed strings into progmem. Change stuff like this:
Code:
  Serial.println("BMP complete");
to
Code:
  Serial.println(F("BMP complete"));
4  Using Arduino / Project Guidance / Re: Using Arduino to read data off website on: July 15, 2014, 08:04:13 am
Building a system where a light is instructed from a web page is often done by using the arduino as a web server and hosting the web page on it. The arduino has limited resources so the pages it serves generally can't be very big or complex, but people have done home control using an Uno in this fashion.

You'll still need to solve the issue of a static IP if you want to connect to the arduino from outside your local network - services such as Dyn or no-ip can do this for you.
5  Using Arduino / Programming Questions / Re: limit on arays? on: July 15, 2014, 07:45:58 am
For speed testing, just read the ADC value into a single variable in a loop & print the time before and after.

Just as a precaution against the compiler being too crafty on optimization, I'd also sum the values you read and print that total at the end.
6  Using Arduino / Project Guidance / Re: Arduino udp and processing udp on: July 15, 2014, 06:29:46 am
Try:
Code:
if(packetBuffer[0]=='a')
7  Using Arduino / Project Guidance / Re: Automatic Garden Watering System on: July 09, 2014, 03:33:13 pm
Sounds feasible. You might want to consider the plastic solenoid they offer - that brass one pulls a lot of current.
8  Topics / Home Automation and Networked Objects / Re: How to send a http command from my arduino? on: July 06, 2014, 06:39:24 am
Since both GET and POST require you to send information to the server, if you control the server, you can use either and GET is nice and simple.

In your case, it very much depends what your automation system expects.
9  Using Arduino / Programming Questions / Re: Automated Greenhouse on: July 06, 2014, 05:55:21 am
On improving your code:

You make use of const for your moisture values; there are plenty of other values (e.g. pin numbers) that would benefit from the same.

Don't repeat yourself: this piece of code appears three times - just move it up out of the if statements:
Code:
    Serial.print("Temp in C: ");
    Serial.println(tempC);

determineTempRange could have a better name to indicate its function - it's controlling the fan speed but its name doesn't make this obvious.

Use of globals is common in arduino sketches but if you're being graded on the quality of your code, you may want to try minimizing their use. In any event, usage here is peculiar:
Code:
int readMoisture()  {  //read the moisture
  moisture = analogRead(moisturePin);
  return moisture;
}
moisture is global and yet you choose to return it and assign it again where this routine is called.

Comments are good. Comments that echo the code are not so much:
Code:
  moisture = readMoisture();  //get the moisture

Check the spelling in your comments. Of course errors make no difference to functionality, but they indicate a lack of attention to detail:
Code:
const int moistureDry = 300;  //moistrue dry level
10  Using Arduino / Programming Questions / Re: Automated Greenhouse on: July 06, 2014, 05:12:56 am
Sounds like a common issue: the arduino only has one ADC and if you're reading two analog pins back to back the reading from one can influence the other. One way to deal with this is to read each pin twice but ignore the first value you get.
11  Using Arduino / Project Guidance / Re: Questions about ethernet shield on: July 05, 2014, 01:26:49 pm
They are very different things; do you need a micro controller or a device that runs Linux? Which of course boils down to - what do you wish to do with your hardware once you have it?
12  Using Arduino / Programming Questions / Re: How to split a byte into nibbles ? on: July 05, 2014, 10:21:21 am
76 % 10 gives you six
76 / 10 gives you seven assuming the  76 is in an int
13  Using Arduino / Programming Questions / Re: I keep getting "myservo was not declared in this scope" error. on: July 05, 2014, 06:55:04 am
Here's a version that compiles at least:
Code:
/*
 Ultrasonic Smart car obstacle avoidance procedures (ARDUINO)
     L = Left
     R = Right
     F = front
     B = after
 */
 #include <Servo.h>
 int pinLB = 6;       // Define pin left after 6
 int pinLF = 9;       // Define the 9-pin front left

 int pinRB = 10;      // 10 pin definitions right rear 
 int pinRF = 11;      // Define the 11-pin front right

 int inputPin = A0;    // Define pin ultrasonic signal reception
 int outputPin = A1;    // Define pin ultrasonic signal transmitter

 int Fspeedd = 0;        //-Speed
 int Rspeedd = 0;        // Right speed
 int Lspeedd = 0;        // Left-speed
 int directionn = 0;     // Front Left = 8 after = 2 = 4 Right = 6
 Servo myservo;          // Set myservo
 int delay_time = 250; // settling time after steering servo motors

 int Fgo = 8;           // Forward
 int Rgo = 6;           // Right
 int Lgo = 4;           // Left
 int Bgo = 2;           // Reverse

 void setup ()
   {
   Serial.begin (9600);       // Define motor output pin
   pinMode (pinLB, OUTPUT); // pin 8 (PWM)
   pinMode (pinLF, OUTPUT); // pin 9 (PWM)
   pinMode (pinRB, OUTPUT); // pin 10 (PWM)
   pinMode (pinRF, OUTPUT); // pin 11 (PWM)
 
   pinMode (inputPin, INPUT);      // Define ultrasound input pin
   pinMode (outputPin, OUTPUT);    // Define ultrasonic output pin   

   myservo.attach (5);      // Define servo motor output section 5 pin (PWM)
   }
 void advance (int a)       // Forward
     {
      digitalWrite (pinRB, LOW);    // The motor (rear right) action
      digitalWrite (pinRF, HIGH);
      digitalWrite (pinLB, LOW);    // The motor (left rear) action
      digitalWrite (pinLF, HIGH);
      delay (a * 100);     
     }

 void right (int b)          // Turn right (single wheel)
     {
      digitalWrite (pinRB, LOW);     // The motor (rear right) action
      digitalWrite (pinRF, HIGH);
      digitalWrite (pinLB, HIGH);
      digitalWrite (pinLF, HIGH);
      delay (b * 100);
     }
 void left (int c)           // Turn left (single wheel)
     {
      digitalWrite (pinRB, HIGH);
      digitalWrite (pinRF, HIGH);
      digitalWrite (pinLB, LOW);     // The motor (left rear) action
      digitalWrite (pinLF, HIGH);
      delay (c * 100);
     }
 void turnR (int d)          // Turn right (wheel)
     {
      digitalWrite (pinRB, LOW);    // The motor (rear right) action
      digitalWrite (pinRF, HIGH);
      digitalWrite (pinLB, HIGH);
      digitalWrite (pinLF, LOW);    // The motor (front left) action
      delay (d * 100);
     }
 void turnL (int e)          // Turn left (wheel)
     {
      digitalWrite (pinRB, HIGH);
      digitalWrite (pinRF, LOW);     // The motor (front right) action
      digitalWrite (pinLB, LOW);     // The motor (left rear) action
      digitalWrite (pinLF, HIGH);
      delay (e * 100);
     }     
 void stopp (int f)           // Stop
     {
      digitalWrite (pinRB, HIGH);
      digitalWrite (pinRF, HIGH);
      digitalWrite (pinLB, HIGH);
      digitalWrite (pinLF, HIGH);
      delay (f * 100);
     }
 void back (int g)            // Check out
     {

      digitalWrite (pinRB, HIGH);    // The motor (rear right) action
       digitalWrite (pinRF, LOW);
      digitalWrite (pinLB, HIGH);    // The motor (left rear) action
      digitalWrite (pinLF, LOW);
      delay (g * 100);     
     }
   
 void detection ()          // Measure three angles (0.90.179)
     {       
       int delay_time = 250;    // Settling time // servo motor after turning
       ask_pin_F ();              // Read from front
     
      if (Fspeedd <10)           // If the distance is less than 10 cm in front of
       {
       stopp (1);                 // Clear the output data
       back (2);                  // Check out 0.2 seconds
       }
           
       if (Fspeedd <25)           // If the distance is less than 25 cm in front of
       {
         stopp (1);                 // Clear the output data
         ask_pin_L ();              // Read from left
         delay (delay_time);        // Wait for a stable servo motor
         ask_pin_R ();              // Read from the right   
         delay (delay_time);        // Wait for a stable servo motor   
       
         if (Lspeedd> Rspeedd)      // If the distance is greater than the right from the left
         {
          directionn = Rgo;         // Right away
         }
       
         if (Lspeedd <= Rspeedd)      // If the left is less than or equal to the distance from the right
         {
          directionn = Lgo;         // Turn Left
         }
       
         if (Lspeedd <10 && Rspeedd <10)      // If the distance to the left and right are less than 10 cm distance
         {
          directionn = Bgo;         // To go after         
         }           
       }
       else                        // Add as front not less than (greater than) 25 cm     
       {
         directionn = Fgo;           // Move forward     
       }
     
     }     
 void ask_pin_F ()     // Measure the distance from the front
     {
        myservo.write (90);
       digitalWrite (outputPin, LOW);     // / Let ultrasonic transmitter low voltage 2 μ s
       delayMicroseconds (2);
       digitalWrite (outputPin, HIGH);    /// Let ultrasonic transmitter high voltage 10 μ s, where at least 10 μ s
       delayMicroseconds (10);
       digitalWrite (outputPin, LOW);      // / Maintain low voltage ultrasonic transmitter
       float Fdistance = pulseIn (inputPin, HIGH);    // / Read worse time difference
       Fdistance = Fdistance/5.8/10;         // / Time to turn to the distance (unit: cm)
       Serial.print ("F distance:");        // / Output distance (unit: cm)
       Serial.println (Fdistance);           // / Display the distance
       Fspeedd = Fdistance;                 // / Read into the distance Fspeedd (former speed)
     }   
   void ask_pin_L ()     // / Measure the distance from the left
     {
       myservo.write (5);
       delay (delay_time);
       digitalWrite (outputPin, LOW);     // Let ultrasonic transmitter low voltage 2 μ s
       delayMicroseconds (2);
       digitalWrite (outputPin, HIGH);    // Let ultrasonic transmitter high voltage 10 μ s, where at least 10 μ s
       delayMicroseconds (10);
       digitalWrite (outputPin, LOW);      // Maintain low voltage ultrasonic transmitter
       float Ldistance = pulseIn (inputPin, HIGH);    // Read worse time difference
       Ldistance = Ldistance/5.8/10;         // Time to turn to the distance (unit: cm)
       Serial.print ("L distance:");         // Output distance (unit: cm)
       Serial.println (Ldistance);           // Display the distance
       Lspeedd = Ldistance;                // Read into the distance Lspeedd (left-speed)
     }   
 void ask_pin_R ()     // Measure the distance from the right
     {
       myservo.write (177);
       delay (delay_time);
       digitalWrite (outputPin, LOW);     // Let ultrasonic transmitter low voltage 2 μ s
       delayMicroseconds (2);
       digitalWrite (outputPin, HIGH);    // Let ultrasonic transmitter high voltage 10 μ s, where at least 10 μ s
       delayMicroseconds (10);
       digitalWrite (outputPin, LOW);      // Maintain low voltage ultrasonic transmitter
       float Rdistance = pulseIn (inputPin, HIGH);    // Read worse time difference
       Rdistance = Rdistance/5.8/10;         // Time to turn to the distance (unit: cm)
       Serial.print ("R distance:");         // Output distance (unit: cm)
       Serial.println (Rdistance);           // Display the distance
       Rspeedd = Rdistance;                // Will read into the distance Rspeedd (Right-speed)
     }   
   
 void loop ()
   {
     myservo.write (90);    // Let servo motor position ready to return to the pre-prepared next time measurement
     detection ();          // Measure the angle and direction of judgment to where to move
     
    if (directionn == 2)    // If directionn (direction) = 2 (reverse)             
    {
      back (8);                      //    Retrogression (car)
      turnL (2);                     // Move slightly to the left (to prevent stuck in dead alley)
      Serial.print ("Reverse");     // Display direction (backwards)
    }
    if (directionn == 6)             // If directionn (direction) = 6 (right turn)     
    {
      back (1);
      turnR (6);                     // Right
      Serial.print ("Right");      // Display direction (turn left)
    }
    if (directionn == 4)            // If directionn (direction) = 4 (turn left)     
    {   
      back (1);       
      turnL (6);                    // Left
      Serial.print ("Left");       // Display direction (turn right)   
    }   
    if (directionn == 8)            // If directionn (direction) = 8 (forward)       
    {
     advance (1);                   // Normal Forward   
     Serial.print ("Advance");     // Display direction (forward)
     Serial.print ("     ");     
    }
   }
14  Using Arduino / Programming Questions / Re: reading data returned from HTTP GET in Arduino with Xbee wifi on: July 04, 2014, 07:39:08 am
What baud rate are you using? If it isn't already 115200, try making it so. Serial.print blocks when you fill the outbound buffer and at low speeds may be causing your incoming data to be missed, just as delay was doing.
15  Using Arduino / Programming Questions / Re: Sending Analog Sensor Data Between XBees on: July 04, 2014, 06:29:16 am
strtok or strchr are useful C string handling functions for this kind of simple parsing.
Pages: [1] 2 3 ... 244