# Arduino sketch combine

**URL:** <https://forum.arduino.cc/t/arduino-sketch-combine/623361>\
**Category:** Programming\
**Created:** [November 29, 2019, 1:46pm UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361 "2019-11-29T13:46:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon61883611](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@anon61883611](https://forum.arduino.cc/u/anon61883611)\
**Post date:** [November 29, 2019, 1:46pm UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361/1 "2019-11-29T13:46:03Z")

</div>

Can anyone help me to combine these to sketch. Iam trying to make a smartphone controlled car with robotics arm. Iam using 3 servo motor, 1 hc-05, 2 gear motor, 1 l298n motor driver and a arduino nano.

[bluetooth\_servo\_control\_multi\_servo\_ino.ino](https://forum.arduino.cc/uploads/short-url/ffnZVEHOFvmvN00SOPNRkBxx37E.ino) (3.39 KB)

[code\_for\_arduino\_blootooth\_controlled\_rc\_car.ino](https://forum.arduino.cc/uploads/short-url/3efHPfi28zPiC6soCX1yIgMxgjR.ino) (1.2 KB)

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [November 29, 2019, 1:59pm UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361/2 "2019-11-29T13:59:15Z")

</div>

Have you tried to combine them yourself ?

---

<div class="post-metadata">

**Author:** ![anon61883611](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@anon61883611](https://forum.arduino.cc/u/anon61883611)\
**Post date:** [November 29, 2019, 2:09pm UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361/3 "2019-11-29T14:09:32Z")

</div>

> UKHeliBob:  
> Have you tried to combine them yourself ?

I don't know how to do it can you please do it for me?

---

<div class="post-metadata">

**Author:** ![lesept](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/lesept/32/238959_2.png) [@lesept](https://forum.arduino.cc/u/lesept)\
**Post date:** [November 29, 2019, 2:24pm UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361/4 "2019-11-29T14:24:29Z")

</div>

You should first Google 'combine arduino sketches', this will give you some hints.

If you are (very) lucky, meaning if your sketches are not too complex or can run independently, it will be straightforward:

- put all the lines before each setups of your 2 codes in a new blank ino file, remove any redondance
- combine the content of both setups (discard any redondant lines)
- create 2 new functions called loop1 and loop2 (for example) and copy the contents of your loops in these functions
- write a new loop as follows  
`void loop() { loop1(); loop2(); }`

But there are chances that this will not work as you want, because of possible delays or interactions between your 2 codes. Then you'll have to merge the 2 loops in only one, and this will require to think more than what I told you above...

---

<div class="post-metadata">

**Author:** ![anon61883611](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@anon61883611](https://forum.arduino.cc/u/anon61883611)\
**Post date:** [November 29, 2019, 2:49pm UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361/5 "2019-11-29T14:49:51Z")

</div>

> lesept:  
> You should first Google 'combine arduino sketches', this will give you some hints.
> 
> If you are (very) lucky, meaning if your sketches are not too complex or can run independently, it will be straightforward:
> 
> - put all the lines before each setups of your 2 codes in a new blank ino file, remove any redondance
> - combine the content of both setups (discard any redondant lines)
> - create 2 new functions called loop1 and loop2 (for example) and copy the contents of your loops in these functions
> - write a new loop as follows  
> `void loop() { loop1(); loop2(); }`
> 
> But there are chances that this will not work as you want, because of possible delays or interactions between your 2 codes. Then you'll have to merge the 2 loops in only one, and this will require to think more than what I told you above...

Can you please do it for me. Iam nooby in programming. Iam making this project for my school exhibition

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [November 29, 2019, 2:54pm UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361/6 "2019-11-29T14:54:16Z")

</div>

> Iam making this project for my school exhibition

You mean that you want someone else to make this project for your school exhibition

You will never progress beyond being a "nooby" unless you try things for yourself

---

<div class="post-metadata">

**Author:** ![anon61883611](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@anon61883611](https://forum.arduino.cc/u/anon61883611)\
**Post date:** [November 29, 2019, 3:08pm UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361/7 "2019-11-29T15:08:50Z")

</div>

> UKHeliBob:  
> You mean that you want someone else to make this project for your school exhibition
> 
> You will never progress beyond being a "nooby" unless you try things for yourself

Please

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [November 29, 2019, 3:21pm UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361/8 "2019-11-29T15:21:04Z")

</div>

I will gladly provide help with a program that you write but I am not going to do it for you

Apart from your pride is there anything riding on the program working ?

---

<div class="post-metadata">

**Author:** ![lesept](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/lesept/32/238959_2.png) [@lesept](https://forum.arduino.cc/u/lesept)\
**Post date:** [November 29, 2019, 3:43pm UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361/9 "2019-11-29T15:43:26Z")

</div>

I can't do it for you, like Bob says you must do the first steps by yourself.  
Reading your files, it appears that you are almost licky. The 2 codes should merge quite easily, except for 2 things:

- you use the pins 9 to 11 in both codes for differents things,
- and the processing of the commands from the serial link has to be re written to be compatible of both needs.

---

<div class="post-metadata">

**Author:** ![Deva\_Rishi](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/deva_rishi/32/227254_2.png) [@Deva\_Rishi](https://forum.arduino.cc/u/Deva_Rishi)\
**Post date:** [November 29, 2019, 7:57pm UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361/10 "2019-11-29T19:57:25Z")

</div>

> Can you please do it for me. Iam nooby in programming. Iam making this project for my school exhibition

Do your own homework, please, make an attempt, see how far you get ask specific question about specific parts, try and compile, post errors & sketch within \</\> code-tags please...

---

<div class="post-metadata">

**Author:** ![dougp](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dougp/32/238908_2.png) [@dougp](https://forum.arduino.cc/u/dougp)\
**Post date:** [November 29, 2019, 10:41pm UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361/11 "2019-11-29T22:41:10Z")

</div>

There's a [tutorial](http://www.thebox.myzen.co.uk/Tutorial/Merging_Code.html) for that.

---

<div class="post-metadata">

**Author:** ![anon61883611](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@anon61883611](https://forum.arduino.cc/u/anon61883611)\
**Post date:** [November 30, 2019, 9:26am UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361/12 "2019-11-30T09:26:22Z")

</div>

> lesept:  
> I can't do it for you, like Bob says you must do the first steps by yourself.  
> Reading your files, it appears that you are almost licky. The 2 codes should merge quite easily, except for 2 things:
> 
> - you use the pins 9 to 11 in both codes for differents things,
> - and the processing of the commands from the serial link has to be re written to be compatible of both needs.

I tried little bit then how to combine two serial available. One is for servo control via Bluetooth and another is dc motor control via Bluetooth using l298n

---

<div class="post-metadata">

**Author:** ![anon73444976](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon73444976](https://forum.arduino.cc/u/anon73444976)\
**Post date:** [November 30, 2019, 9:27am UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361/13 "2019-11-30T09:27:11Z")

</div>

> Hari220903:  
> I tried little bit then how to combine two serial available. One is for servo control via Bluetooth and another is dc motor control via Bluetooth using l298n

...and?

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [November 30, 2019, 9:35am UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361/14 "2019-11-30T09:35:15Z")

</div>

> how to combine two serial available

It sounds like you need 2 serial interfaces

Take a look at the SoftwareSerial library

---

<div class="post-metadata">

**Author:** ![slipstick](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@slipstick](https://forum.arduino.cc/u/slipstick)\
**Post date:** [November 30, 2019, 9:36am UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361/15 "2019-11-30T09:36:30Z")

</div>

> Hari220903:  
> I tried little bit then how to combine two serial available. One is for servo control via Bluetooth and another is dc motor control via Bluetooth using l298n

So first show us your attempt to combine the two sketches and explain what works and what doesn't.

If you are using a single smartphone app to control the servos and the DC motors then you are only using one Bluetooth connection so what's the problem? If you are not using one smartphone app then tell us what exactly you are using.

Steve

---

<div class="post-metadata">

**Author:** ![anon61883611](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@anon61883611](https://forum.arduino.cc/u/anon61883611)\
**Post date:** [November 30, 2019, 12:25pm UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361/16 "2019-11-30T12:25:04Z")

</div>

I choose two projects from the internet. I need to combine those. The idea was to control a car and robotic arm using smartphone. there are two separate codes. I need to combine those codes.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [November 30, 2019, 12:39pm UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361/17 "2019-11-30T12:39:05Z")

</div>

> Hari220903:  
> I choose two projects from the internet. I need to combine those.

We get that. But this:

> slipstick:  
> If you are not using one smartphone app then tell us what exactly you are using.

... specifically asks about the BT app or apps sending the controls in.

---

<div class="post-metadata">

**Author:** ![slipstick](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@slipstick](https://forum.arduino.cc/u/slipstick)\
**Post date:** [November 30, 2019, 4:12pm UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361/18 "2019-11-30T16:12:09Z")

</div>

The problem with just taking code from the Internet is that you probably have no idea how it works. That can make it you difficult to combine the sketches. But YOU are the only one who wants the sketches combined so YOU have to put some effort in yourself.

As I said before, if you make an attempt at combining the sketches and post it here we'll help you to get it working. You'll also need to answer the questions you're asked. Just ignoring people's questions will not encourage them to help you.

But if you just want someone else to do all the work then try posting in Gigs and Collaborations but you'll probably need to pay someone to do the work for you.

Steve

---

<div class="post-metadata">

**Author:** ![anon61883611](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@anon61883611](https://forum.arduino.cc/u/anon61883611)\
**Post date:** [December 1, 2019, 3:10pm UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361/19 "2019-12-01T15:10:16Z")

</div>

> slipstick:  
> The problem with just taking code from the Internet is that you probably have no idea how it works. That can make it you difficult to combine the sketches. But YOU are the only one who wants the sketches combined so YOU have to put some effort in yourself.
> 
> As I said before, if you make an attempt at combining the sketches and post it here we'll help you to get it working. You'll also need to answer the questions you're asked. Just ignoring people's questions will not encourage them to help you.
> 
> But if you just want someone else to do all the work then try posting in Gigs and Collaborations but you'll probably need to pay someone to do the work for you.
> 
> Steve

I did it. It works. Thank you so much for the help. Now I need to slow down the dc motor.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 12:09am UTC](https://forum.arduino.cc/t/arduino-sketch-combine/623361/20 "2021-05-06T00:09:44Z")

</div>

Closed on May 6, 2021, 12:09am UTC


