How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask Scott Your Own Question

Scott, MIT Graduate
Category: Homework
Satisfied Customers: 3040
Experience:  MIT Graduate (Math, Programming, Science, and Music)
Type Your Homework Question Here...
Scott is online now
A new question is answered every 9 seconds

I need some help with my arduino code. i am currently

Customer Question

Hello, i need some help with my arduino code. i am currently building a model elcetric go kart as part of my school engineering practical. it consists of a dc motor a servo motor controlled with a double axis ps2 thumbstick (potentiometer). the code i have so far is working and shown below:#include
#include "utility/Adafruit_MS_PWMServoDriver.h"
#include// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
// You can also make another motor on port M2
//Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);Servo myservo; // create servo object to control a servoint potPinServo = 0;int potPinDrive = 1;int val; // variable to read the value from the analog pinvoid setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Adafruit Motorshield v2 - DC Motor test!");
AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz// Set the speed to start, from 0 (off) to 255 (max speed)
// turn on motor
}void loop() {
// read value of joystich axis
int potVal = analogRead(potPinDrive);val = analogRead(potPinServo); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(50); // waits for the servo to get thereif(potVal > 512)
myMotor->setSpeed (potVal);
}else if(potVal < 500)
}i would like to use this code but split it apart from inputs and outputs onto two seperate arduino uno boards and connect them wirelessy using one way radio frequency link modules.can this be done if so who can help me achieve this.i have links below for the thubstick and link modules
Submitted: 5 months ago.
Category: Homework
Expert:  swmcdonnell replied 5 months ago.
Hi there, my name is***** thought I responded to this yesterday, but my response doesn't appear so I'll try again.I can help you split the sketch and put in the wireless link between the two boards. I'm assuming it's because you want a handheld controller separate from the go-kart, and not for performance reasons, because you might see lower performance after you separate them due to the delay from the wireless communication.It looks like you decided on the 315MHz transmitter/receiver. I've done something similar with a 433Mhz transmitter/receiver, which is essentially identical. They are really cheap and pretty reliable. There are also other solutions that are more reliable but more expensive, like Zigbee, Wi-Fi or Bluetooth.Take a look at the library called RCSwitch . It will handle the wireless communication between the two boards, and it's pretty straight forward. If you still need help with this, please let me know and I can give you an estimate to help you get it working. Please let me know if you want me to write the sketches for you, or just to give you instructions on what should be where and how to connect them.
Customer: replied 5 months ago.
when you say "ecause you might see lower performance after you separate them due to the delay from the wireless communication." is the differenece very signifigant or is it very slow.can this be fixed by send multiple signals??i do still need help im an absolute beginner and really dont know what im doing, any chance you could write the sketch up for me also what should the circuit look like?my rf links might be 433hz but im not too sure
Expert:  swmcdonnell replied 5 months ago.
I think you'll be OK on the performance, I was just making sure you weren't doing it for performance reasons. I'll send you an offer to give you the wiring diagrams and the sketches for each Uno for your kart. I attached a sample to this message. But there are a few things I need to know:1) How are you steering the kart? Is that what the Servo is doing? You need to tell me more about how that is set up with the motors.2) I would assume that Joystick up (max) is 255 forward, down (max) is 255 backward and the rest scales from 0-255.3) I would assume that Joystick left (max) and right (max) are 180 and the rest scales for the servo (if I have that right).4) When you push the button on the joystick, what should it do (if anything)?If you accept my offer, I can start right away. If you don't accept it, I'll opt out and you can see if another expert can help you.
Expert:  swmcdonnell replied 5 months ago.
Here's the sample diagram for the joystick.
Customer: replied 5 months ago.
sorry i do not have the money for that and if i was to pay for your services i would need more of a sample than just the wiring diagram
Expert:  swmcdonnell replied 5 months ago.
OK, well I'll give you some pointers then, hopefully this will help you out:1) Watch this video. That's how you connect the joystick and read the values.2) If y-axis is speed, you need to convert (map) it to -255 to 255:0 -- all the way up524 -- in the middle1023 -- all the way down3) If x-axis is direction, you need to convert (map) it to -255 to 255, or however your servo is controlling direction:left center right0 524 10234) Use the RCSwitch library to send the commands to the other Uno.5) On the other Uno, wire up the RF receiver and use the RCSwitch library to listen and get messages.6) Take the input you sent and use it to control the motor speed and direction.I hope this helps. Sorry, but it would take some time to write the sketches for you and draw the diagrams, and they only pay me $12 for this question. If this helps and you would accept my answer, I would appreciate it.
Customer: replied 5 months ago.
i have all the components set up but how do io split the code i alrady have and join it with the rc witch code?

Related Homework Questions