Is it ok to send 5v to the reset pin?

Hi.
Im making a hexapod project controlled by IR remote, I use the remote to turn it on and off
but i cant turn it off (just stop it in place)
I’ve been trying everything but with no success.
Yesterday I’ve got an idea
the idea is to connect pin 2 to the reset pin
and then when the IR sensor get anything it will trigger the interrupt function and will send 5v to the reset pin,
or I need to bring low voltage to the reset pin?

Sorry for my bad English, i hope you get the idea :slight_smile:

/******* Preprocessor Directives *******/

#include <Servo.h>  //Include servo library
#include <IRremote.h>  //Include IR library

#define trigPin 13 //Define pin 13 as trig pin
#define echoPin 12 //Define pin 12 as echo pin
#define led 7  //Define pin 7 as red led+buzzer pin
#define led2 8 // Define pin 8 as green pin

/******* Global Variables Declarations *******/

Servo Middleservo; //Define first servo
Servo Rightservo; //Define second servo
Servo Leftservo; //Define third servo

int IR_Recv = 3; //IR Receiver Pin 3
int shutdown = 0;

IRrecv irrecv(IR_Recv); //Create the receiver object
decode_results results; //Decode the results from the sensor

/******* Initializing the setup of the main function *******/

/*
*	Function name: setup
*	Purpose:
*			- Setup of the serial input.
*			- Trigger the pins to be ready for input / output.
*			- Setup of the 3 main servo engines.
*			- Setup of the IR sensor.
*	Return value: None.
*	Important notes: None.
*/

void setup() 
{
  Serial.begin (9600); //Start the serial communication at 9600 bits per second

  pinMode(trigPin, OUTPUT); // make the trigger's pin an output:
  pinMode(echoPin, INPUT); // make the echo's pin an input:
  pinMode(led, OUTPUT); // make the red led+buzzer pin an output:
  pinMode(led2, OUTPUT); // make the green led pin an output:

  Middleservo.attach(9); //Attach the Middleservo variable to pin 9
  Rightservo.attach(10); //Attach the Rightservo variable to pin 10
  Leftservo.attach(11); //Attach the Leftservo variable to pin 11

  irrecv.enableIRIn(); // Starts the receiver
  irrecv.blink13(true); //Enable blinking the LED when during reception
}

/*
*	Function name: loop
*	Purpose:
*			The main function of the project.
*			The whole proccess of operating the robot.
*			The function waits for the signal from the IR remote, when the IR signal is recieved the function calculates the distance between the actual robot to an obstacle,
*			By the distance the function sets the way of the behavior of the robot(Go straight, Turn around and ETC.. ).
*	Return value: None.
*	Important notes: None.
*/

void loop()
{
  if (irrecv.decode(&results)) //Attempt to receive a IR code
  {
    if(results.value == 16753245)
    {
      //Set the variables as 0
      long duration = 0, distance = 0;
      // Start Ranging
      digitalWrite(trigPin, LOW);
      delayMicroseconds(2);
      digitalWrite(trigPin, HIGH);
      delayMicroseconds(10);
      digitalWrite(trigPin, LOW);
      // Compute distance
      duration = pulseIn(echoPin, HIGH);
      distance = (duration/2) / 29.1;

      if(distance <= 20) //If the distance is lower or equal to 20 CM do below
      {
        digitalWrite(led,HIGH); // sets the red led+buzzer on
        digitalWrite(led2,LOW); // sets the green led off

        Middleservo.write(75); // set Middleservo to 75 degrees
        delay(200); // waits for a 200 milliseconds
        Leftservo.write(110); // set Leftservo to 110 degrees
        delay(50); // waits for a 50 milliseconds
        Rightservo.write(80); // set Rightservo to 80 degrees
        delay(50); // waits for a 50 milliseconds
        Middleservo.write(95); // set Middleservo to 95 degrees
        delay(200); // waits for a 200 milliseconds
        Rightservo.write(105); // set Rightservo to 105 degrees
        delay(50); // waits for a 50 milliseconds
        Leftservo.write(80); // set Leftservo to 80 degrees
        delay(50); // waits for a 50 milliseconds
      }
      else //If the distance isnt lower or equal to 20 CM do below:
      {
        digitalWrite(led,LOW); // sets the red led+buzzer off
        digitalWrite(led2,HIGH); // sets the green led on

        Middleservo.write(65); // set Middleservo to 65 degrees
        delay(200); // waits for a 200 milliseconds
        Leftservo.write(80);  // set Leftservo to 80 degrees
        delay(50); // waits for a 50 milliseconds
        Rightservo.write(80);  // set Rightservo to 80 degrees
        delay(50); // waits for a 50 milliseconds
        Middleservo.write(105); // set Middleservo to 105 degrees
        delay(200); // waits for a 200 milliseconds
        Rightservo.write(110);  // set Rightservo to 110 degrees
        delay(50); // waits for a 50 milliseconds
        Leftservo.write(110);  // set Leftservo to 110 degrees
        delay(50); // waits for a 50 milliseconds	 
      }
      if (distance >= 200 || distance <= 0)
      { //If the distance is bigger or equal to 200 and lower and equal to 0
        Serial.println("Out of range"); // print "Out of range"
      }
      else 
      {  //If the distance is NOT bigger or equal to 200 and lower and equal to 0
        Serial.print(distance); //print distance
        Serial.println(" cm"); //print cm below the distance
      }
    }
    else //if the result isnt 16753245 do below
    {
      irrecv.resume(); //reset the receiver and prepare it to receive another code
    }
  }
}

Easy way to find your answer is to look at the datasheet for the uC that you're using. However, reset should be pulled-down to GND for a reset to happen.

Yesterday I've got an idea the idea is to connect pin 2 to the reset pin and then when the IR sensor get anything it will trigger the interrupt function and will send 5v to the reset pin, or I need to bring low voltage to the reset pin?

First did you know the reset pin should be high in order the micro controller to run. So to do a reset to him it must be pulled down for some time(consult the data sheet about that minimum time) About your idea i suggest you don’t do that!! I don understand why you need to reset the micro controller when you receive something??? Shouldn’t instead you process that data? Using a pin to trigger a reset on him self won't prevent the minimum time to reset happen in a "save" way

but i cant turn it off (just stop it in place) I've been trying everything but with no success.

You have not tried everything or you would have succeeded. Presumably you have managed to send other commands and it is just the 'stop moving' command that you are having trouble with. Your question seems to indicate, however, that you want the bot to stop

when the IR sensor get anything

so maybe not.

Post your code and you will get more helpful answers

Ok so here is my code:

/******* Preprocessor Directives *******/

#include <Servo.h>  //Include servo library
#include <IRremote.h>  //Include IR library

#define trigPin 13 //Define pin 13 as trig pin
#define echoPin 12 //Define pin 12 as echo pin
#define led 7  //Define pin 7 as red led+buzzer pin
#define led2 8 // Define pin 8 as green pin

/******* Global Variables Declarations *******/

Servo Middleservo; //Define first servo
Servo Rightservo; //Define second servo
Servo Leftservo; //Define third servo

int IR_Recv = 3; //IR Receiver Pin 3
int shutdown = 0;

IRrecv irrecv(IR_Recv); //Create the receiver object
decode_results results; //Decode the results from the sensor

/******* Initializing the setup of the main function *******/

/*
*	Function name: setup
*	Purpose:
*			- Setup of the serial input.
*			- Trigger the pins to be ready for input / output.
*			- Setup of the 3 main servo engines.
*			- Setup of the IR sensor.
*	Return value: None.
*	Important notes: None.
*/

void setup() 
{
  Serial.begin (9600); //Start the serial communication at 9600 bits per second

  pinMode(trigPin, OUTPUT); // make the trigger's pin an output:
  pinMode(echoPin, INPUT); // make the echo's pin an input:
  pinMode(led, OUTPUT); // make the red led+buzzer pin an output:
  pinMode(led2, OUTPUT); // make the green led pin an output:

  Middleservo.attach(9); //Attach the Middleservo variable to pin 9
  Rightservo.attach(10); //Attach the Rightservo variable to pin 10
  Leftservo.attach(11); //Attach the Leftservo variable to pin 11

  irrecv.enableIRIn(); // Starts the receiver
  irrecv.blink13(true); //Enable blinking the LED when during reception
}

/*
*	Function name: loop
*	Purpose:
*			The main function of the project.
*			The whole proccess of operating the robot.
*			The function waits for the signal from the IR remote, when the IR signal is recieved the function calculates the distance between the actual robot to an obstacle,
*			By the distance the function sets the way of the behavior of the robot(Go straight, Turn around and ETC.. ).
*	Return value: None.
*	Important notes: None.
*/

void loop()
{
  if (irrecv.decode(&results)) //Attempt to receive a IR code
  {
    if(results.value == 16753245)
    {
      //Set the variables as 0
      long duration = 0, distance = 0;
      // Start Ranging
      digitalWrite(trigPin, LOW);
      delayMicroseconds(2);
      digitalWrite(trigPin, HIGH);
      delayMicroseconds(10);
      digitalWrite(trigPin, LOW);
      // Compute distance
      duration = pulseIn(echoPin, HIGH);
      distance = (duration/2) / 29.1;

      if(distance <= 20) //If the distance is lower or equal to 20 CM do below
      {
        digitalWrite(led,HIGH); // sets the red led+buzzer on
        digitalWrite(led2,LOW); // sets the green led off

        Middleservo.write(75); // set Middleservo to 75 degrees
        delay(200); // waits for a 200 milliseconds
        Leftservo.write(110); // set Leftservo to 110 degrees
        delay(50); // waits for a 50 milliseconds
        Rightservo.write(80); // set Rightservo to 80 degrees
        delay(50); // waits for a 50 milliseconds
        Middleservo.write(95); // set Middleservo to 95 degrees
        delay(200); // waits for a 200 milliseconds
        Rightservo.write(105); // set Rightservo to 105 degrees
        delay(50); // waits for a 50 milliseconds
        Leftservo.write(80); // set Leftservo to 80 degrees
        delay(50); // waits for a 50 milliseconds
      }
      else //If the distance isnt lower or equal to 20 CM do below:
      {
        digitalWrite(led,LOW); // sets the red led+buzzer off
        digitalWrite(led2,HIGH); // sets the green led on

        Middleservo.write(65); // set Middleservo to 65 degrees
        delay(200); // waits for a 200 milliseconds
        Leftservo.write(80);  // set Leftservo to 80 degrees
        delay(50); // waits for a 50 milliseconds
        Rightservo.write(80);  // set Rightservo to 80 degrees
        delay(50); // waits for a 50 milliseconds
        Middleservo.write(105); // set Middleservo to 105 degrees
        delay(200); // waits for a 200 milliseconds
        Rightservo.write(110);  // set Rightservo to 110 degrees
        delay(50); // waits for a 50 milliseconds
        Leftservo.write(110);  // set Leftservo to 110 degrees
        delay(50); // waits for a 50 milliseconds	 
      }
      if (distance >= 200 || distance <= 0)
      { //If the distance is bigger or equal to 200 and lower and equal to 0
        Serial.println("Out of range"); // print "Out of range"
      }
      else 
      {  //If the distance is NOT bigger or equal to 200 and lower and equal to 0
        Serial.print(distance); //print distance
        Serial.println(" cm"); //print cm below the distance
      }
    }
    else //if the result isnt 16753245 do below
    {
      irrecv.resume(); //reset the receiver and prepare it to receive another code
    }
  }
}

My problem is when the IR sensor recieves a signal it set’s it into the results.value.
Then if i want to use another value I have to reset the previous with this command "irrecv.resume() "
now, I need it to stay in the working loop for unlimited time and scan for new value at the same time.
The second problem I have is when I tried to stop it, it stopped just for few seconds and then keep working again.

Anyone have a good idea for me? :slight_smile:

Something like this

      else 
      {  //If the distance is NOT bigger or equal to 200 and lower and equal to 0
        Serial.print(distance); //print distance
        Serial.println(" cm"); //print cm below the distance
      }
    }
    else if (results.value == the command that you want to stop the bot)
    {
       //commands to stop the bot go here 
    }
    else
    {
      irrecv.resume(); //reset the receiver and prepare it to receive another code
    }

I added those codes lines to he code but its still doesn't respond the next values. After i give him the first value its set itself as result.value and going into infinite loop

I need to reset the value but somehow to continue the working loop until its gets another value.

What value are you sending to stop the bot ? Please post your revised code

/******* Preprocessor Directives *******/

#include <Servo.h>  //Include servo library
#include <IRremote.h>  //Include IR library

#define trigPin 13 //Define pin 13 as trig pin
#define echoPin 12 //Define pin 12 as echo pin
#define led 7  //Define pin 7 as red led+buzzer pin
#define led2 8 // Define pin 8 as green pin

/******* Global Variables Declarations *******/

Servo Middleservo; //Define first servo
Servo Rightservo; //Define second servo
Servo Leftservo; //Define third servo

int IR_Recv = 3; //IR Receiver Pin 3
int shutdown = 0;

IRrecv irrecv(IR_Recv); //Create the receiver object
decode_results results; //Decode the results from the sensor

/******* Initializing the setup of the main function *******/

/*
*	Function name: setup
 *	Purpose:
 *			- Setup of the serial input.
 *			- Trigger the pins to be ready for input / output.
 *			- Setup of the 3 main servo engines.
 *			- Setup of the IR sensor.
 *	Return value: None.
 *	Important notes: None.
 */

void setup() 
{
  Serial.begin (9600); //Start the serial communication at 9600 bits per second

  pinMode(trigPin, OUTPUT); // make the trigger's pin an output:
  pinMode(echoPin, INPUT); // make the echo's pin an input:
  pinMode(led, OUTPUT); // make the red led+buzzer pin an output:
  pinMode(led2, OUTPUT); // make the green led pin an output:

  Middleservo.attach(9); //Attach the Middleservo variable to pin 9
  Rightservo.attach(10); //Attach the Rightservo variable to pin 10
  Leftservo.attach(11); //Attach the Leftservo variable to pin 11

    irrecv.enableIRIn(); // Starts the receiver
  irrecv.blink13(true); //Enable blinking the LED when during reception
}

/*
*	Function name: loop
 *	Purpose:
 *			The main function of the project.
 *			The whole proccess of operating the robot.
 *			The function waits for the signal from the IR remote, when the IR signal is recieved the function calculates the distance between the actual robot to an obstacle,
 *			By the distance the function sets the way of the behavior of the robot(Go straight, Turn around and ETC.. ).
 *	Return value: None.
 *	Important notes: None.
 */

void loop()
{
  if (irrecv.decode(&results)) //Attempt to receive a IR code
  {
    if(results.value == 16753245)
    {
      //Set the variables as 0
      long duration = 0, distance = 0;
      // Start Ranging
      digitalWrite(trigPin, LOW);
      delayMicroseconds(2);
      digitalWrite(trigPin, HIGH);
      delayMicroseconds(10);
      digitalWrite(trigPin, LOW);
      // Compute distance
      duration = pulseIn(echoPin, HIGH);
      distance = (duration/2) / 29.1;

      if(distance <= 20) //If the distance is lower or equal to 20 CM do below
      {
        digitalWrite(led,HIGH); // sets the red led+buzzer on
        digitalWrite(led2,LOW); // sets the green led off

        Middleservo.write(75); // set Middleservo to 75 degrees
        delay(200); // waits for a 200 milliseconds
        Leftservo.write(110); // set Leftservo to 110 degrees
        delay(50); // waits for a 50 milliseconds
        Rightservo.write(80); // set Rightservo to 80 degrees
        delay(50); // waits for a 50 milliseconds
        Middleservo.write(95); // set Middleservo to 95 degrees
        delay(200); // waits for a 200 milliseconds
        Rightservo.write(105); // set Rightservo to 105 degrees
        delay(50); // waits for a 50 milliseconds
        Leftservo.write(80); // set Leftservo to 80 degrees
        delay(50); // waits for a 50 milliseconds
      }
      else //If the distance isnt lower or equal to 20 CM do below:
      {
        digitalWrite(led,LOW); // sets the red led+buzzer off
        digitalWrite(led2,HIGH); // sets the green led on

        Middleservo.write(65); // set Middleservo to 65 degrees
        delay(200); // waits for a 200 milliseconds
        Leftservo.write(80);  // set Leftservo to 80 degrees
        delay(50); // waits for a 50 milliseconds
        Rightservo.write(80);  // set Rightservo to 80 degrees
        delay(50); // waits for a 50 milliseconds
        Middleservo.write(105); // set Middleservo to 105 degrees
        delay(200); // waits for a 200 milliseconds
        Rightservo.write(110);  // set Rightservo to 110 degrees
        delay(50); // waits for a 50 milliseconds
        Leftservo.write(110);  // set Leftservo to 110 degrees
        delay(50); // waits for a 50 milliseconds	 
      }
      if (distance >= 200 || distance <= 0)
      { //If the distance is bigger or equal to 200 and lower and equal to 0
        Serial.println("Out of range"); // print "Out of range"
      }
      else 
      {  //If the distance is NOT bigger or equal to 200 and lower and equal to 0
        Serial.print(distance); //print distance
        Serial.println(" cm"); //print cm below the distance
      }
    }
    else if (results.value == 16736925)
    {
      irrecv.resume(); //reset the receiver and prepare it to receive another code       
    }
  }
  else //if the result isnt 16753245 do below
  {
    irrecv.resume(); //reset the receiver and prepare it to receive another code
  }
}

