Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8571387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:46:14+00:00 2026-06-11T18:46:14+00:00

The microcontroller is AVR and the processor in it is ATMEGA8. I wrote a

  • 0

The microcontroller is AVR and the processor in it is ATMEGA8. I wrote a piece that followed the black color. It is like :

#include<avr/io.h>
#include<util/delay.h>
int main()
{
int rs,ls; // denotes the right sensor and left sensor respectively 
DDRC=0x00; // DENOTES THAT WE TAKE INPUT FROM THE SENSER
DDRB=0xFF; // DENOTES THAT PORT IS MEANT FOR THE OUTPUT FROM THE MOTOR
while(1) {
 ls=PINC&0b0000001; // last bit on
 rs=PINC&0b0001000; // 1st bit on

 if((ls==0b0000001)&(rs==0b0001000))
  PORTB=0b00010010; // forward
 if((ls==0b0000001)&(rs==0b0000000))
  PORTB=0b00000010; // right
 if( (ls==0b0000000) & (rs==0b0001000))
  PORTB=0b00010000; // left
 if((ls==0b0000000)&(rs==0b0000000) )
  PORTB=0b00010010; // stop
}
}

I am trying to write for the edge avoider. It has the same sensors that detect the black color. But now those sensers have to avoid a pit while moving on the table. I am unable to decide as to how i can do this.

NOTE : Sensor is able to detect the pit if there is nothing beneath it. But how do I am having problem writing code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:46:15+00:00Added an answer on June 11, 2026 at 6:46 pm

    There can be many solutions for Edge Avoider. One implementation I have seen is –

    Explanation –

    • If none (left & right) is black (black = edge, white = table surface), you can keep moving forward.
    • If any/both are black, you need to back off a little (CAUTION : This is tricky, in backing also, you may end up falling), and then change direction.

    You need to experiment with delays, to get appropriate working.

    These are the values needed below (I had omitted them before, because they are dependent on configuration)-

    int move_backward = 0b00000110;
    int right_turn = 0b00001010;
    int move_forward = 0b00001001;
    int left_turn = 0b00000101;
    
    int left_sensor_on = 0b0010000;
    int right_sensor_on = 0b0100000;
    int left_sensor_off = 0b0000000;
    int right_sensor_off = 0b0000000;
    

    The below code should go inside while (1)

    left_sensor = (PINC & 0b0000001); // This depends upon your configuration
    right_sensor = (PINC & 0b0001000); // So I have used, the one from your code
    
    if ((left_sensor==left_sensor_off) & (right_sensor==right_sensor_off))
    {
        PORTB = move_backward;       //move backward
        _delay_ms(50);
        PORTB=right_turn;           //take a right turn
        _delay_ms(30);
        left_sensor = 0;
        right_sensor = 0;
    }
    if ((left_sensor==left_sensor_on) & (right_sensor==right_sensor_on))
    {
        PORTB = move_forward;        //move forward
        left_sensor = 0;
        right_sensor = 0;
    } 
    if ((left_sensor==left_sensor_off) & (right_sensor==right_sensor_on))
    {
        PORTB = move_backward;
        _delay_ms(50);
        PORTB = right_turn;
        _delay_ms(30);
        left_sensor = 0;
        right_sensor = 0;
    }
    
    if ((left_sensor==left_sensor_on) & (right_sensor==right_sensor_off))
    {
        PORTB = move_backward;
        _delay_ms(50);
        PORTB = left_turn;
        _delay_ms(30);
        left_sensor = 0;
        right_sensor = 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Programming a 8-bit AVR microcontroller I've came across a behavior that is shown on
I have a microcontroller that returns a status response like this from an HTTP
I am using AVR as the micro controller and ATMEGA8 as the processor (inside
I'm trying to build GCC for use with an AVR microcontroller and avr-ada, and
I would like to use both 8-bit timers of an ATmega 64 microcontroller .
I am programming an AVR microcontroller, and in the programmers notepad in the WINAVR
I have encountered a problem in a C program running on an AVR microcontroller
I'm working on an i/o project where I have a microcontroller that communicates with
I have a microcontroller that must download a large file from a PC serial
I wrote my own terminal program that reads from the serial port to read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.