Go Down

Topic: Help needed with controlling a robot using obstacle avoiding sensors. (Read 4356 times) previous topic - next topic


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



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

Code: [Select]

#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() {


  // 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!!!  XD XD
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.



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! :)

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131