element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
element14's The Ben Heck Show
  • Challenges & Projects
  • element14 presents
  • element14's The Ben Heck Show
  • More
  • Cancel
element14's The Ben Heck Show
Forum Electronics Question (arduino)
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join element14's The Ben Heck Show to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 19 replies
  • Subscribers 32 subscribers
  • Views 1307 views
  • Users 0 members are here
  • help
  • electronics
  • arduino
Related

Electronics Question (arduino)

ballyrick
ballyrick over 12 years ago

Hey guys.

 

I am making a toy car with speed control, automatic door, steering and lights.

All of these (3 switches & 2 potentiometer) will be controlled by a remote connected via cable. I would like to use either a USB or RJ11 (4-core telephone) cable.

My question is can I combine all the signal cables to reduce the number of wires going from remote to Arduino.

I thought of i2c but not sure if it will work or how to implement it.

 

Thanks.

 

 

FunctionInputOutput
steering:PotentiometerServo
Automatic doorButtonservo
lightsButtonLED's
Speed controlPotentiometerMotor
Motor DirectionSwitchMotor
  • Sign in to reply
  • Cancel

Top Replies

  • timryder
    timryder over 12 years ago +1
    You could always put a small micro controller on the remote control (like an AT-Tiny) and gather the necessary data from each input device and then send down via RS232 (Serial 3 wires) a series of data…
  • ballyrick
    ballyrick over 12 years ago in reply to timryder +1
    Hi Tim. Just a quick question for you, what model At Tiny would you recommend? And what programmer or can i program it via the arduino uno. I have also attached a picture of the circuitry so far. Than…
  • timryder
    timryder over 12 years ago in reply to ballyrick +1
    First, the ATTINY85 is a nice unit with a fair amount of memory and capabilities. Ben uses them a lot in his designs. There are a number of ways to program it but for your project probably using the Uno…
Parents
  • timryder
    timryder over 12 years ago

    Did you buy the ATTINY yet?

    Hopefully not, if you did no biggy you're only out a couple of bucks and you'll use it someday.

     

    However if you look on eBay for "Arduino Mini" there's a small micro controller Arduino with much more I/O and is available for about 5-8 bucks U.S. it would be easier to integrate and has all the I/O you'd need in your controller without having to do some high level programming.

     

    It's a cheap Chinese knockoff but it's fully compatable.

     

    Then the basic idea is to program the mini in the loop to monitor the current values of each input and create either a String or if you're comfortable with it a Byte array where you would add each value from each input. Separate the string values with like a carriage return char so you can parse them later easier. Then after you've built the string send it down to the other Arduino in the car serially and parse through the string applying each value to their respective outputs. 

     

    I'd put a delay of 5-10 ms after that before looping again to ensure the Uno is finished before the buffer is hit again with another packet.

     

    Congrats you've just design and hopefully programmed a protocol.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • timryder
    timryder over 12 years ago

    Did you buy the ATTINY yet?

    Hopefully not, if you did no biggy you're only out a couple of bucks and you'll use it someday.

     

    However if you look on eBay for "Arduino Mini" there's a small micro controller Arduino with much more I/O and is available for about 5-8 bucks U.S. it would be easier to integrate and has all the I/O you'd need in your controller without having to do some high level programming.

     

    It's a cheap Chinese knockoff but it's fully compatable.

     

    Then the basic idea is to program the mini in the loop to monitor the current values of each input and create either a String or if you're comfortable with it a Byte array where you would add each value from each input. Separate the string values with like a carriage return char so you can parse them later easier. Then after you've built the string send it down to the other Arduino in the car serially and parse through the string applying each value to their respective outputs. 

     

    I'd put a delay of 5-10 ms after that before looping again to ensure the Uno is finished before the buffer is hit again with another packet.

     

    Congrats you've just design and hopefully programmed a protocol.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