turning on value = 16753245
turning off value = 16736925

    else if (results.value == 16736925)
    {
      irrecv.resume(); //reset the receiver and prepare it to receive another code       
    }

should be

    else if (results.value == 16736925)
    {
     //commands to stop the bot go here    
    }

I don’t know which command I can use to stop the bot.
i used the resume command to get back to the starting point and wait for turning on value.
that’s why I thought to use the reset pin

What sort of servos are you using ?
Are they conventional servos that move to a position and stop or do they rotate continuously ?

move to a position and stop

OK, they are the correct type

Can you describe exactly what happens when you power up the bot ? Do the servos move before you use the IR remote ? What happens when you send the command to start ? Do the servos move once or continue to move ?

Insert some Serial.prints in your code like this

void loop()
{
  if (irrecv.decode(&results)) //Attempt to receive a IR code
  {
    Serial.print("results.value : [");
    Serial.print(results.value);
    Serial.println("]");
    if(results.value == 16753245)
    {

What do you get printed when you press the 'start' key on the IR remote and when you don't ? What do you get printed when you press the 'stop' key ?

Can you describe exactly what happens when you power up the bot ? Do the servos move before you use the IR remote ? What happens when you send the command to start ? Do the servos move once or continue to move ? When i turn on the bot the servos stays on 90 degrees and resist any movement by touching them. They are stay at 90 degrees before i use the remote. When i sending the command to start to start the bot they start to work, in the same order as I wrote. They move until I disconnect the power. because it have the same result.value every time.

I added the code you gave me and here's the results: after I turn it on (pressed just once at the start) :

results.value : [16753245]
38 cm
results.value : [16753245]
140 cm
results.value : [16753245]
24 cm
results.value : [16753245]
24 cm
results.value : [16753245]
59 cm
results.value : [16753245]
28 cm
results.value : [16753245]
174 cm
results.value : [16753245]
105 cm
results.value : [16753245]
83 cm
results.value : [16753245]
118 cm
results.value : [16753245]
93 cm
results.value : [16753245]
113 cm
results.value : [16753245]
112 cm
results.value : [16753245]
96 cm
results.value : [16753245]
109 cm
results.value : [16753245]
104 cm
results.value : [16753245]
84 cm

what i got when i pressed on the stop bottom:

results.value : [16736925]

Then i pressed on the work bottom:

results.value : [16736925]
results.value : [16753245]
Out of range
results.value : [16753245]
28 cm
results.value : [16753245]
27 cm
results.value : [16753245]
27 cm
results.value : [16753245]
27 cm
results.value : [16753245]
27 cm
results.value : [16753245]
27 cm
results.value : [16753245]
27 cm
results.value : [16753245]
26 cm
results.value : [16753245]
27 cm
results.value : [16753245]

I tried to press on the off bottom while it working, but it didn't show it on the serial. It just keep to use the working value.

Looks like the problem is that once you have started the bot the value of the command is being remembered and acted upon.
Try this

      {  //If the distance is NOT bigger or equal to 200 and lower and equal to 0
        Serial.print(distance); //print distance
        Serial.println(" cm"); //print cm below the distance
      }
      irrecv.resume(); // <<<<<<<<< new line added
    }

This should reset the receiver.

Here's the problem with this code line i have to keep pressing on the bottom to keep it work I need to press once to make it work and once on the other bottom to stop it

What's happens? Every loop???? it resets the value and i have to set it again.

I need it to stay in the working loop for infinite time but in the same time to check for new values

Without the reset command it will never read another command.

A suggestion. Read the IR input every time through loop() When you receive a command set a variable to indicate the state of the program then issue the IR reset command. Keep the program doing what you want by checking the variable unless/until another command is read but do not block loop() from executing.