text:
How do I lock a servo motor?
I am working on a robot which uses Ackermann's steering principle. Now the steering principal itself is in the development stage and the first prototype is pretty much good except for the fact that it can get turned very easily.
So I was hoping to find a way to lock the servo operating the steering mechanism so that it only rotates when the servo does. Any way to do that??
I'm using a UNO.
Thanks!

Did you call servo.detach()? Servo's should usually hold their position when attached. This is because of the way how servo's work. They've got an internal feedback loop, which constantly adjusts the servo towards it's setpoint (if it's a bit off).

@Paul no I didn't

What type of servo do you have?

@Paul simple rc servo, Turnigy MX - 3505

It might not get enough current to hold it into position? If you touch it, would it jump back to it's position when you release it?

No it just moves with my steering mechanism as if moved by external force. I am giving it 5V 3 Amps through a UBEC and raw power from 2 ICR 16850 batteries, totalling somewhere near 8.5 V

Hobby servos are typically susceptible to backdriving when unpowered, and possibly also if they are powered but have no signal.  Counteracting backdriving would require that the internal control loop function, but a traditional analog implementation would have no memory of what the last commanded position was.  An MCU based servo could have such a memory, but its not clear it would be programmed to.  Make sure you are continuing to send pulses to the servo and do not subject it to torque above its rating.  This may turn out to be a mechanical design problem not an Arduino one.

It's Ackermann and principle.
What do you mean by "find a way to lock the servo operating the steering mechanism so that it only rotates when the servo does"? When what rotates?

@JayEye thanks for pointing that out. My design is just of wood and rotate s easily with any external force. I will control the rotation from my servo. So I want that my servo only moves when the Arduino tells it do so, otherwise stay "locked" in the centre position,

@ChrisStratton well that's most probably a mechanical problem, I can just counteract it by locking my servo.

Hobby servos do not offer "locking" as a feature.

This seems to be a question about servos rather than Arduinos, so I'm going to close it.

A normale servo will stay in position when:

It's powered up (with enough current)
You are feeding the control signal into it.

And

It's rated for the amount of force applied.

Based on your comments, it seems that it's not a regular servo or could be faulty.
I couldn't find the datasheet for your servo, so I can't tell if it's normal behavior, though it seems unlikely. (Servo's aren't made to bounce around)
Edit:
It doesn't really make sense that it could be easily rotated by touching it, that would also mean that it can't lift anything? I would suggest trying another servo.

authors: Зориг Өлзийжаргал


text:
Avoid the 10 attempts of Avrdude when programmer is not responding
Sometime I update my sketch in the Arduino environment, and when I click on the transfer arrow but forget to plug my arduino (I'm using the UART in my project so every time I need to plug/unplug some wires) it's a drama, avrdude throw this for at least 2 minutes :

avrdude: stk500_recv(): programmer is not responding
  avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x32

It's a real pain because I can't stop avrdude when this happens.
Is there a way to configure the Arduino environment to disable it?

Good question, I thought it would be an easy fix, but couldn't find anything in the AVRDude command line options (http://www.nongnu.org/avrdude/user-manual/avrdude_4.html) or the avrdude config files.

On Linux I just open a terminal and type killall avrdude and it stops it...

I didn't thought about this, good work around.

Also I use UECIDE rather than the Arduino IDE because I especially programmed a "stop" button in to get around this very problem.

Unfortunately, MAX_SYNC_ATTEMPTS is a constant in the source code, and one which appears several times.
avrdude is an open source project, so customizing and building it should be relatively straightforward.  Since it is a numeric rather than string value, and is checked in several places, simply modifying the binary is likely to be tricky.
One can of course manually kill the process, though it is annoying to have to.
Another approach could be to write a wrapper which might potentially do some sanity checking first (does any other process have the port open?) and then would launch avrdude as its child, passing through all the arguments.  By monitoring the output before passing it on, it should be possible to detect this message and terminate the avrdude instance automatically.

I had the same question and found following solution in linux: write a script,
#!/bin/bash
avrdude=`ps -C avrdude | tail -n 1 | head -c 7`
kill $avrdude

store it and connect it with a shortcut

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Peristaltic Pump Project
I am designing a peristaltic pump and need some advice for parts. I am using an Arduino Leonardo and also have an UNO and am planning on adding a temperature and pH sensor as well. I have two questions:
1) I am planning to use a Stepper Motor but am unsure if I should use the NEMA 17 or 23 or some other motor. I need a relatively "high" amount of torque maybe around 1 to 3 N-m.
2) Should I go with a Motor Shield or Motor Driver. I am currently looking at the Big Easy Driver or A4988 Bipolar Driver or the simple Arduino Motor Shield.
Does anyone know which of these would be best or have any suggestions? Thank you very much!

A lot of people like the Pololu stepper motor drivers. Especially in the DIY 3D printer scene. They are probably cheaper than an entire shield.

The specifications for each stepper motor varies, with the larger models having the greater torque. With great torque comes the requirement of great power. A quick search for nema 17 stepper motors finds the torque figures on the low side of your request, while the nema 23 motors display a greater range, including your figures.
The additional power requirements may exceed the capabilities of the Arduino Motor Shield (2a per channel, 4a max), while the A4988 board specifies up to 2a per coil. Also note that to achieve the use of the higher power levels, these boards will require heat sinks.
If you expect to require the higher figure for torque, consider to research for a driver board that has a greater power limit, "just in case".

Rule of thumb: work out your power requirement, double it, then add a bit :) You can never have too much headroom.

"NEMA 17"  etc. only designates the mechanical mounting specification, not the strength or other electrical specifications of the motor.