Children
  • gadget.iom
    gadget.iom over 12 years ago in reply to timryder

    Totally agree with the Arduino Mini, Good shout. image

    You can also use the Arduino Nano, with a built-in USB interface.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • ballyrick
    ballyrick over 12 years ago in reply to timryder

    Thanks Paul, Tim and Douglas.

     

    That sounds like a good idea. I haven't bought the AtTiny yet but i might still get them as they are very useful.

    I'll give a shot at programming the protocol and see how it turns out.

    Also do you think i should use a Arduino Nano in the remote and in the car to reduce space.

     

    All your help is very much appreciated,

    Just another quick question any idea if the 2 servos and motor will work together if all running at same time, as the way i have it now only one servo works at a time and the motor loses considerable speed when a servo is active.

    This might just be a programming error which i will check when i start programming the new program but i would like to get your opinion also.

     

    Kind Regards

    Ricky

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • colecago
    colecago over 12 years ago in reply to ballyrick

    Could be programming, or could be losses on the wire or internal battery resistance.  Try running on a power supply or bigger battery pack to see if the problem goes away.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • ballyrick
    ballyrick over 12 years ago in reply to colecago

    I will try these, thanks

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • timryder
    timryder over 12 years ago in reply to ballyrick

    Post your code.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • ballyrick
    ballyrick over 12 years ago in reply to timryder

    int switchPin = 4; // switch input

    int motor1Pin = 5; // H-bridge leg 1

    int motor2Pin = 6; // H-bridge leg 2

    int speedPin = 11; // H-bridge enable pin

    int ledPin = 13; //LED

    int potPin = 0;

    int speed = 0;

     

     

     

     

    // set pin numbers:

    const int buttonPin = 2;     // the number of the pushbutton pin

    int potpin1 = 1;  // analog pin used to connect the potentiometer

     

     

     

     

     

     

     

    int buttonState = 0;         // variable for reading the pushbutton status

    int val;    // variable to read the value from the analog pin

     

     

    #include <Servo.h>

     

    Servo doorservo;  // create servo object to control a servo

    Servo steeringservo;  // create servo object to control a servo

     

    void setup() {

    // set the switch as an input:

    Serial.begin (9600);

    pinMode(switchPin, INPUT);

     

     

    // set all the other pins you're using as outputs:

    pinMode(motor1Pin, OUTPUT);

    pinMode(motor2Pin, OUTPUT);

    pinMode(speedPin, OUTPUT);

    pinMode(ledPin, OUTPUT);

     

     

    // set speedPin high so that motor can turn on:

    digitalWrite(speedPin, HIGH);

     

     

    // blink the LED 3 times. This should happen only once.

    // if you see the LED blink three times, it means that the module

    // reset itself,. probably because the motor caused a bownout

    // or a short.

    blink(ledPin, 3, 100);

     

     

      // initialize the pushbutton pin as an input:

      pinMode(buttonPin, INPUT);   

      doorservo.attach(10);  // attaches the servo on pin 9 to the servo object

      steeringservo.attach(9);  // attaches the servo on pin 9 to the servo object

    }

     

     

    void loop(){

      // read the state of the pushbutton value:

       buttonState = digitalRead(buttonPin);

     

     

      // check if the pushbutton is pressed.

      // if it is, the buttonState is HIGH:

      if (buttonState == HIGH) {    

        doorservo.write(180);                  // sets the servo position according to the scaled value

         delay(10000);                           // waits for the servo to get there

     

     

      }

      else {

        // send servo home:

          doorservo.write(5);                  // sets the servo position according to the scaled value

          delay(100);                           // waits for the servo to get there

     

      }

     

      val = analogRead(potpin1);            // reads the value of the potentiometer (value between 0 and 1023)

      val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)

      steeringservo.write(val);                  // sets the servo position according to the scaled value

      delay(15);                           // waits for the servo to get there

     

     

     

     

     

    // if the switch is high, motor will turn on one direction:

    if (digitalRead(switchPin) >0) {

    digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low

    digitalWrite(motor2Pin, HIGH); // set leg 2 of the H-bridge high

    speed = analogRead(potPin);

    speed = 793 + (speed/6);

    analogWrite (speedPin, speed);

    Serial.println(speed);

    delay (50);

     

     

    }

    // if the switch is low, motor will turn in the other direction:

    else {

    digitalWrite(motor1Pin, HIGH); // set leg 1 of the H-bridge high

    digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge low

    speed = analogRead(potPin);

    speed = 793 + (speed/6);

    analogWrite (speedPin, speed);

    Serial.println(speed);

    delay (50);

    }

    }

     

     

    /*

    blinks an LED - SIGNIFIES RESET AND ARDUINO SHUTDOWN

    */

    void blink(int whatPin, int howManyTimes, int milliSecs) {

    int i = 0;

    for ( i = 0; i < howManyTimes; i++) {

    digitalWrite(whatPin, HIGH);

    delay(milliSecs/2);

    digitalWrite(whatPin, LOW);

    delay(milliSecs/2);

    }

    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • timryder
    timryder over 12 years ago in reply to ballyrick

    Comment out your Serial.print commands

     

    They're really taxing

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • ballyrick
    ballyrick over 12 years ago in reply to timryder

    Hey.

     

    that makes a big difference with the speed at which everything happens but

    it still didn't solve the problem.

    Its no biggie tho.

     

    I also noticed that when i press the button to open the door, it will not let any other signal through.

    EG: when the door is open, if i change the speed of the motor it will not change until he door (servo) starts to close.

     

    Thanks

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • timryder
    timryder over 11 years ago in reply to ballyrick

    I don't understand why you're delaying the program for 10 seconds after you set the Servo for the door to open?

    Your comment says to make sure the door gets there.  However the servo itself has small circuitry which will ensure that the servo gets to the position you tell it to go via a digital or analog feedback signal internally.  So you don't need to do this.

    Your program is just going to hang there until its done which delays any more execution.  The PWM signal being generated by the Arduino won't change until you re-write a new value into that pin so it's pretty much guaranteed to get there.

     

    Whats the significance of this line:

    speed = analogRead(potPin);
    speed = 793 + (speed/6);

     

    Why the math on it? Perhaps you can do something else hardware wise like a scaled voltage divider circuit?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • ballyrick
    ballyrick over 11 years ago in reply to timryder

    Hi Tim.

     

    Thanks very much for the help.

    I got rid of all the lines that had the servo delay. This made a huge difference to the running of the servo. They now run much smoother and don't jump around then stopped.

    The 10 second delay for the door is because i have one button that opens the door and then 10 sec later it closes automatically.

     

    I am not 100% sure what you mean by a scaled voltage divider.

    Do you mean put 4 resistors of different values and then send the voltage to the one i want to use?

     

    Thanks

    Ricky

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube