# programming

**URL:** <https://forum.arduino.cc/t/programming/222054>\
**Category:** Programming\
**Created:** [March 24, 2014, 3:46pm UTC](https://forum.arduino.cc/t/programming/222054 "2014-03-24T15:46:25Z")\
**Posts on this page:** 10\
**Page:** 1

<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:** [March 24, 2014, 3:46pm UTC](https://forum.arduino.cc/t/programming/222054/1 "2014-03-24T15:46:25Z")

</div>

hello im new in this area. i want to ask if someone can guide me code for the arduino to correlated with servo motor but depends on LM34 (temperature sensor). deepest thanks. here i attach the picture of my group project.

![uhev6aSv5IIxOA5w.jpg](https://europe1.discourse-cdn.com/arduino/original/4X/3/9/e/39e24e10e40ddb25761c499de83ecbd8744cde55.jpeg)

---

<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:** [March 24, 2014, 4:55pm UTC](https://forum.arduino.cc/t/programming/222054/2 "2014-03-24T16:55:05Z")

</div>

Do you have code for the servo motors (using the Servo library) ?  
Do you have code for the LM34 ?

The Arduino 5V pin is a 5V output. It can supply perhaps 100 to 300mA.  
A single servo motor needs 500mA when it starts rotating, but it might even be 1A.  
You have to use a seperate powers supply to power the servo motors.

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [March 24, 2014, 4:58pm UTC](https://forum.arduino.cc/t/programming/222054/3 "2014-03-24T16:58:21Z")

</div>

Sure, but before you start your project, google, LM34 Arduino, and servo Arduino.  
Many examples on the WEB.  
Go thru the basic examples that come with the IDE to get some experience in programming.

---

<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:** [March 24, 2014, 7:11pm UTC](https://forum.arduino.cc/t/programming/222054/4 "2014-03-24T19:11:01Z")

</div>

hi afryan\_!

perhaps you should have a look on the servo-library:

> **[Servo - Arduino Reference](https://www.arduino.cc/reference/en/libraries/servo/)**
>
> The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.

pay attention: here you can read:  
" Note that servos draw considerable power, so if you need to drive more than one or two, you'll probably need to power them from a separate supply (i.e. not the +5V pin on your Arduino). Be sure to connect the grounds of the Arduino and external power supply together."

if you are not sure how to do that, you can ask again and i try to send you a schematic curcuit diagram...

---

<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:** [March 25, 2014, 2:55pm UTC](https://forum.arduino.cc/t/programming/222054/5 "2014-03-25T14:55:51Z")

</div>

thnx guys for helping me. GBU!

---

<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:** [March 25, 2014, 3:44pm UTC](https://forum.arduino.cc/t/programming/222054/6 "2014-03-25T15:44:06Z")

</div>

caltoa: i dont have the code for servo and LM34. if you have the source please tell me. thank you.

---

<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:** [March 25, 2014, 7:23pm UTC](https://forum.arduino.cc/t/programming/222054/7 "2014-03-25T19:23:19Z")

</div>

The link I gave is to the Servo library.

> **[Servo - Arduino Reference](https://www.arduino.cc/reference/en/libraries/servo/)**
>
> The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.

On the right side of that page, you see two examples.

The LM34 is connected to the 5V and GND, the middle pin to perhaps A0.  
[http://learn.parallax.com/lm34-temperature-sensor-arduino-demo](http://learn.parallax.com/lm34-temperature-sensor-arduino-demo)

Don't start to write the final sketch. Make a sketch to test the servo motors. And another sketch to try the LM34.

---

<div class="post-metadata">

**Author:** ![GoForSmoke](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/goforsmoke/32/1127097_2.png) [@GoForSmoke](https://forum.arduino.cc/u/GoForSmoke)\
**Post date:** [March 25, 2014, 8:32pm UTC](https://forum.arduino.cc/t/programming/222054/8 "2014-03-25T20:32:47Z")

</div>

You shouldn't pull more than 200 mA of 5V through an UNO, and while the per pin max is 40 mA @ 5V it is better to stick to 20 mA or less. The less current you pull through the board, the better.

# Links to often referred to pages on the Arduino site:

Products with many specs on each: [http://arduino.cc/en/Main/Products](http://arduino.cc/en/Main/Products)  
Foundations, for beginners: [http://arduino.cc/en/Tutorial/Foundations](http://arduino.cc/en/Tutorial/Foundations)  
Hacking, for once you've got your stride: [http://arduino.cc/en/Hacking/HomePage](http://arduino.cc/en/Hacking/HomePage)  
The command reference: [Arduino - Home](http://arduino.cc/en/Reference/HomePage)  
The underlying C/C++ libraries: [avr-libc: Modules](http://www.nongnu.org/avr-libc/user-manual/modules.html)  
The official libraries: [http://arduino.cc/en/Reference/Libraries](http://arduino.cc/en/Reference/Libraries)  
The official Examples, more about those below: [http://arduino.cc/en/Hacking/HomePage](http://arduino.cc/en/Hacking/HomePage)  
The Playground, user contributed: [http://playground.arduino.cc/](http://playground.arduino.cc/)  
The Playground, libraries : [Arduino Playground - HomePage](http://playground.arduino.cc/Main/GeneralCodeLibrary#.UzHkwx4z3jI)

The Example sketches versions that match your IDE come with your IDE. You load them through the File menu.  
They are not perfect (like the Playground, it varies) and some teach bad habits (using C++ Strings and like).  
Still sections 1, 2, 3 and 5 are mainly all lessons that every Arduino programmer should know about, even with the occasional minor error they run as needed.

If you have code that reads a sensor and other code that moves a motor then don't mix them together. If the sensor picks up a trigger then have that code set a variable that the motor code uses as a signal to run. Do not put the motor code right into the sensor code since  
A) it makes the whole harder to debug.  
B) it makes the whole harder to change.  
C) it makes adding motor triggers harder to do and require more code than setting that variable.  
D) it makes the whole harder to read when you do ask for help.

Try to keep the parts that do one thing in one place separated from the rest and pass signals/values between parts. Use the fact that loop() runs when loop() ends to drive your code by events rather than a fixed top-down sequence (what they teach in intro and intermediate PC programming) that's supposed to do everything in one pass. The top-down approach should come with a jar of sauce for all the times it leads to spaghetti.

---

<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:** [March 26, 2014, 10:28am UTC](https://forum.arduino.cc/t/programming/222054/9 "2014-03-26T10:28:42Z")

</div>

thnx for your help guys. really appreciate it!

---

<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 5, 2021, 8:36pm UTC](https://forum.arduino.cc/t/programming/222054/10 "2021-05-05T20:36:17Z")

</div>

Closed on May 5, 2021, 8:36pm UTC


