Hello everybody my name is Aston and I am a student at college.
next semester I am required to do a project and have decided to create a robotic arm such as the one in the picture below.
The robotic arm uses 7 servos to control it, two of the servos will be running on the same signal.
To control the servos I have decided to use two arduinos which will communicate using infrared.
I have created a quick diagram to help put across my ideas
This circuit will be sending IR signals
This circuit will be receiving IR signals and control the servos
I have all the parts required to build it but i'm totally stuck with the coding I have been searching for hours but had no luck.
I've have found several bits of coding that needs improving upon and merging.
The first is controlling a servo using two buttons (Forum Link - http://forum.arduino.cc/index.php/topic,3595.0.html)
#include <Servo.h>
Servo myservo;
#define leftPin 2
#define rightPin 3
int pos = 90;
int delayPeriod = 50; // increasing this slows down the servo movement
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo.write(pos); // center the servo
pinMode(leftPin, HIGH); // turn on pullup resistors
pinMode(rightPin, HIGH);
}
void loop()
{
if(digitalRead(leftPin) == LOW)
{
// in steps of 1 degree
if( pos > 0)
--pos;
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(delayPeriod);
}
if(digitalRead(rightPin) == LOW)
{
if( pos < 180)
++pos;
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(delayPeriod);
}
}
If anyone can help me change the code from controlling one servo to six and is there any possibility of controlling the delay period for each servo independantly that would be amazing.
The next code is sending infrared code using the IR LED (Forum Link - http://garagelab.com/profiles/blogs/tutorial-arduino-ir-sender-and-receiver)
/*
irSend sketch
this code needs an IR LED connected to pin 3
and 5 switches connected to pins 4 - 8
*/
#include <IRremote.h>
// IR remote control library
const int numberOfKeys = 1;
const int firstKey = 4;
// the first pin of the 5 sequential pins connected to buttons
boolean buttonState[numberOfKeys];
boolean lastButtonState[numberOfKeys];
long irKeyCodes[numberOfKeys] = {
0x18E758A7, //0 key
};
IRsend irsend;
void setup()
{
for (int i = 0; i < numberOfKeys; i++){
buttonState[i]=true;
lastButtonState[i]=true;
int physicalPin=i + firstKey;
pinMode(physicalPin, INPUT);
digitalWrite(physicalPin, HIGH); // turn on pull-ups
}
Serial.begin(9600);
}
void loop() {
for (int keyNumber=0; keyNumber<numberOfKeys; keyNumber++)
{
int physicalPinToRead=keyNumber+4;
buttonState[keyNumber] = digitalRead(physicalPinToRead);
if (buttonState[keyNumber] != lastButtonState[keyNumber])
{
if (buttonState[keyNumber] == LOW)
{
irsend.sendSony(irKeyCodes[keyNumber], 32);
Serial.println("Sending");
}
lastButtonState[keyNumber] = buttonState[keyNumber];
}
}
}
If anyone could help me change the code so that 12 buttons would send out an individual code that would be also amazing.
The final code is the IR receiver code from the same forum as above
/*
IR_remote_detector sketch
An IR remote receiver is connected to pin 2.
The LED on pin 13 toggles each time a button on the remote is pressed.
*/
#include <IRremote.h> //adds the library code to the sketch
const int irReceiverPin = 2; //pin the receiver is connected to
const int ledPin = 13;
IRrecv irrecv(irReceiverPin); //create an IRrecv object
decode_results decodedSignal; //stores results from IR detector
void setup()
{
pinMode(ledPin, OUTPUT);
irrecv.enableIRIn();
}
boolean lightState = false;
unsigned long last = millis();
// Start the receiver object
//keep track of whether the LED is on
//remember when we last received an IR
void loop()
{
if (irrecv.decode(&decodedSignal) == true) //this is true if a message has been received
{
if (millis() - last > 250) {
//has it been 1/4 sec since last message
lightState = !lightState;
//toggle the LED
digitalWrite(ledPin, lightState);
}
last = millis();
irrecv.resume();
// watch out for another message
}
}
If anyone could help me to change the code so that instead of toggling the LED when receiving and IR signal that it will send a signal to the respective pin when is receives a certain IR code which the other arduino Sent. once again if anyone could do this you are a genius
If all this could be done the final request is to merge the servo code with the IR code so that the servos can be controlled when the respective button is pressed.
Thank you to anyone that can help and I apologize for this massive request.