Thanks a bunch. I think I will go with a driver board like you said just to be safe.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Is the C++ STL fully supported on Arduino?
I don't yet own an Arduino board to run code on, and as the title says, I'm curious if the C++ STL is fully supported on Arduino and already part of the Arduino IDE. The STL is probably the most efficient, fully tested, and resource-minimal (which is a slightly redundant phrase, as I already mentioned efficiency) publicly available C++ code out there, and would make life much easier to code for Arduino.
If the STL is not a part of Arduino IDE, then how to include specific libraries such as <algorithm> and <utility>? (I'm very tempted to ask "why isn't it included?" but that seems too broad.)

The problem with "efficient" is that it doesn't specify just how efficient it is; will it run well on a 16MHz device with only 2kiB of RAM?

and already part of the Arduino IDE - last time I looked it wasn't. Personally I like the STL, and think it should be included. Whether or not you can tolerate the overhead is surely a decision for the end-user? I installed the Maniacbug library fairly recently, and it seemed to work OK.

The STL is not a part of Arduino IDE.
Although efficient by desktop standards, the consensus is it doesn't fit comfortably in an Arduino's limited space.  That said, here's someone who seems to have done it:
https://github.com/maniacbug/StandardCplusplus
Check out the forks, they seem more up to date

I'm against this consensus :p so it's not really a consensus anymore? ;p it should be used wisely, but can be very powerfull/usefull. Not everything of it may work as well. But we used std::queue to create a message-queue which the Arduino would clear. In theory it could get overrun, but it's usually more space efficient as setting an fixed buffer. Because one needs to set the buffer big enough, but will end up always "using" the full memory of the buffer.

@Paul Could you please explain why you have a different perspective? I'm sure it's interesting/educational.

@Paul do you use the maniacbug version or a different flavor?  Please share.  STL looks interesting to me but its slight lean towards dynamic allocation and rtti shied many (including myself) from using it for AVR scenarios

I've edited my reply, basically making a fixed buffer for your storage is less space efficiënt as using a dynamic storage. You'll only get in trouble when you run out of memory though, and since dynamic, can be hard to predict. But in general should fail later.

It was actually in my seconden year, we used the GNU-GCC toolchain with, I believe AVR-GCC, avrdude and eclipse. But I don't know how we got stl, it seemed easy at that time

A thread with some other STL options & thoughts: https://forum.arduino.cc/index.php?topic=360116.0

I lost the toolchain, since I got a new laptop. Which I pity very badly, but I do have the code from that project. I'll check with some classmates, if they can find the document for setting up GCC for AVR with STL

But, I think it's worth trying, especially with the newer microcontrollers, with more ram. If you try it, it may actually work very well.

Even with limited RAM, if you try writing your own linked-list you may well find that you don't do a better job than the STL does.

Years later, but I'd like to point out compelling alternatives: etl (https://github.com/ETLCPP/etl) and my own estdlib (https://github.com/malachi-iot/estdlib)

STL is efficient on the platform it was designed for, which is personal computers and similar-scale devices, where allocating a single byte in the heap consumes a 4k memory page (that's several times as much as ALL Arduino RAM), and where array indexes can be efficiently replaced by pointers (8-bit microcontrollers need at least two commands to deal with a pointer). So no, it's not efficient with Arduino.
Think of quicksort algorithm - it performs very well on large lists, but is easily beaten by a simple sort if you need to sort an array of 5 elements. Being asymptotically efficient doesn't mean being efficient in every case.

Unless the library is re-written for AVR. In theory it will be better/more efficient as me trying to program a queue or priority queue in C. If you really need the behavior, you should atleast consider or try it.

I would personally use an AVR port of C++ STL which is on GitHub, and bother the people on GitHub if you've got a better implementation, this way we can make it work, instead of everyone choosing to create his own implementation ;) And since it's on GitHub (and may even have multiple contributors) and is aimed on AVR. It should perform reasonable and be reviewed by multiple. Which is probably better/faster as some self written code. But I agree on the part: "use with care". But not "don't use because the PC version will be no good.".

@Paul If STL were to be rewritten for AVR, it would automatically lose it's "fully tested / mature" status, wouldn't it?

Well, if you were to implement it yourself, it would automatically lose it's fully tested status aswell :p and if you collaborate on github, it's more fully tested as when you're doing it alone? (:

Plus, on stl being fully tested; yes it is, for PC. (:

The STL is not a part of Arduino IDE.
Another answer is mentioning https://github.com/maniacbug/StandardCplusplus although this library doesn't seem to be maintained anymore.
Maybe a better idea could be to try https://github.com/mike-matera/ArduinoSTL
It's a port of uClibc++ packaged as an Arduino library.

I've been using Mike Matara's Arduino STL and it has been working fine on my AVR based boards. However I just entered the ESP8266 world and no fun ... plenty of compile errors with a warning that says it's "compatible with AVR and SAMD but may be incompatible with ESP8266" Doh!.

The STL is not part of Arduino and no support for libstc++ from AVR.
My "answer" differences from Malachi at one point though, as explained in the comments.
I don't think you shouldn't, just because "most people say" that you shouldn't. There are a lot of people that even think you shouldn't use C++ at all.
The problem is that C++ (and C++ standard library) are very powerful and may be ported in a non-efficient way.

Why use libstdc++?
I think, however, that if you use it with care, it can be very usefull.
Let's say we've got two buffers, a send buffer and a receive buffer.
With C, you would store them in a fixed char array. In C++ you can use dynamic containers.
So in C, you'll use 2x 256 bytes of memory to save your messages. Any longer message won't fit.
In C++ you'll use only whatever bytes are needed at one point (plus some extra probably). And if you get a longer message, it will simply scale up.
If the C++ thing works for you, and just test it very very well, why not use it? On average, it will use less memory, since you don't assign all of it when it's not used. You will have a problem when your messages get too big, since your memory will overflow, often causing the microcontroller to reset. But if more buffers in your program are dynamic, one may leave some space for the other, etc. Effectively using the memory more efficient!
But, without dynamic allocation, it might be a little safer, since you've already claimed those pieces of memory, there is no way you can't use those pieces. Any message that is bigger, simply won't fit, but you can easily check on that. Another thing is that the C++ stl's you find, might not be as well optimalised for your architecture/microcontroller.
Also, creating your very own dynamic storage in C may cause even more problems than the C++ stl ;). And it's not like you have to use dynamic storage for everything, simply being able to do so is nice.

Current microcontrollers are also getting much more serious as the 8-bit Arduino's (328P). 20$ can get you a Teensy 3.2 which has 256K Flash Memory, 64K RAM so, in this case, dynamic memory can be very useful (if you are certain you always have enough memory left).
Also: All STM32F41xxx products embed: Up to 192 Kbytes of system SRAM including 64 Kbytes of CCM (core coupled memory) data RAM
By that, it can also be a very nice way to learn C++ and program in the same language as you do on the PC.
But keep in mind that on an 8-bit micro, you should check if your stl-functions don't give too much overhead.

How use C++ standard template library for AVR?
I've followed the blog from Andy Brown and now have iterators/string/vectors working in AtmelStudio.
Though I did get some errors, the first batch of errors included:
Error        '_M_deallocate' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]      D:\avr-stl\include\string    173
Message        declarations in dependent base 'std::_String_alloc_base<char, std::allocator<char>, true>' are not found by unqualified lookup        D:\avr-stl\include\string    173
Message        use 'this->_M_deallocate' instead     D:\avr-stl\include\string    173

This error actually explains itself; you should use this->_M_deallocate.
After that I got undefined reference to "operator new(unsigned int, void*). But I fixed it by including "pnew.cpp" right under #include <new>  in stl_construct.h which is weird, but it works.
(Piece of stl_construct.h)
#ifndef __SGI_STL_INTERNAL_CONSTRUCT_H
#define __SGI_STL_INTERNAL_CONSTRUCT_H

#include <new>
#include <pnew.cpp>

__STL_BEGIN_NAMESPACE

After checking some stuff on the internet, it indeed appears that static allocation is most often better than dynamic allocation. Since the problems (possible overflows, less control and heap fragmentation) are unlikely to weigh up against the benefits. BUT, that doesn't mean everyone should stop experimenting with it ;) and nor that it can't be usefull in some niche applications (thus it's not a bad thing to have it "installed").

Tough crowd, I don't think you deserve a negative for your answer!  Heap fragmentation is one of the main things that steer me away from dynamic memory on AVR.  However, on bigger chips I'm a fan - when used carefully.


text:
How do I stop the Arduino TX/RX LEDs from flashing? How do I turn off the "ON" LED?
I actually have a SparkFun RedBoard, but I think this question applies to Arduino Uno and other boards as well.
I'm wondering how much control the programmer has over the various LEDs on the board. First there's the "ON" LED which is very bright. Can this be turned off or dimmed, or do I need to resort to electrical tape?
More annoying is the "TX" and "RX" LEDs. These blink rapidly when data is being communicated over the USB-serial connection. I'm guessing these are not configurable, but I couldn't find the answer anywhere online.
I know that the "Pin 13 LED" can be controlled (via Pin 13!).

I'm wondering how much control the programmer has over the various LEDs on the board. First there's the "ON" LED which is very bright. Can this be turned off or dimmed, or do I need to resort to electrical tape?

Remove it, remove the resistor inline with it, or cut the track powering it. Either that or resort to electrical tape (or blu-tack). You have absolutely no control over it.

More annoying is the "TX" and "RX" LEDs. These blink rapidly when data is being communicated over the USB-serial connection. I'm guessing these are not configurable, but I couldn't find the answer anywhere online.

If your board uses an ATMega16U2
As above, or compile a custom version of the ATMega16U2 firmware and flash it on to the ATMega16U2 chip.
If your board uses an FT232 chip
Download the FT232 EEPROM editing program from FTDI and use that to reconfigure the IO pins the LEDs are attached to so they do nothing. If you are on Linux you can use libftdi's ftdi_eeprom program.

According to Sparkfun the board does use an FT232


text:
Problems running several Arduinos off of one HC-05 Tx pin
TL;DR: Multiple Arduinos listening to a single serial rail are burning out my HC-05's TX pin. Arduinos are leaking voltage onto the signal rail. How do I stop, or isolate that to keep from burning out Bluetooth TX pin?
I'm trying to build an LED-based track light that uses an HC-05 to communicate with up to 8 Arduinos to control up to 16 LEDs total. Each Arduino can only control 2 LEDs because of the shape and form factor of the project.
The track has 3 rails, 12V, Ground and Signal and all Arduinos share the same rails. Hopefully the schematic below does a good job explaining it.

On to my issue. Initially, I was getting almost 5V from my pin 7 (SoftwareSerial pin) on the Arduinos, which was quietly ruining the TX pin on my HC-05. I lowered that to about 1v after using pinMode(bluetoothTx, INPUT);, which is good but not good enough. That voltage starts to add up as I add more and more Arduinos to the overall setup.
My solution in theory is to add diodes to pin 7 on the Arduinos, so they can't put voltage on the signal rail. This drops the voltage by 0.7v from what I've read, which most likely is why the Arduinos aren't reading a signal now, because that drops it below the logic level required, since the HC-05 is only putting out 3v3. So I think to add a level shifter on the HC-05 to pump up the signal to 5v, then the diode's voltage drop shouldn't matter right? See schematic below.

My solution seems unnecessarily convoluted and I don't even know if it would work. The more I read without bouncing the information off of others, the more confused I am becoming. Now after reformatting this post for an hour, I am thinking about a decoupling capacitor between the pin and ground... Will that have the effect I am looking for?
I also looked into using a pulldown resistor, but from everything I've seen (and from the first electronics course I've taken), it seems like an inappropriate solution. The examples I've seen usually use a switch, which makes sense, but for my application I am protecting the TX pin on my HC-05, so I think it would not give the effect I am looking for (tapping the line in between resistor and pin would not isolate the voltage, tapping in after the resistor would short the signal to ground).
I'm including my code for completeness, but the schematic is where I think I need help. Could someone point me in the right direction, I don't mind working for my answers but I've been going solo at this for over a month now, and I'm not even at the point in my education where we've covered much logic yet. I'm reaching a little here.
#include <EEPROM.h>
#include <SoftwareSerial.h>

byte address = 1; //change this to change light address
byte lightno = (address + 1); // variable to print light number
int addressShifter= ((address)*500); //This number will be subtracted from input
int bluetoothTx = 7; //btTX to pin 7 //input from HC-05
int bluetoothRx = 8; //btRX to pin 8 //not used
int led1 = 3; // the PWM pin LED1 is attached to
int led2 = 5; // the PWM pin LED2 is attached to
int brightness1 = EEPROM.read(0); //Recalling previous setting
int brightness2 = EEPROM.read(1); //Recalling previous setting
int thismodMin = (0 + addressShifter); //min two-byte looked for
int thismodMax = (499 + addressShifter); //max two-byte looked for

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx); //naming it bluetooth and assigning it to the variables shown

void setup() {
    pinMode(led1, OUTPUT); // sets the pin as output
    pinMode(led2, OUTPUT); // sets the pin as output
    pinMode(bluetoothTx, INPUT); // sets the pin as input
    //Setup usb serial connection to computer
    Serial.begin(9600);
    //Setup Bluetooth serial connection to android
    bluetooth.begin(9600);
    analogWrite(led1, brightness1); //Set Led brightness from stored values
    analogWrite(led2, brightness2); //Set Led brightness from stored values
    Serial.println("SETUP COMPLETE, I am Light #"); //Identify self
    Serial.println(lightno);
    Serial.println("expecting Min "); //Min value listened for
    Serial.println(thismodMin);
    Serial.println("expecting Max "); //Max value listened for
    Serial.println(thismodMax);
}

void loop() {
    //---------Serial Communication---------
    if(bluetooth.available()>= 2) {
        unsigned int blu1 = bluetooth.read();
        unsigned int blu2 = bluetooth.read();
        unsigned int blueinput = (blu2 *256) + blu1;
        //I don't know why any of the above is neccesary but it will not read correctly without this conversion
        //Serial.println("blueinput = "); Not used
        //Serial.println(blueinput);  Not used
        if (((blueinput) >= (thismodMin)) && ((blueinput) < (thismodMax))){
            //If this blueinput is within this modules adress range, convert signal to PWM
            int thisMod = ((blueinput) - (addressShifter));
            //Convert blueinput to a value this module will work with (0-500)
            //-----------Lights---------
            if (((thisMod) >= 0) && ((thisMod) < 100)){ //0=off 1-100=on-Bright
                brightness1 = ((thisMod)*2.55); //converts percentage brightness to PWM value
                analogWrite(led1, brightness1); //apply brightness
                //      Serial.println("brightness1: "); //diagnostics
                //      Serial.println(brightness1); //diagnostics
                delay(10);
            } else if (((thisMod) >= 101) && ((thisMod) < 201)){ //101=off 102-201=on-Bright
                brightness2 = (((thisMod)-101)*2.55); //subtract starting value and then convert percentage brightness to PWM value
                analogWrite(led2, brightness2); //apply brightness
                //      Serial.println("brightness2: "); //diagnostics
                //      Serial.println(brightness2); //diagnostics
                delay(10);
            } else if ((thisMod) == (399)){ //if specific code recieved
                EEPROM.write(0, brightness1); //store brightness setting for light 1
                Serial.println("Epprom1 written");
            } else if ((thisMod) == (424)){
                EEPROM.write(1, brightness2); //store brightness setting for light 2
                Serial.println("Epprom2 written");
            } else{}
        }
    }
}

Have you considered that it's not the voltage on the lines, but rather the current that the TX pin is sourcing when connected to multiple Arduinos in parallel that is burning out the pin?

first of all just to clarify some things.
softwareSerial library sets PinMode for rx,tx declared pins internally so it should not have any impact on voltages you measure if you include pinMode(bluetoothTx, INPUT); and if this happens, as you describe, it indicates a problem.
a pin declared as INPUT is on a high impedance state which means that it will not (in general) affect signals connected to it.
an RX pin, by default is pulled up which means that when you do not have anything connected to it, you should measure 5V and when you connect it to GND you should read 0V.

i tried to reproduce your problem by implementing your first schematic utilizing 3 arduinos as receivers with the difference of having another arduino as transmitter instead of HC-05 and using a simplified version of your program (see it below).
I could not reproduce it. Also, I suspect that parallel pull up resistors from ~8 arduinos may be the problem, so I would suggest:

make sure communication between HC-05 and only one arduino works.
try connecting HC-05 with two arduinos and see if both arduinos are able to read incoming data.
keep adding arduinos and checking if every arduino can read incoming data.

also try with another arduino as transmitter instead of HC-05 in case you still have a problem and post the results so we can further investigate .
#include <SoftwareSerial.h>

int bluetoothTx = 7;    //btTX to pin 7 //input from HC-05
int bluetoothRx = 8;    //btRX to pin 8 //not used

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);  //naming it bluetooth and assigning it to the variables shown

void setup()
{
        //Setup usb serial connection to computer
        Serial.begin(9600);

        //Setup Bluetooth serial connection to android
        bluetooth.begin(9600);

        Serial.println("SETUP COMPLETE, I am Light #");  //Identify self
}

void loop()
{
        //---------Serial Communication------
        if(bluetooth.available() )
        {
             Serial.print(bluetooth.read(),HEX );
        }

}

Thanks for such a thorough and fast reply, I tested both your code and my own on my uno, mega and nano and all seem to measure 4.5-5v with no load with multimeter (DMM)connected between pin 7 and ground. With a load (2.2k resistor to ground) voltage drops immensely (like a dead batter would with high impedance) so I see what you are saying. With High impedance, the voltage would show but not be there as soon as a load is applied? That said,

the voltage without load and with load both drop significantly when I specify pinmode input, can you verify that on your end? If my devices are normal, will this voltage without load hurt my TX pin or is that unrelated? When you say parrallell pull up resistors would that apply to the TX pin that is an input, I assume that the resistor that is giving it high impedance is that same that functions as a pullup, just connected differently? Lastly, if I'm connecting that 2.2k resistor for pin 7 to G, and the voltage drops a ton, I think that takes care of my problem right just using a pulldown?

ok, I found an HC-05 and have connected it's TxD pin to 2 uno's , one micro, one mega, all at the same time. Note that on arduino mega, pin 7 cannot operate as softwareSerial RxD pin, so I used it's pin 53 instead. The voltage on the line, when not transmitting any data, is stable to 3.3V as expected, regardless of whether or not pin 7 (or 53 for mega) is explicitly declared as INPUT (with pinMode function). I still suggest you follow the steps provided on this answer and report back on which step problems start appearing.

for the time being, do not concern yourself with pull up resistors think I described.It has a small probability of being the problem source and we must narrow down the problem first.


text:
Why can't the OCR1A register be set to 1 to get a 8MHz PWM?
The max PWM frequency that can be achieved with an Arduino is by using the PWM fast mode with the pre-scaler set at 1 and the TOP counter value at 3, getting 4MHz
f_OC = 16000000/(1(1 + 3)) = 4000000
Why can't be the TOP value set at 1?

Because then you only have 1-bit PWM. And there aren't an awful lot of applications for 1-bit PWM.

Yeah, I understand isn't quite useful, but there is some kind of physical limitation? if I set the TOP =1, what will happen?

There's no physical limitation, there's just no point. The DC of the signal will be either 0% or 100%, which means you've emulated a normal GPIO except that you're consuming the power to run the clock as well.

You're right I was thinking on three values.

And what about TOP =2 ?


text:
Get value from a website using Yún and a RPi
I have a project that requires opening a door remotely. I'm using an arduino Yún and a raspberry pi.
 I have a switch connected to the RPI and i'm sending it's value to a web server. How can I get the value from the website to the arduino, so that it can process it and see if an order to open the door is issued?
Thanks for any help :)

Do you want to do it from the Linux portion or the AVR portion of the Yun?

I want to check the remote value (located on a web-site) using AVR.

You need to use the Process library that comes with the IDE.
That allows you to execute commands on the Linux portion of the Yun from within your Arduino code, and get data back from it.
You use that class to execute the curl command in Linux to fetch the content of a web page and return that content to the AVR code where you can deal with it.
If the content of the web page is complex it may be worth passing the output of curl through some other Linux based commands first (such as grep and cut or awk) to clean it up and reduce the amount of text you have to deal with at the AVR end.


text:
ESP8266 not able to communicate over serial connection with arduino UNO
This is the code I uploaded in Arduino UNO:
#include<SoftwareSerial.h>
SoftwareSerial ESP(2,3); // RX, TX
//ESP RX-->3(UNO) TX-->2(UNO)

void setup() {
// Open serial communications and wait for port to open:

    Serial.begin(9600);
    while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
    }

    Serial.println("Goodnight moon!");

    // set the data rate for the SoftwareSerial port
    ESP.begin(9600);

}

void loop() {
    if (ESP.available()) {
        char inData = ESP.read();
        Serial.println("Got reponse from ESP8266: ");
        Serial.write(inData);
    }

    ESP.write("AT\r\n"); //Normally ESP responds to AT command with "OK"
}

But ESP is not able to receive the AT command properly...sometimes it recieves A, sometime T. It then responds with garbage value. Though we are able to give command to ESP through Serial Monitor and it responds pretty well. But when trying to communicate through code, the communication is not OK.

This site is about electrical engineering.  Extra-sensory perception is off topic here.

Why is this question downvoted and voted to close? MCVE code is provided, sympthoms of failure are described. What is the problem?

Are you aware that you can program the ESP8266 directly from the Arduino IDE using proper Arduino C rather than AT commands.  This means that it might be possible to eliminate the need for a 32MHz Arduino and just rely on the 160MHz ESP82366 instead.
Also you need to have a look at the SO Arduino forum.

@Matt yeah it can be done...but am using arduino in my project to control servos and all, so I am relying on arduino for the processing work. :)

Unless you are pushing the connections on an Arduino to the limit it might be worth looking at a Webbo D1, its an ESP8266 12E with an Arduino form factor.  The biggest issue I have had porting is remembering the Pins are addressed by GPIO label not pin number.

@Matt do you mean WeMos D1? There is no Webbo D1.

@gre_gor - Yes, that's the one.  Sorry its been a long week :(

The problem is in your loop() function. On each iteration, you will receive at most one character from the SoftwareSerial, while writing the same AT command again and again. As a result, your slave device (ie. ESP8266) will overflow its UART buffers, resulting in garbage being sent and received.
You should keep receiving data from the slave for as long as it has data:
while (ESP.available()) {
    char inData = ESP.read();
    Serial.println("Got response from ESP8266: ");
    Serial.write(inData);
}

Thanx it works fine now! :)

@abhimanyubishnoi Note that you can click o that "check" mark to accept my answer if it really solved your problem. That way, other people will see your problem was solved, and move on to answer unsolved questions.

Dmitry Grigoryev - i have tried u r solution, but still i am not able to get response 'OK' from ESP 01(my device)....here is the screen shot with response https://i.stack.imgur.com/mOklg.png....

@3bu1 Judging by your screenshot, you still have failed to replace if with while.

still the same, here is the screen shot(https://i.stack.imgur.com/3nAC2.png) and i have posted question on this url(https://arduino.stackexchange.com/questions/39729/not-able-to-get-response-from-esp-using-arduino-uno), kindly help me with this...thank u in advance


text:
Any way to not explicitly include dependent libraries?
When I am including the Adafruit_BMP280 library, Arduino IDE 1.7.10 complains that it wants all dependent libraries included:
Adafruit_Sensors.h
Wire.h
SPI.h

Isn't it possible to circumvent that? This question says to include the first library like
#include "Adafruit_BMP280"

but also with the full path, this doesn't work and just returns the same error.

You could put these includes in a separate file, and include that file? I'm not sure if that's what you mean? Or probably include them in the BM280 file? I'm actually not sure. Maybe newer versions of Arduino IDE, I don't believe I ever had to include SPI?

No, it is not possible. The IDE needs to know which libraries you are using so that it can compile the source code for them.
Other IDEs have got around the problem by recursively scanning the libraries themselves and building up a list of dependencies (such as UECIDE) but this is not something that the Arduino IDE has been programmed to do.
The only other possible option might be to create a single massive library that contains everything that the "main" library relies on, however this may cause problems with other libraries also wanting the same things and you ending up with massive conflicts.


text:
ESP2866 and java ServerSocket
So I have an application that runs on the Arduino that passes info over serial.
I'm using a ESP2866 to make it wireless.
Arduino->Serial->Esp2866->SocketConn->JavaSocket->Console

I have a working java socket server, that I can connect to with other applications. (Java, c++, ext.) And even across the network.
I just cant seem to get my ESP2866 to connect.
Iv tried several ESP2866 units, no success. Iv tried updating the firmware on each, nope.
AT                      ->  OK
AT+RST                  ->  ready
AT+CWMODE=1             ->  OK
AT+CWJAP="name","pass"  ->  CONNECTED,GOTIP,OK
AT+CIPMUX=0             ->  OK
AT+CIFSR                ->  192.168.0.30
AT+CIPSTART="TCP","192.168.0.9","4160"  ->  ERROR

The lack of debug info is... Aggravating.
Iv Seen other examples of this that worked. So whats the problem?
Additional info:
netstat -tulpn | grep 4160
tcp6       0      0 :::4160          :::*      LISTEN      23058/java

(Edit 1:)Just tried restricting to IPV4 and rebinding the port. Nope.
InetAddress localAddress = Inet4Address.getByAddress(new byte[]{(byte) 192,(byte) 168,0,9});
System.setProperty("java.net.preferIPv4Stack", "true");
ServerSocket listener = new ServerSocket(port,20,localAddress);
//...Code to make socket work.

The ESP trys to connect to port 4160, but the server is listing on port 20.

java.net.ServerSocket.ServerSocket(int port, int backlog, InetAddress bindAddr) throws IOException

try just writing ServerSocket listener = new ServerSocket(port/ 4160/);

is the port answer solved your problem?


text:
Does Serial.read() ever return a character?
I'm trying to program my Arduino Mega to work with a TSL1401 line scan module and while looking over someone else code I came across this:
void loop()
{
    int b = Serial.read();      //Reads incoming serial data. Returns the first byte of
                                //incoming serial data available (or -1 if no data is available)

    if (b == 's')
    {
        getCamera();
        delay(2000);
    }
}

For the most part I understand what it's doing but I got confused when I saw that he was setting the return value of Serial.read() equal to a variable and then checking to see if that variable was a character. To my understanding Serial.read() returns an integer so why would you compare it to a character?

On an 8 bit arduino a character is a byte.  A byte can represent values between -128 and 127, or between 0 and 255, depending on how you "look" at them (signed or unsigned).
The whole concept of a character is a purely human thing. The Arduino only knows numbers.
For instance the character 'A' is actually the number 65. We, as humans, choose to represent it as an 'A' and call it "ASCII".
Again, the character 'a' is actually the number 97. You can also subtract characters from each other.  'a' - 'A' = 32

Part of the answer is in the comment in your given example:
int b = Serial.read();      //Reads incoming serial data. Returns the first
                            //byte of incoming serial data available
                            //(or -1 if no data is available)

If you're reading raw 8-bit data from the serial port (basically, could be any value from 0-255), how do you represent errors?   Per the comment: if nothing is available, it returns -1.  But... as @Majenko pointed out, -1 is a valid CHAR too, it all depends on how you look at the data (signed, or unsigned).
But an INT can hold a value from 0-255 easily, and also a -1 to represent 'nothing'.  The Serial.read function is non-blocking (it doesn't WAIT for a data byte), so it needs to be able to return a status that indicates 'empty bucket', meaning there's actually 257 (256+1) different possible values... thus you need more than 8 bits.
It's a painful lesson with usage of fgetc(3), getc(3) and similar functions.  You need to be able to represent EOF, while also returning valid 8 bit data.  Hence the use of INT's as return value size.  Often someone (ok, me... but it was a long time ago!) will figure that since they're reading CHAR's, you can use a CHAR sized variable... but then EOF never seems to be found... oops!
Hope this helps.

On the Arduino an int value can range from -32,768 to 32,767. You can easily differentiate that from a char value. And Serial.read() returns a int value.

@ott why this example uses char? https://www.arduino.cc/en/Reference/SoftwareSerialRead


text:
How can you export data to a file in Arduino?
How can I export the readings that are being sent to my Arduino Mega to a file?
I know there is a write() method but I can't find the documentation on how to use it.
I want the file to be created and stored on my PC not an SD card. Also I want to know if there is a way to do this without using external programs.

Where do you want this file to be? On an SD card or on your PC?

You can use a terminal program like putty or Minicom to write that data to a log file. Then you can use whatever program or app to process this log file.
Both programs can read from the serial interface.

if your arduino is connected to a computer, you can create a small application that will listen to serial port and write on a file whatever arduino sends over the serial.
Alternatively you can write directly on an sdCard. (There are many sdCard shields available on the market.)
As for the write method, you probably are referring to write method of File class of SD library

Isn't there a way of doing this without having to use another program?

@IsabelAlphonse Use the serial terminal built into the Arduino IDE. And copy/paste the text from it into a text file ;)
There isn't really a way to get stuff done on a PC, withouth a program ;D

I know there is a write() method but I can't find the documentation on how to use it.

You can use: Serial.write(F("TEXT")); to send text over the "serial communication".
This basically means that your Arduino will send the text to your PC over the USB emulated COM port.
The magnifying glass button at the top-right of your Arduino IDE's screen will open the "Serial Monitor" here you can see the text that's coming from the Arduino, you can even send text back.

How can I export the readings that are being sent to my Arduino Mega to a file?

You could make your Arduino interface with an SD-card.
Or use that serial connection I told you about.
You could create a program (on the PC) that takes the serial input and stores it into a file. A lot of examples from this should be on the internet.
Another thing might be, to use a more advanced serial terminal. I believe "terminal.exe" allows "logging" to a file.


text:
Deploy data online from SD Card on Arduino
I intend to design an air pollution monitoring station which will measure these data (CO, NO2, O3, Temperature, Humidity and Pressure). I want to store the data on the SD card during the whole day and deploy it online in CSV format.
I will have five stations in fixed locations and gather their daily data.

Any suggestions about specific types of sensors (references)?
How to store the data as CSV format?
How to send the data online at certain time on Arduino?
Is it better to use GSM or WiFi?

How to store the data as CSV format?

Write the values to the card with commas between them.
myFile.print(noxValue);
myFile.print(",");
myFile.print(coValue);
myFile.print(",");
myFile.println(ozValue);
... etc ...

How to send the data online at certain time on Arduino?

You need to make a suitable network request to whatever unknown thing it is you are sending it to. That may be a HTTP POST request, or it could be some completely different mechanism. Until you have decided where you are sending it we can't help you with the how of sending it.
As to the when, you really could do with a Real Time Clock module so you know what the time is. Then at a certain time you can run your code. Some RTC modules have an alarm that can alert you when it's time to send your code. Great for if your MCU has been placed in a sleep mode and needs waking up at the right time.

Is it better to use GSM or WiFi?

That depends if you have access to WiFi where the sensor is. If you do, then WiFi is (more often than not) cheaper. If you don't, then WiFi is impossible and GSM is the only option.


text:
Amforth on Arduino UNO
I'm having trouble with flashing amforth on my Arduino UNO.
I'm using an Arduino as ISP to write amforth.
Here's what I do:

Upload the code on the Arduino programmer and set Baudrate to 19200
Wire the Arduinos this way -> Wiring
Run avrdude -P /dev/ttyUSB* -c avrisp -b 19200 -p m328p -e -U flash:w:uno.hex:i -U eeprom:w:uno.eep.hex:i -U efuse:w:0x05:m -U hfuse:w:0xD9:m -U lfuse:w:0xFF:m

Sometimes it fails to set efuse,  but if I give the command just for it, even if it says "efuse changed, it was 5, not is 0xfd, do you want to change it back?" and I say no, I get the message with the correct fuses.
I log onto the amforth Arduino with the python shell, but my stack is constantly ??? -13 and different numbers. I found out -13 is error code for not found, but... not found what?
What does it mean? What am I missing?

I have to say that I'm new at this things, I recently studied Forth and discovered that I can use it on my Arduino, and I wanted to try.

By the way, the Arduino is not original.
 The chip is ATmega 328p
EDIT:
I downloaded amforth from here
Initially I followed [first guide] (different wiring but I've read around it's the same) and then "clarified my doubts" with another one from sparkfun.
(no link used because maximum for me is 2 links per post at the moment, I'll write it in the comments)

I tried with versions 6.1 and 6.0, then I decided to try with 5.9 (the one from the first guide) and now I'm running that (at least it allows me to pop elements from the stack).

update: everything seems to work fine, I just get error -13 when I print the stack content

The 0xfd part is easily explained. The extended fuse on that chip only uses the first 3 bits, and the rest read back as 1 for future compatibility. That is, not matter what you set them to, you get back 1s for 5 of the bits. ie. 11111xxx. So, 5 is 00000101 and reads back as 11111101 (0xFD).

Please edit your question to state where amforth comes from. That saves a search, and even if we search for it, we may find a different one to the one you are trying.

first guide second guide

I programmed by Uno using your first guide and it seems to work OK.
amforth 6.1 ATmega
8P Forthduino

For example, using the serial monitor, I entered:
6 7 * .

It printed:
42  ok
>

Then  entered the ASCII table example:
\ print a ascii table
: .ascii
base @
$7f $20 do
    i emit
    decimal  ." , dec: " i .
    hex      ." , hex: " i .
    8 base ! ." , oct: " i .
    2 base ! ." , bin: " i .
    cr
loop
base !
;

Then when I invoked it with ".ascii" it printed the table:
> .ascii
 , dec: 32 , hex: 20 , oct: 40 , bin: 100000
!, dec: 33 , hex: 21 , oct: 41 , bin: 100001
", dec: 34 , hex: 22 , oct: 42 , bin: 100010
#, dec: 35 , hex: 23 , oct: 43 , bin: 100011
$, dec: 36 , hex: 24 , oct: 44 , bin: 100100
%, dec: 37 , hex: 25 , oct: 45 , bin: 100101
&, dec: 38 , hex: 26 , oct: 46 , bin: 100110
', dec: 39 , hex: 27 , oct: 47 , bin: 100111
(, dec: 40 , hex: 28 , oct: 50 , bin: 101000
), dec: 41 , hex: 29 , oct: 51 , bin: 101001
*, dec: 42 , hex: 2A , oct: 52 , bin: 101010
+, dec: 43 , hex: 2B , oct: 53 , bin: 101011
,, dec: 44 , hex: 2C , oct: 54 , bin: 101100
-, dec: 45 , hex: 2D , oct: 55 , bin: 101101
., dec: 46 , hex: 2E , oct: 56 , bin: 101110
/, dec: 47 , hex: 2F , oct: 57 , bin: 101111
0, dec: 48 , hex: 30 , oct: 60 , bin: 110000
1, dec: 49 , hex: 31 , oct: 61 , bin: 110001
2, dec: 50 , hex: 32 , oct: 62 , bin: 110010
3, dec: 51 , hex: 33 , oct: 63 , bin: 110011
4, dec: 52 , hex: 34 , oct: 64 , bin: 110100
5, dec: 53 , hex: 35 , oct: 65 , bin: 110101
6, dec: 54 , hex: 36 , oct: 66 , bin: 110110
7, dec: 55 , hex: 37 , oct: 67 , bin: 110111
8, dec: 56 , hex: 38 , oct: 70 , bin: 111000
9, dec: 57 , hex: 39 , oct: 71 , bin: 111001
:, dec: 58 , hex: 3A , oct: 72 , bin: 111010
;, dec: 59 , hex: 3B , oct: 73 , bin: 111011
<, dec: 60 , hex: 3C , oct: 74 , bin: 111100
=, dec: 61 , hex: 3D , oct: 75 , bin: 111101
>, dec: 62 , hex: 3E , oct: 76 , bin: 111110
?, dec: 63 , hex: 3F , oct: 77 , bin: 111111
@, dec: 64 , hex: 40 , oct: 100 , bin: 1000000
A, dec: 65 , hex: 41 , oct: 101 , bin: 1000001
B, dec: 66 , hex: 42 , oct: 102 , bin: 1000010
C, dec: 67 , hex: 43 , oct: 103 , bin: 1000011
D, dec: 68 , hex: 44 , oct: 104 , bin: 1000100
E, dec: 69 , hex: 45 , oct: 105 , bin: 1000101
F, dec: 70 , hex: 46 , oct: 106 , bin: 1000110
G, dec: 71 , hex: 47 , oct: 107 , bin: 1000111
H, dec: 72 , hex: 48 , oct: 110 , bin: 1001000
I, dec: 73 , hex: 49 , oct: 111 , bin: 1001001
J, dec: 74 , hex: 4A , oct: 112 , bin: 1001010
K, dec: 75 , hex: 4B , oct: 113 , bin: 1001011
L, dec: 76 , hex: 4C , oct: 114 , bin: 1001100
M, dec: 77 , hex: 4D , oct: 115 , bin: 1001101
N, dec: 78 , hex: 4E , oct: 116 , bin: 1001110
O, dec: 79 , hex: 4F , oct: 117 , bin: 1001111
P, dec: 80 , hex: 50 , oct: 120 , bin: 1010000
Q, dec: 81 , hex: 51 , oct: 121 , bin: 1010001
R, dec: 82 , hex: 52 , oct: 122 , bin: 1010010
S, dec: 83 , hex: 53 , oct: 123 , bin: 1010011
T, dec: 84 , hex: 54 , oct: 124 , bin: 1010100
U, dec: 85 , hex: 55 , oct: 125 , bin: 1010101
V, dec: 86 , hex: 56 , oct: 126 , bin: 1010110
W, dec: 87 , hex: 57 , oct: 127 , bin: 1010111
X, dec: 88 , hex: 58 , oct: 130 , bin: 1011000
Y, dec: 89 , hex: 59 , oct: 131 , bin: 1011001
Z, dec: 90 , hex: 5A , oct: 132 , bin: 1011010
[, dec: 91 , hex: 5B , oct: 133 , bin: 1011011
\, dec: 92 , hex: 5C , oct: 134 , bin: 1011100
], dec: 93 , hex: 5D , oct: 135 , bin: 1011101
^, dec: 94 , hex: 5E , oct: 136 , bin: 1011110
_, dec: 95 , hex: 5F , oct: 137 , bin: 1011111
`, dec: 96 , hex: 60 , oct: 140 , bin: 1100000
a, dec: 97 , hex: 61 , oct: 141 , bin: 1100001
b, dec: 98 , hex: 62 , oct: 142 , bin: 1100010
c, dec: 99 , hex: 63 , oct: 143 , bin: 1100011
d, dec: 100 , hex: 64 , oct: 144 , bin: 1100100
e, dec: 101 , hex: 65 , oct: 145 , bin: 1100101
f, dec: 102 , hex: 66 , oct: 146 , bin: 1100110
g, dec: 103 , hex: 67 , oct: 147 , bin: 1100111
h, dec: 104 , hex: 68 , oct: 150 , bin: 1101000
i, dec: 105 , hex: 69 , oct: 151 , bin: 1101001
j, dec: 106 , hex: 6A , oct: 152 , bin: 1101010
k, dec: 107 , hex: 6B , oct: 153 , bin: 1101011
l, dec: 108 , hex: 6C , oct: 154 , bin: 1101100
m, dec: 109 , hex: 6D , oct: 155 , bin: 1101101
n, dec: 110 , hex: 6E , oct: 156 , bin: 1101110
o, dec: 111 , hex: 6F , oct: 157 , bin: 1101111
p, dec: 112 , hex: 70 , oct: 160 , bin: 1110000
q, dec: 113 , hex: 71 , oct: 161 , bin: 1110001
r, dec: 114 , hex: 72 , oct: 162 , bin: 1110010
s, dec: 115 , hex: 73 , oct: 163 , bin: 1110011
t, dec: 116 , hex: 74 , oct: 164 , bin: 1110100
u, dec: 117 , hex: 75 , oct: 165 , bin: 1110101
v, dec: 118 , hex: 76 , oct: 166 , bin: 1110110
w, dec: 119 , hex: 77 , oct: 167 , bin: 1110111
x, dec: 120 , hex: 78 , oct: 170 , bin: 1111000
y, dec: 121 , hex: 79 , oct: 171 , bin: 1111001
z, dec: 122 , hex: 7A , oct: 172 , bin: 1111010
{, dec: 123 , hex: 7B , oct: 173 , bin: 1111011
|, dec: 124 , hex: 7C , oct: 174 , bin: 1111100
}, dec: 125 , hex: 7D , oct: 175 , bin: 1111101
~, dec: 126 , hex: 7E , oct: 176 , bin: 1111110
 ok
>

I suspect your issue is you are not using it the way it is supposed to be used. Can you show the exact commands you type which cause the error?

(Edited to add)
After fairly extensive investigation of the source, I think that .s is not necessarily implemented for the Uno .hex file.
I found one suggested implementation here:
: .s  ( -- )\ stack picture listing order
depth
begin dup while dup pick . 1- repeat
drop
;

Running that it seems to work OK:
> 1 2 3 4 .s
1 2 3 4  ok

The .s word is implemented in the file dot-s.asm where you can see exactly how they did it (it's not the same as the Forth version above).

You mean Forth commands, right? I've tried pushing and popping things from stack. Using amforth 5.9 I pushed values to stack, and popping with .  was fine. I tried printing some strings and defining simple words, no problems. The problem is when I use .s to print the stack. That gives me the error. I haven't tried with other commands. Now I'm not near my computer, I hope that I can retry flashing 6.1 and do some other tests...

Yes, Forth commands/statements, whatever they are called.

Well, I told them in the previous comment lol. Tomorrow I can run some other tests (even if it's going to be hard, I'll be all day in university..), if not tomorrow, surely the day after. But I think that the problem is just .s . All the things I tried that do not involve printing stack worked fine.. By the way I did not use the serial monitor but the python shell shipped with amforth. The only edit I made to the script was to change /dev/amforth serial port parameter in a function to /dev/ttyUSB0 (the first did not exist, so I changed to the latter, that exists)

If you type "words" you get a list of words. ".s" is not amongst them. According to the documentation The default configuration includes most but not all words..

See amended reply - you can implement your own .s in Forth.

Wow, I've really missed the link between -13 and not found. I assumed that .s was sort of "the basic word" but thinking about it yeah, it's not really necessary. I tried that implementation of .s and works like a charm.
I have one more question: I noticed my previous words are saved permanently, is there a way to wipe the dictionary without rewriting the bootloader? The only thing that comes in my mind is the -e option for avrdude, but it erases the whole thing, am I right?

I was wondering that myself. It was rather cool that new words stay added to the dictionary, but I don't know how to remove them. For example I accidentally added 3 x .ascii before I realized. (Only when I typed words did I find out).

@NickGammon -- There is sometimes a "forget" command. And that also involves somehow marking where you want forget to go back to. But generally, I just make a mess of things with multiple definitions and all, keeping track of what I want to become permanent, add that to some kind of automatically loaded file, and hit reset.


text:
Can I connect a camera without a shield?
I have an Arduino Uno and an ArduCAM-mini 2MP camera:
http://www.arducam.com/tag/arducam-mini/
Is it possible to connect this camera, or similar cameras, to the arduino without a shield?  The only tutorials I've found use a shield.
edit - here is what my cam looks like:

The first picture on that page shows it connected without a shield.

I see the photo, but with no supporting information I won't get far.  It looks like the vcc and gnd pins from the camera are connected to the wires.  It wasn't clear to me that I should bend the camera pins as such (mine has 8 pins pointing downward).  Sorry, complete novice.  Any help is appreciated.

Hey! This looks like an awesome piece of hardware! It can definitely work without a shield since it communicates using the SPI interface which the arduino can handle.... I might be able to help you further if you take a picture of the labels on it :p (i can't find a decent one :/)

Judging by the photo (below) it is specifically designed to plug into the SPI ports on a Uno or similar (that is, pins 10 to 13). The other two wires are going to the ICSP header, presumably to pick up +5V and ground.

So yes, most certainly you can use it like that. With the pins done like that it even points horizontally.

It wasn't clear to me that I should bend the camera pins as such (mine has 8 pins pointing downward).

You can buy pins with a 90° angle. If yours are not already soldered on, I would use the bent connector. If the pins are already soldered on, then the camera would lie flat, so just rotate the Arduino itself to point to where you want it to.
However you would need to do something with the +5V and Gnd pins, so that they can be rerouted to the correct place.

Looking at another photo on that site.

The pins would match most of the pins on a Uno, like this:

The only one that is wrong is AREF - you need +5V into that pin, not AREF, which is why they bent those two pins outwards (+5V and Gnd) and ran wires to the ICSP header.

If you mean all your pins are at right-angles already, then you really only need to fix the +5V one (you can probably bend it up). This is the pin-out for the ICSP header (view from above):

As you can see, you can pick up +5V from pin 2 (Vcc). Alternatively, run the +5 wire over to where +5 is marked on the Uno on the other side.

Another possible approach would be to not bend anything, but solder on a wire to the +5V pin and leave it plugged into AREF. AREF is just an input (analog reference voltage) and it won't hurt to have it left at +5V.

Note that some people choose to just connect 5V direct to the AREF pin since connecting 5V to AREF is perfectly valid (though pretty pointless) so you then don't need to bend any pins.  See this other recent question pertaining to a similar device: http://arduino.stackexchange.com/questions/24528/what-is-vref-pin

Yep, I realized that and made yet another edit. Nice to know I wasn't the only one with that idea. :)

authors: طالبة الغفران


text:
Operating two functions simultaneously
I have connected a bluetooth module(HC-06) and a voice recognition shield(EasyVR) on an arduino UNO.
By using an another HC-06 on the another arduino(so, 2 arduinos and 2 HC-06 totally), I am going to let two arduionos communicate with each other.
Also, simultaneously, one arduino with HC-06 will recogize the voice by using the voice recognition module.
I have successed each operations, but after combining two codes the bluetooth doesn't work...
(Voice recognition have successed.)

Is it unable to operate two operations simultaneously?

Can we use these two sentences in one code?
SoftwareSerial BT(2,3);     --> for bluetooth module
SoftwareSerial Port(12,13);   --> for voice recognition module

Is it unable to operate two operations simultaneously?

The only way you can do two operations simultaneously is to have two Arduinos. An Arduino can only do one thing at a time. In order to make it seem like it's doing things at once you have to create your sketch accordingly. The use of delay() is right out. As are long loops using things like while(). In short: anything that blocks is bad.

Can we use these two sentences in one code?

Not reliably, no.  They are both resource hungry and, to a large extent, blocking. A general rule is, if you need at least two more UARTs than the board provides then you need a different board. You can only reliably work with one software UART at a time.
I would suggest upgrading to a more capable board with more hardware UARTs. Either that or use a bluetooth system that doesn't use UART, such as an SPI based BLE module.

Physically It is impossible to run 2 things at the same time when you have one microcontroller. "The Arduino is a very simple processor with no operating system and can only run one program at a time". But I am pretty sure that the solution you are trying to find, hides in multitasking or interuption. There are some cones in delay() function: "The problem is that delay() is a "busy wait" that monopolizes the processor. " But in multitasking, you share clock of the processor between two different pieces. You can find more about running different things simultanously here.
I have used miles() in one of my projects where were coin validator which was outputing impulses and screen which was showing chash inside it.


text:
The function AnalogWrite is outputting less voltage than digitalWrite on my board
I can't figure out why the output voltage of analogWrite(255) is less than the voltage of digitalWrite(255). My code and an image of my setup are below. Some other useful information is that I am using the NodeMCU by HiLetgo, 3.3k ohm resistors with the meters, and that the meters use 1mA of current DC at full scale. Thanks for your help!
int pPressure       = D2;
int pPrecipProb     = D1;
int pWindSpeed      = D0;

int mTemperature;
int mHumidity;
int mPressure;
int mPrecipProb;
int mWindSpeed;
int mAlert;

void setup() {
  Serial.begin(9600);
  pinMode(pPrecipProb,   OUTPUT);
  pinMode(pWindSpeed,    OUTPUT);
  pinMode(pPressure,     OUTPUT);
  pinMode(LED_BUILTIN,   OUTPUT);     // Initialize the LED_BUILTIN pin as an output
}

// the loop function runs over and over again forever
void loop() {
    mPressure           = (int) constrain(mPressure + 1, 0, 255);
    mPrecipProb         = (int) constrain(mPrecipProb + 1,     0, 255 );
    mWindSpeed          = (int) constrain(mWindSpeed + 1,     0, 255 );

    if(mPressure == 255)
    {
      mPressure = 0;
      mPrecipProb = 0;
      mWindSpeed = 0;
    }

    digitalWrite(pPressure,      HIGH   );
    analogWrite(pPrecipProb,    255 );
    analogWrite(pWindSpeed,     mWindSpeed  );

    delay(10);

}

Left: AnalogWrite(255)
Middle: DigitalWrite(HIGH)
Right: the other one that cycles

Have you tried swapping the meters/resistors?

Those analog meters may be loading (drawing enough current to cause the voltage to droop) the "analog" output.  The digital output likely has a higher drive ability.  I don't know this for sure, so I'm not putting it as an answer.

@slightlynybbled: analogWrite() on a ESP8266 performs (software) PWM on a normal digital output.

First, do something simpler, and eliminate possible causes.

Are you certain the NodeMCU's CPU is an 8bit PWM? If it were
9bits, it would read about 50% full scale, and 10bits would be about
25% of digitalWrite (which is what I think I can see on the photo).
Swap the analogue meters around, and see if the difference is consistent
with the pin, or consistent with the meters.
Use a digital multimeter (DMM) to measure voltage. It should be a
small load. So this should eliminate, or identify, the analogue
meters as a culprit.

If there is still a difference in voltage, do the NodeMCU equivalent of:
void setup() {
  pinMode(10, OUTPUT);  // a pin capable of analogOut and DigitalOut
}

void loop() {
  digitalWrite(10, HIGH);
  analogWrite(9, 255);  // a pin capable of analogOut and DigitalOut

  delay(100);
}

Then swap 9 and 10.
If the DMM shows the analogue output is consistently lower, then go back and check that PWM is 8 bits, and the device output range for PWM is the same output voltage as digitalWrite to a GPIO.

ESP8266's default PWM resolution is actually 10 bits, which would be consistent with the 25% output shown in the picture.

@IgnacioVazquez-Abrams - Ah ha! That was my main suspicion, but I haven't seen a proper data sheet for it.

Eh, the ESP8266 datasheet isn't particularly enlightening. PWM has to be done in software so you'd have to look at the core documentation instead.

@IgnacioVazquez-Abrams - thank you, that clarifies things. I thought I had read that all (most?) pins could supply PWM, but I hadn't realised it was soft. So I was looking for the wrong information.

The 10 bit solution worked! I simply switched out the 255 with 1023. Thanks for your help!

@user3242816 - You are welcome. If it answers your question, I'd appreciate you accepting my answer. Not only do I get more points ;-), it also marks in the question list that an answer has been accepted, which may help some of the community. I don't know, but web search engines might also pick up the 'answered' flag. However, I'd hope search engines do a good job of indexing ee.se anyway. While editing this, you have. Thank you!

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
What is the wiring of arduino motor shield to Nano?
I have the basic version of the stepper motor driver and a Nano, I see the pins are set to plug directly in to a Uno or similar Arduino, but according to the documentation it just needs most of the digital pins connected to the arduino - https://learn.adafruit.com/adafruit-motor-shield/faq
As it seems they are the opposite position to plug into a breadboard for testing, I may need to wire and solder them (11 to D11, 3 to D3, 5 to D5, 6 to D6). Is this correct or does the Nano not have the power/amperage/timing or something to run this type of shield, hence the lack of compatibility listed for that shield?

I found that this does work with the Nano - the only reason they don't list it is because it doesn't fit in to the shield I suppose.

I believe, though it's not clear, that the shield in question uses a 74HC595 shift register to control the main motor drivers - the other pins are for the servo interfaces (and they are just wired 1:1). Theoretically you can therefore use any pins you like to control the motor drivers themselves.
It's not the same as the Adafruit one which looks to use direct Arduino control of the motor drivers.

Thanks for the answer. Look up the docs for "L293D Motor Drive Shield For Arduin" and it looks like it's the old Adafruit shield, and uses specific pins for each motor... If that's all the difference I guess I'll connect/solder them to the Nano and try.

Or just another simple version (which is more hardcore such as brute force):
Get expansion shield for nano to uno :)
I think this is just a sandwich version, which just takes additional space and cost.


text:
Arduino Mega + SIM808 GSM + GPS Module + Program Switch ON without pressing Push Button?
I am new to IOT and tried out integration and a small test code with an Arduino Mega + SIM808 + GSM + GPS Module. It works fine with the SIM808 Library.
My requirement is to put it in an enclosure, but when the power restarts, for some reason we have to manually start the SIM 808 + GPS + GSM Module. Can we control it from code? Can we do a software trigger from Arduino code?
Maybe if we have some pins to connect and trigger the power on. Kindly provide inputs/suggestion for this module.
If you are aware of some module that can be started through code kindly suggest.
Here's one reference I found for a different module with Software Trigger.

I tried connecting D9 to 5 V and Damn it works !! ,, I don't know where didi you get that information from but it works giving 5V for D9 on sim808 evb 3.2 for 3 - 4 seconds will make it power on .

There is a simple way of power the module without pressing the button. There is pin call D9 at the bottom right corner of the module. Just power the pin by Arduino digital pin or 5v pin around 3, 4 seconds. Then it will power the whole module. No need to press the press switch. Make sure you connect power(9V-12V) to the board and provide 5V and GND to the sim808 module. below figure shows the pin D9

This is great solution, vote up! Anyway please how did you get to this information? As I bought this board on Aliexpress I have no datasheet.

About the 5V, if the board is powered by DC044 then V_IN is not needed. Note: blue arrow on the image is pointing to the VMCU which controls the high level of TTL UART.

Google probably answered my "D9" question: https://www.elecrow.com/wiki/index.php?title=SIM808_GPRS/GSM%2BGPS_Shield_v1.1

I can't get a great view of the board, but if you are pressing the button just below "GSM" and "Made" then I would suggest soldering some leads onto the button and connecting them to a digital output and Gnd on the Arduino.  (You might need resistors and stuff)  Then when you wanted to press the button you could pulse the line high.

Thanks ! will try the same and add relay ..and control using arduino !


text:
What would be the code for using Arduino UNO to alert by sound or LED when it detects a certain position through GPS?
I am in grade 6. I have a very nice pet dog in my house but it often enters Mom's kitchen to spoil all the foods. So I am thinking of a device to attach with him which can locate its position. But I am totally new to arduino programming. I have found some tutorials of arduino UNO to locate position with GPS. But I don't know how to set up the alarm when my dog reaches the position of our kitchen and what will be the code for it. If I wanna set alarm for different position, like kitchen and two toilets, what would be the code then? I know Java a very little bit. C too. Nothing else. Is there any altruist to help me out, please?

First things first: do you know that a GPS can locate your dog accurately enough in your home?
Basically, even with a good GPS receiver, the best accuracy you can expect (using off-the-shelf receivers, non-military or DGPS) is maybe 3 m. Typical performance is maybe 4 m, and indoors it will be even worse. The point is, your dog could be 5 m away from your intended location, and you will get an alarm. 5 m in a house might be the room over, two rooms over, or outside the house!
However, if you want to go forward with this, get yourself a GPS module, connect it to your Arduino, install the TinyGPS++ library (one of the better Arduino GPS libs IMO), and play with it. It's easy to figure out how to perform an action when the GPS coordinates are in range of a given coordinate set.
You might have better luck using a different form of dog location detection.

FYI, you might be interested in my library, NeoGPS.  It's smaller and faster, the examples are more robust, and the docs (hopefully) help new users avoid the many pitfalls in the TinyGPS examples.

A more low-tech solution might be better. For example, a couple of light beams across the doorway to the kitchen. An human would block both of them as they passed, and a dog only the lower one. You could sound an alarm if the lower one is broken, and the upper one is not broken (within a second).

Or do something with infra-red transmitters / receivers. There are lots of Arduino projects using those. You could have a transmitter in the kitchen pointing towards the doorway, sending some code (eg. 1234). Mount on the dog an Arduino with an IR decoder sketch. When the dog enters the kitchen it will get the code, and then you could sound a beeper. The beeper alone might make the dog change its mind about going in, especially if you go after it yelling "bad dog!" every time the beeper goes off.
Since the IR beam is just light, it would only go in a straight line, and if properly positioned would flood the kitchen, but not hit anywhere else.

Proof of concept
I made up a test of my idea of the IR transmitter.
(Please don't report me to the moderators for being off-topic. I know the question was about a GPS, but the real question is how to detect that the dog has come into the kitchen).
You can get IR (infra-red) LEDs cheaply at any electronics supplier (or eBay). They are like normal LEDs except that they transmit in the IR light range. They can also usually handle higher currents, like 80 mA.

Sender
So, to drive that from the Arduino we need a transistor to boost the output from the Arduino pin, like this:

Note that the positive pin of the LED will have a longer lead. The positive pin goes to the 39 ohm resistor, and the negative (shorter) lead goes to the transistor collector. In the schematic the negative pin (cathode) is at the bottom and has a horizontal line (think of the horizontal line as a minus sign).
The 39 ohm resistor limits current through the LED to 74 mA. Assuming a LED forward voltage of 2.1V we have:
 (5V - 2.1V) / 39Ω = 74 mA

The 470 ohm resistor limits current through the transistor base.

Sender code
Then some simple code to send a IR code (using PWM modulation like TV remotes do). There is a library for that, so the code is very simple:
#include <IRLib.h>

IRsend My_Sender;

const unsigned long DOG_ALERT_CODE = 0xBADA;

void setup()
  {
  }

void loop()
  {
  My_Sender.send (NEC, DOG_ALERT_CODE, 20);
  delay (1000);
  }

That sends the code 0xBADA (which I just picked at random) every second using the NEC IR protocol.
The objective would be to have this plugged into the power somewhere in the kitchen, and aimed at the doorway. The IR library uses digital pin 3 (on the Uno at least). That happens to be the Timer 2 "B" output to send 38 kHz PWM (pulse-width-modulated) signal, which it interrupts from time to time to encode the code into it.

Receiver
Now we need something on the dog to detect the IR code. The objective is to notice the code above (eg. 0xBADA) and if found, sound a tone on a speaker, otherwise ignore it. That way we can still use remotes in the kitchen, and the speaker won't sound.

The code for the receiver is a bit more complex, but not much:
#include <IRLib.h>
#include <TonePlayer.h>

const byte SPEAKER = 9;  // output pin is fixed (OC1A)
const byte IR_READER = 11;
const unsigned long BEEP_WIDTH = 50;
const int BEEP_FREQUENCY = 880;  // Hz
const unsigned long DOG_ALERT_CODE = 0xBADA;

// pin D9 (Uno), D11 (Mega)
TonePlayer tone1 (TCCR1A, TCCR1B, OCR1AH, OCR1AL, TCNT1H, TCNT1L);

IRrecv My_Receiver(IR_READER);
IRdecode My_Decoder;

void setup()
  {
  My_Receiver.enableIRIn(); // Start the receiver
  pinMode (SPEAKER, OUTPUT);
  }

unsigned long lastTone;

void loop()
  {
  if (My_Receiver.GetResults(&My_Decoder))
    {
    My_Decoder.decode();
    if (My_Decoder.decode_type == NEC)
      {
      if (My_Decoder.value == DOG_ALERT_CODE)
        {
        tone1.tone (BEEP_FREQUENCY);
        lastTone = millis ();
        }  // end of wanted code
      }  // end of NEC type
      My_Receiver.resume();
    }  // end of if we got a result

    // if time up, stop the beep
    if (millis () - lastTone >= BEEP_WIDTH)
      tone1.noTone ();

  } // end of loop

This also uses the IR library, this time to detect an incoming code. You wire the "Data" pin of the IR detector to digital pin 11 on the Arduino (Uno or similar). The other two pins of the IR detector go to Ground and +5V as marked.
To play a sound get a small piezo speaker and wire that to digital pin 9 (one side) and Ground (other side).
Because of the way that the IR library uses interrupts, I had to use my own Tone library to generate a tone. You can download that from:
http://www.gammon.com.au/Arduino/TonePlayer.zip

Testing
How well did it work? Certainly at short distances (like three feet or one metre) we got a positive result. There could be variance based on the light conditions in the room, and the exact parts you get.
You might want to read the design notes for TV B Gone where they discuss the technicalities of sending IR beams. In particular for their design they used four IR LEDs to give adequate range. You could add more LEDs by duplicating the transistor driver shown above a few times. In other words, duplicate the transistors, LEDs and resistors. They could all be driven from the same output pin.
As mentioned in the TV B Gone article, you can get different IR LEDs. Some have a narrow beam, but go further, others have a wider beam, but go less far.
Also you could arrange them to point in slightly different directions to cover more of the room.
You could also change the length of the beep when the code is detected (BEEP_WIDTH) in milliseconds. And also the frequency (BEEP_FREQUENCY) which I had at 880 Hz. A higher frequency might annoy the dog more but be less audible to humans. I suppose it depends if you want the dog to hear it or the people in the house.

Hardware size and power
You probably want a small Arduino (like a Nano) which is physically quite small. Also powering it could be an issue. You could get 3 x AA batteries, which would nominally output around 4.5V, and connect them directly to the +5V pin of the Arduino.
To save battery power you could have the Arduino sleep for (say) a second, wake and eheck for a code, and then sleep again. See my post about power savings for more details about that sort of thing.

Hardware photos

I needed the GPS coding but thank you for it. Could you help me with the GPS coding and how to set up the buzzer?

There are many posts by people who have connected a GPS to an Arduino. Asking to "provide code" goes beyond the scope of this site. We are here to answer questions, and be helpful as much as we can. Writing code from scratch isn't really our purpose. If you find code and have trouble getting it to work, by all means ask about that. I would find something that gets the current position, work out what that position is, for the kitchen, and then detect if you are in the kitchen or not.


text:
how to implement PWM LED fading into a random case switch?
Ive recently bought my self a arduino Mega 2560 and managed to get a sort of RANDOM function to work with different cases which go of by the number selected.
My question is is there a way to also make a PWM sequence in such a case? so that the LED is fully light to dark and then the the next case starts?  IS there a more random sequence wich i could then also expand if neccesary?
Mark.
int ledcolor = 0;
 int a = 500; //this sets how long the stays one color for
int b = 2000;
int brightness = 255;    // how bright the LED is
int fadeAmount = 25;    // how many points to fade the LED by

 void setup() { //this sets the output pins

 pinMode(11, OUTPUT);
 pinMode(10, OUTPUT);
 pinMode(9, OUTPUT);
 pinMode(8, OUTPUT);
 }

 void loop() {
 int ledcolor = random(1,16); //this randomly selects a number between 1 and 15

 switch (ledcolor) {

 case 1: //if ledcolor equals 1 then the led on pin 11 will turn on etc.
 analogWrite(11, brightness);
 brightness = brightness - fadeAmount;     break;
 case 2:
 digitalWrite(10, HIGH);
 delay(a);
 digitalWrite(10, LOW);
 break;
 case 3:
 digitalWrite(9, HIGH);
 delay(a);
 digitalWrite(9, LOW);
 break;

Research this, but I believe the Arduino library random function returns the same set of (pseudo) random numbers after each power up.  If this is a problem you can research if you can seed the Arduino random number generator.  However, finding a (always changing) starting seed (with out something like a RTC or Temperature sensor) is difficult in an embedded environment.

What are you actually trying to do? Are you trying to set random brightness on 4 LEDs? Or is the aim more complex?

@gbulmer my Goal is to have many different cases wich are going to be set of random with different LED effects for Simulation a firework on my Model Traintrack. and some of those fireworks should also be able to fade from 255 to 0.

In order to fade in and fade out LEDs you need to use PWM feature. And, specifically you need to use the analogWrite() function call. Also, you need to make sure all your LEDs are connected to PWM port pins.  Port pins which support the PWM feature for various Arduinos are listed in the above link.
In your code you might try replacing your 500ms delay with a count up followed by a count down loop.  Each loop should contain the appropriate delay and count up or down to the appropriate value.
For instance, you might try a 1ms delay and a count from 0 to 255 followed by a count from 255 to 0.  In both loops just before or just after calling the delay() function, place the call to the analogWrite() function and pass the counter value as the PWM duty cycle (LED brightness setting).
added later...
For example, you might try to see if this code works for the 1st case statement:
int brightness_level;

case 1: //if ledcolor equals 1 then the led on pin 11 will turn on etc.
  for(brightness_level = 0 ; brightness_level < 255 ; brightness_level++)
  {
    analogWrite(11, brightness_level);
    delay(1);
  }
  for(brightness_level = 255 ; brightness_level >= 0 ; brightness_level--)
  {
    analogWrite(11, brightness_level);
    delay(1);
  }
break;

thank you for the quick help i now have changed the Code but the led does not fade bevor the next case which is randomised beginns even tho i made the delay time longer. (see my changed Code pls) Mark

Not exactly what I had in mind.  In each case segment of code use two for loops. The first should count from 0 to 255.  The second should count from 255 to 0.  In each loop there should be a 1ms delay and a call to analogWrite passing the pin number and the current loop value.  Make sure the pin used for your Arduino supports the PWM feature!

would there be a possibility fopr you to do an example for me im not quite shore what u mean. and it should be only counting down from 255 to 0 and then the next random case Shell start.

I added an exmple to the answer. I haven't tried it so errors might have snuck in.  Try it.  Make sure pin 11 on your Arduino supports PWM.

thank you. Great now I know what u meant with the for loop.

ive just uploaded it onto my arduino but somehow the LED is not Fading ist flashing. what could i doo that it fades from 255 to 0n and then the next case starts? @st2000

Double check the code (I seldom write perfect code on the first go).  Also, you need to do this for all case statements, for all the LEDs.  I just gave you the fist as an example.

To make a completely "non blocking" system you need to change your thinking somewhat. Instead of thinking "A need to fade from X to Y" you instead need to start thinking "I am at brightness X at the moment. I want to get to brightness Y. What do I need to do to get there?".
For instance, you might have a loop() than contains a structure like:

My target brightness is Y
My current brightness is X
Is X equal to Y?

Yes:

Select a different target brightness to get to

No:

If my current brightness is below my target brightness then make it brighter.
Otherwise make it dimmer.

You can introduce a small delay to slow the fading down, or use millis() to only run that structure at pre-defined intervals (like BlinkWithoutDelay does) to get your desired fade speed.


text:
is it possible to code microservo automatically stop when the speed of rotation getting slower?
my group is doing a project which call automatic bed maker. we want to use a servomotor to pull the sheet of the bed. can we possibly make the servomotor stop rotate when the speed of rotation decrease? or is there any way to make the servo motor automatically stop beside using timer.
sorry for broken english.

Not without feedback to the MCU.

Is this a very small model to show the idea? What is causing the speed of the servo to slow down? A standard microservo is only going to have a very small movement, and it is easier to get information from a DC motor with motor drive than from a continuous rotation servo.


text:
How would you send clock impulses to a camera with an Arduino Mega?
Hardware newbie here and I need to know how to connect my TSL 1401 line scan camera to an Arduino Mega so that I can send it the needed impulses. The Mega has a hundred different sockets and the Schema just scared me when I looked at it.
I just want to know which socket I can connect to the CLK and SI ports of my camera so that I can get and an analog output of pixels.

Please [edit] your question to include a link to the datasheet of the TSL 1401 and the schema of the arduino mega that you are using.

Is this related to this question?

It depends on the camera that you're using but you send in impulse just sending digital write signal, waiting a little bit and then turning it off. You do this over and over again until you have all the pixels. Here is an example where I send 128 impulses:
  for(int i = 0; i < 128; i++)
  {
    digitalWrite(CLK, HIGH);
    delay(1);
    digitalWrite(CLK, LOW);
    delay(1);
  }

Depending on the hardware you are using you might have to send a SI (signal impulse) prior to the CLK impulses and the delay in between them will vary. The best thing to do is to read the documentation to find these figures.


text:
Debugging with an ATtiny?
I have an ATtiny hooked up to two line scan modules. I'm sending digital signals to the line scan modules then receiving the analog output and storing it in an array. I have an if statement that will make the LED on the ATtiny programmer blink when the number are below a certain range (meaning that lens is covered).
Here is my code:
#include <SoftwareSerial.h>
const int rx=0;
const int tx=1;

SoftwareSerial mySerial(rx,tx);
int CLK = 2;
int SI = 1;
int Aout = A3;
int Aout1 = A2;

int LED = 0;

int pixelsArray[128];   //Array to hold the values of the individual pixles.
int pixelsArray1[128];

 void outputPixels()
{
  for(int j = 0; j < 128; j++)
  {
    digitalWrite(LED, LOW);

    if(pixelsArray[j] < 100)
    {
      digitalWrite(LED, HIGH);
      delay(500);
      digitalWrite(LED, LOW);
      delay(500);
    }
  }
}

The problem that I am having is that when I test my code with one line scan module it works just fine. You will notice that in the readPixels() I have the statement pixelsArray1[i]=analogRead(Aout1); commented out. However, when I try to use it with two the LED start blinking regardless of how much light is hitting the line scanner.
The strange thing is that EVEN when I comment out the digitalWrite(LED, HIGH); statement in the outputPixels() method...THE LED STILL BLINKS!!!
Since the ATtiny does not support URT and can't use the console in Arduino I have no idea how to debug this. Does anyone here have any clue what is wrong?
Here is the datasheets
ATtiny: http://www.atmel.com/Images/Atmel-2586-AVR-8-bit-Microcontroller-ATtiny25-ATtiny45-ATtiny85_Datasheet.pdf
ATtiny Programmer: https://learn.sparkfun.com/tutorials/tiny-avr-programmer-hookup-guide/?_ga=1.59946280.467360091.1464906372

The ATtiny2313 has only 128 bytes of RAM. Your two pixel arrays, together, need 512 bytes. No way this can work.

Sorry I linked the wrong datasheet. I am using the ATtiny85 which has 512  bytes of RAM.

That's still not enough. Your arrays are eating all the RAM of the ATtiny85, thus corrupting the stack.

If I am reading the ATtiny datasheet correctly then I have a total of 512 bytes of RAM. Meaning that u should have enough space for two 128 arrays. What am I missing? Sorry if I'm being stupid, but I'm really outside of my field right now.

Your program needs RAM for storing all its globals (in the “data” and “bss” sections of the RAM), and the return addresses for the functions you call (“stack” section). You cannot allocate all the RAM to your arrays and expect it to work.

Since you do not have enough RAM for your arrays, something has to
give. A few options:

Do you really need the 10-bit precision of the ADC? If you can live
with 8 bits, then use 8-bit arrays (type uint8_t) and store only
the 8 most significant bits of each reading
(pixelsArray[i]=analogRead(Aout)>>2). This will make the arrays
half as big.
If you really need 10-bit precision, maybe you do not need 128-pixel
resolution? Then you could store only every other pixel. This will
also halve the array sizes.
If you do need both the full precision and the full resolution, then
you will have to pack the bits tight. You can pack up to 4 readings
in 5 bytes. But this will increase the complexity of your program.

Addendum: To declare the arrays as being made of 8-bit integers,
just replace
int pixelsArray[128];
int pixelsArray1[128];

by
uint8_t pixelsArray[128];
uint8_t pixelsArray1[128];

Here “uint8_t” means “unsigned 8-bit integer”, whereas “int” is a
regular integer, i.e. signed and, on the AVRs, 16-bits long.

These are pixels so I don't need a lot of precision, but how can I use 8-bit arrays? Do I just add the >> like you said or do I need to change it in the declaration? Also doesn't each integer take up 2 bytes?

@FortunaIwasaki: You have to change the declaration also. See the amended answer.

Thank you so much for your help, but could you also explain what you meant by "pack the bits tight"? How can you keep the same number of pixels and still store them as integers, yet use less space?

@FortunaIwasaki: By using bitwise operations, you can manage the storage at the bit- (instead of byte-) level. Then, you would allocate 10 bits per pixel, which amounts to 2560 bits (320 bytes) for the 256 pixels.

According to the Specs of the Attiny, this microcontroller only has 128 bytes of memory (RAM).
In the code you declare two arrays:
int pixelsArray[128];   //Array to hold the values of the individual pixles.
int pixelsArray1[128];

which will occuppy much more memory than the available on this microcontroller.
Try to reduce the size of the array. Each int entry occupies 2 bytes according to the link.


text:
Motor control using arduino board
I want to control 2 dc motors using the arduino board directly. One motor must rotate clockwise and the other counter clockwise. The directions  doesn't change only the speed of each motors. Can this be done without any shield? Them motors may need a higher voltage than the arduino can provide. If I link the arduino board to a power source of about 15 V (the board is arduino mega limits between 6 and 20 ) and I use "analog.write()" function can I output more than 5 volts(the internal voltage)?

If you post a link to the motors you are intending to drive, you might get an even simpler solution. We need to know both the voltage and the current, preferably from the motor's datasheet.

Simplest way to do this is two MOSFETs (one per motor, because you don't need to change direction), and some miscellaneous passives, and a flyback diode for each motor.
See this tutorial for wiring diagrams and details.

Great link! You saved me! But I still don't get it. What's the difference between a mosfet and a transistor? I searcher a few more pages and they said a mosfet is a transistor. Does any transistor work?

A MOSFET is a type of transistor. BJTs (bipolar junction transistors) are the other dominant type of transistor, and are not as appropriate for this application. The difference between MOSFETs and BJTs is too much to discuss here, but as far as what you should use: use a logic-level MOSFET (low Vgs(on))

@uint128_t it is syaing that link does not exist