EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Replies / A program that I have written

A program that I have written

|

Microcontroller › AVR › SMS operated robot › A program that I have written

June 8, 2013 at 3:22 pm #9914
SOUBHIK KUMAR DEY
Participant

A program that I have written for the SMS ROBOT –

 

/* Header files */

 

 

 

#include<avr/io.h>

#include<avr/delay.h>

#include”at8ports.h”

 

int s[10];              /*GLOBAL VARIABLE to store INPUT in an array format*/

int sms;                                /*GLOBAL VARIABLE  to receive incoming sms*/

 

/* Initialise input & output pins */

 

/*

PD0 is the sensor input pin

PB1 and PB2 are the motor speed control pins

PC0 to PC3 are the motor direction control pins

*/

 

void init_settings()

{

                DDRD_IN(0);                      /* PD0 = Input */

               

                DDRB_OUT(1);  /* PB1 = Output */

                DDRB_OUT(2);  /* PB2 = Output */

 

                DDRC_OUT(0);  /* PC0 = Output */

                DDRC_OUT(1);  /* PC1 = Output */

                DDRC_OUT(2);  /* PC2 = Output */

                DDRC_OUT(3);  /* PC3 = Output */

}

 

 

 

/* Functions for different directions */

/* Direction is determined from PC0 to PC3 */

 

/*PB_ON(x) implies to turn ON PULL UP resistor of PBx i.e. set the Output of PBx as LOGIC 1*/

/*PB_OFF(x) implies to turn OFF PULL UP resistor of PBx i.e. set the Output of PBx as LOGIC 0*/

/*same concept applies to all other pins*/

 

void forward()

{

                /* PB1 and PB2 will always be high */

 

                PB_ON(1);

                PB_ON(2);

 

                /* PC0 to PC3 = 1010 */

                /*This is the ideal forward condition i.e. Logic 1:Logic 0:Logic 1:Logic 0*/

 

                PC_ON(0);

                PC_OFF(1);

                PC_ON(2);

                PC_OFF(3);

}

 

void left()

{

                /* PB1 and PB2 will always be high */

 

                PB_ON(1);

                PB_ON(2);

 

                /* PC0 to PC3 = 0110 */

                /* Left motor backward (so opposite LOGIC to FORWARD), Right motor forward*/

 

                PC_OFF(0);

                PC_ON(1);

                PC_ON(2);

                PC_OFF(3);

}

 

void right()

{

                /* PB1 and PB2 will always be high */

 

                PB_ON(1);

                PB_ON(2);

 

                /* PC0 to PC3 = 1001 */

                /* Left motor forward, Right motor backward (so opposite LOGIC to FORWARD)*/

 

 

                PC_ON(0);

                PC_OFF(1);

                PC_OFF(2);

                PC_ON(3);

}

 

void backward()

{

                /* PB1 and PB2 will always be high */

 

                PB_ON(1);

                PB_ON(2);

 

                /* PC0 to PC3 = 0101 */

                /*Both motors in Backward direction, exactly opposite to Forward*/

 

                PC_OFF(0);

                PC_ON(1);

                PC_OFF(2);

                PC_ON(3);

}

 

/* To take input from the sensors [PD0 to PD4] */

 

void sensors()

{

                sms = PD_IN(0);

               

}

 

 

/*SOMEHOW WE HAVE TO BREAK THE DIGITS RECEIVED BY SMS SO THAT EACH DIGIT GETS STORED AS AN ELEMENT OF ARRAY s[ ] AND WE CAN THEN MANIPULATE TO OUR WISH. THIS I AM NOT UNABLE TO DO SO. AS OF NOW LET’S ASSUME OUR INCOMING sms IS A 2-DIGIT NO. CONSISTING OG 1 & 0. THESE DIGITS ARE ASSUMED TO BE STORED IN ARRAY FORMAT IN s[ ] in exactly same order*/

 

 

void main()

{

 

                init_settings();  /* To initialise all input and output pins */

 

                while(1)               /* Infinite loop */

                {

                                sensors();                            /* To take sensor values and store them */

                               

                                if(s[0] == 0 && s[1] == 1)                                              

                                {A

 

 

                                                left();                    /* Take a left turn */

                                                                               

}

 

                                else if(s[0] == 1 && s[1] == 0)                     /* Rightmost sensor */

                                {

                                                right();  /* Take a right turn */

                                               

                                }

 

 

 

                                else if(s[0] == 0 && s[1] == 0)                     /* No sensor on the line */

                                {

                                                PB_OFF(1);                         /*Motors stopped

PB_OFF(2);

                                }

                                else                        /* Zero error condition [Move forward] */

                                {

                                                forward();                           /* Go straight ahead */

                                }

                }                              /* End of while loop */

}                              /* End of the program */

RSS Recent Posts

  • Relay question May 19, 2026
  • Phone Charger 5v to 12v May 19, 2026
  • reviving old swordfish program but? May 18, 2026
  • Assistance locating a 'trail' camera gadget, please ? May 18, 2026
  • Projector focus circuit May 18, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise