Pages: 1 2 [3]   Go Down
Author Topic: Help needed with controlling a robot using obstacle avoiding sensors.  (Read 2813 times)
0 Members and 1 Guest are viewing this topic.
Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 27
"A manual is my bible"
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

 smiley-roll-sweat *facepalms*
Sometimes I go faster than I should. but you're right I'll continue learning.
Thanks for now!

M
Logged

Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 27
"A manual is my bible"
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

After following the suggestions given to me, I sketched this:

Code:

#include <legopowerfunctions.h> // Lego PF Library

LEGOPowerFunctions lego(13); // Pin for Lego PF IR Output

//configure the obstacle avoiding sensor
int sensorEN = 7;    // Common pin for module
int sensorLO = 6;    // Left Object detected output pin
int sensorRO = 5;    // Right Object detected output pin   
int senValue = 0;  // variable to store the value coming from the sensor
unsigned long last_event = 1;

void setup() {

  last_event=millis();

  // Set the desired pin modes
  pinMode(sensorEN, OUTPUT);
  pinMode(sensorLO, INPUT);
  pinMode(sensorRO, INPUT);

  // ready the sensor
  digitalWrite(sensorEN, HIGH);

}

void loop()

{
  // move forward
  if ((digitalRead(sensorLO) == LOW) && (digitalRead(sensorRO) == LOW)) {
    lego.ComboPWM(PWM_REV3, PWM_FWD3, CH4);
  }

  {
    // move left
    if ((digitalRead(sensorLO) == HIGH) && (digitalRead(sensorRO) == LOW)) {
      lego.ComboPWM(PWM_BRK, PWM_FWD3, CH4);
    }
    {
      // move right
      if ((digitalRead(sensorLO) == LOW) && (digitalRead(sensorRO) == HIGH)) {
        lego.ComboPWM(PWM_REV3, PWM_BRK, CH4);
      }

      {
        // move backwards
        if ((digitalRead(sensorLO) == HIGH) && (digitalRead(sensorRO) == HIGH)) {
          lego.ComboPWM(PWM_FWD3, PWM_REV3, CH4);
        }
      }
    }
  }
}


After uploading the code I put my robot on the floor and it started roaming.. and it worked!!!  smiley-lol smiley-lol
Totally awesome! Throughout the years I tried several times to build and programme something like this,
so for me it is a big breakthrough! :-) So many thanks for the nice people on this forum, people who write
tutorials and the Arduino team for developing a great platform!

Ofcourse I have some questions left, about the sketch, like:

- Is this sketch memory friendly?
Because I see this roaming sketch as a first chapter, I do want to add more functionality, like using RGB LEDS
for Head, Tail and turninglights, some sound events.

M
Logged

0
Offline Offline
God Member
*****
Karma: 2
Posts: 596
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is this sketch memory friendly?
Because I see this roaming sketch as a first chapter, I do want to add more functionality

Don't worry, you still have plenty of room for more functionality. Keep learning and report back! smiley
Logged

Pages: 1 2 [3]   Go Up
Jump to: