Bobby project

Hello

I am making a robot called Bobby,and it is based on Arduino nano v3. I have a lot of difficulties as i am alone in developing it and i want help from anybody in here willing to help me make a beautiful functional robot. Now im gonna say that i am 18 years old and i started developing it from 10. The base features of this robot are : - It goes forward,backward via controller - It turns :P - It measures distance from the front object with hs-sr04 radar - It uses an adxl345 sensor to determine his status(if its been held straight or anything else) - It uses a microsd to capture all those informations in every sec I want to try to make it harder, like using the hc-sr04 as a mvement tracker,so the robot can retain a static distance from the object in front when it is moving. I also have a facebook page called Bobby project which i will upload the whole code of arduino there,and i want anybody of you that knows arduino and can help me to support me via sending some changes in the code to make it work better and more reliable or even suggestions about doing something new. THe page is mostly in greek but i will use english language in posts or descriptions. The page is this : Facebook page And i will try to update this topic with changes and code in order for other members without fb can help me.

Your help is appreciated!

Hi. Can you give me the links to the part datasheets? And why are you using the Arduino Nano?

Hi nikosdd,

Yes I build bots, but don't name them. We can help, but tell us what motors you have, what driver board, is it L293 based, Do you have a chassis/kit or made your own. You can make it do the things you want, but give us more details.

You can see some of my early bots here: www.melsaunders.co.uk under Electronics.

Hope it helps. Regards

Mel.

Thanks for your reply. Bobby uses arduino because it has an adxl345 accelerometer,light sensor,hc-sr04 radar and an sd-card module. It gets all the values from adxl and light sensor and stores it onto an sdcard. For the hc-sr04 im trying to make it with relay modules,to detect obstacles and revert the motors in order to avoid the obstacle. For the motors im using an E-Sky electronic speed controller with an oroma fm receiver with crystal(35.150 FM). The board that holds all those modules is made by my own. I dont know what else you may need to know in order to help me... Right now i am trying to use correctly the hs-sr04 module and count the distance from the obstacles but many times when it is trying to calculate distances in open areas,without reason reverts the motors because of obstacle..

Hi nikosdd, Could we see your code? I only check for close distances like 20cm and don't bother with anything else, if you take a reading and the distance is too far, perhaps the HC-05? value overflows giving a false triggering...

Regards

Mel.

Yes this is the code

#include <SD.h>
#include <Wire.h>
#include <ADXL345.h>
#include <NewPing.h>

#define TRIGGER_PIN 4
#define ECHO_PIN 3
#define MAX_DISTANCE 200

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

byte x = 0;
File myFile;
ADXL345 adxl;
int timer;
int ch2;
int ch1;
int lightsensorPin = 3;
char mode;
int alldist = 40; //Allowed distance before stop
int startx,starty,startz;
int longgr = 0; //Gets 1 everytime something forces lights to turn on. So disables led checks

void setup()
{
  pinMode(6, OUTPUT); //Relay module no1
  pinMode(5, OUTPUT); //Relay module no2
  pinMode(A1, INPUT); //Pulse channel 2
  pinMode(A0, INPUT); //Pulse channel 1
  pinMode(8, OUTPUT); //Lights
  pinMode(A2, OUTPUT); //Laser
  pinMode(2, OUTPUT); //Ultrasonic radar green light
  pinMode(7, OUTPUT); //Ultrasonic radar yellow light
  pinMode(13, OUTPUT); //Main light pin 13
  startx = 0;
 // Open serial communications and wait for port to open:
  Serial.begin(115200);
  Wire.begin();
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  Serial.println("Connecting to Slave device");
  Serial.println("Powering on adxl345");
  adxl.powerOn();
  Serial.println("Initializing SD card...");
   pinMode(10, OUTPUT);
   
  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
  }
  else
  {
  Serial.println("initialization done.");
  }
  timer=1;
  mode = 'start';
}

void loop()
{
  int x,y,z;
  int warning = 1;
  longgr = 0;
  //Ultra sensor radar
  delay(10);
  unsigned int cm = sonar.ping_cm();
  if ((cm<=alldist) && (cm!=0))
  {
    Serial.print("Obstacle found at distance : ");
    Serial.print(cm);
    Serial.print(" Cm. Waiting 1 sec");
    digitalWrite(7, HIGH);
    digitalWrite(2, LOW);
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    warning = 2;
    delay(1000);
  }
  else
  {
   digitalWrite(7, LOW);
   digitalWrite(2, HIGH);
  }
  ch2 = pulseIn(A1, HIGH, 25000);
  ch1 = pulseIn(A0, HIGH, 25000);
  if ((cm>alldist) || (cm==0))
  {
    Serial.print("Next obstacle at : ");
    if (cm==0)
    {
      Serial.print(" Out of range");
    }
    else
    {
      Serial.print(cm);
      Serial.print(" Cm");
    }
    //ADXL
    {
      adxl.readAccel(&x, &y, &z);
      if(startx==0)
      {
        Serial.print("Starting adxl with defaults");
        Serial.print(x+y+z);
        startx=x;
        starty=y;
        startz=z;
      }
      //Adxl testing
      {
        if (y >= (starty+180))
        {
          longgr = 1;
          warning = 3;
        }
        if (y <= (starty-180))
        {
          longgr = 1;
          warning = 3;
        }
        if (x <= (startx-180))
        {
          longgr = 1;
          warning = 4;
        }
        if (x >= (startx+180))
        {
          longgr = 1;
          warning = 4;
        }
      }
      myFile = SD.open("sensors.txt", FILE_WRITE);
      if (myFile) 
      {
         myFile.print("Time : Uknown");
         myFile.print(" - (Adxl345) - X axis : ");
         myFile.print(x);
         myFile.print(" - Y axis : ");
         myFile.print(y);
         myFile.print(" - Z axis : ");
         myFile.print(z);
         myFile.print(" - (LightSensor) - sensitivity : ");
         myFile.println(analogRead(lightsensorPin));
         myFile.close();
      }
      Serial.print(" Gravity sensor : X = ");
      Serial.print(x);
      Serial.print(" ,Y = ");
      Serial.print(y);
      Serial.print(" ,Z = ");
      Serial.print(z);
    }
    //Relay module
    {
      if (ch2>1400)
      {
        digitalWrite(5, LOW);
        digitalWrite(6, LOW);
      }
      else
      {
         digitalWrite(5, HIGH);
         digitalWrite(6, HIGH); 
      }
    }
    //Lights
    {
      if ((ch1 <1100) && (longgr==0))
      {
         digitalWrite(8, LOW);
         digitalWrite(A2, LOW);
      }
      else
      {
         digitalWrite(8, HIGH);
         if (longgr==0)
         {
           digitalWrite(A2, HIGH);
         }
         else
         {
           digitalWrite(A2, LOW); 
         }
      }
    }
  }
  Serial.println();
  Wire.beginTransmission(9);
  Wire.write(cm);
  Wire.write(x);
  Wire.write(y);
  Wire.write(z);
  Wire.write(analogRead(lightsensorPin));
  Wire.write(warning);
  Wire.endTransmission();
}

Ι have to mention that i’ve added another one arduino for testing purposes that uses I2C.

Anyone?? :(