text:
How to directly solder wires to protoshield to connect them to Arduino pins
I bought an assembled Arduino Uno protoshield version 5, similar to this:

I bought it because I would like to solder wires from Arduino IOs, and I was quite disappointed with the impossibility to do so, since the solder points are already taken by the female headers, which are not connected to anything (there are not tracks coming from then to other islands, which I find quite dumb).
I am considering to remove (by desoldering) the headers, so I can access the holes for soldering wires (instead of plugging them to headers), but before doing so, I ask:

Is there a good way to solder wires so they are electrically connected to the Arduino IO pins?

I think they cheaped out when assembling this board. Notice that you can no longer stack any other shields on top, since the female headers are further to the inside. My guess it the board was designed to have stacking headers inserted in the outside row, and have the inside row free for soldering. Those headers are however a lot more expensive.

@Gerben You're absolutely right... I haven't noticed that detail, and since I can not even stack more shields, the very purpose to keep the female headers doesn't make much more sense. One more reason to remove them and use the holes directly (besides having some extra headers to put elsewhere on the board, with a saner ordering). Would you elaborate your comment in an answer? I'd upvote and perhaps accept it!

Instead of soldering wires, consider crimping on male pins compatible with the headers.  Or get silicone insulated wire and neatly solder it where each header pin is soldered to the board - it is admittedly a skill, but develops with practice.

For the signals, get some AWG30 wire and solder them underneath to the female header pads. For power, get some AWG22 or AWG24 wire and solder them to the top of the male header pads.

I did it, but the result is visually and conceptually very ugly, not to mention the wire running under the shield got uncomfortably close to the ATmega exposed metal pins (not terrible, but, c'mon...). Would you risk to suggest why on earth they didn't provide tracks from the pins to any free island? Similar to the triplets found around the center DIP IC area? That would be perfect!

Probably because they figured that everyone would just drop a solderless breadboard in the middle and use the female headers as they normally would.

If you use insulated wire it shouldn't be a problem - hand soldering to a single row at .100" spacing gives you plenty of elbow room compared to what you would have to deal with in reworking more modern electronics, where sub-millimeter pitch (typically 4 to 5 times denser) is the norm.

Accepting the answer because it actually works, but I ended up desoldering the headers (not a pretty work to do). For anyone with intention to solder the wires instead of plugging, there are two good options for the v5 of the board: buying the - by the way cheaper - unassembled kit (and not soldering the female headers) or buying a model with stacking headers.

Other boards bring the header pins to prototype area pins, as I do here
http://www.crossroadsfencing.com/BobuinoRev17/UnoScrewSheild2016.jpg

While disclosed, this is pretty close to "advertising" to fit here

@CrossRoads - It says on your website: "Assembled cards are $21.50 and ship flat rate boxes. Shipping and paypal fee added to all orders." I'm assuming the price is in US dollars, so for Canadians, our cost for one of your shields would be $27.17 CDN plus shipping (USD * 1.31 Exchange rate), plus paypal fee (USD * 1.31 Exchange rate), plus "the big one", duty of approx. 33% in CDN$ (Canada charges it to us on delivery). So, how much is the shipping and paypal fee?

I do all payments in USD via paypal, so I only see USD and paypal I assumes shows you the in-country price.  Shipping to Canada via Priority Mail International® Small Flat Rate Box is $25.95, international paypal fee on the card + shipping is $2.35.  We can fit several in the same flat rate box if you want more than 1.

It looks like you are missing the solder-less breadboard piece for your shield. The shield I bought came with one, and some 2 sided sticky "foam tape" to affix it to the circuit board.

If you use the shield with the solder-less breadboard, then it would be not be feasible to stack another shield on top of it because of the height of the components and jumper wires plugged into it.
I tested my shield and found the same thing you did, the header pins are not connected to any of the connection points on the board. That is dumb indeed.
As CrossRoads mentioned in his answer, there are other options, such as screw terminal shields. They sell them for $2.43 USD on aliexpress.com Screw Terminal Shield.

authors: นรินทร์ โอษฐ์งาม


text:
Assembling a float from an array of bytes
I would like to convert an array of bytes, received from serial, to a float.
Let's consider this exemple. I'm sending 0.12 byte-wise from an Android application. The conversion from float to array of bytes in the Android side is handled by this function
public static byte [] float2Bytes(float value)
    {
        return ByteBuffer.allocate(4)./*order(ByteOrder.LITTLE_ENDIAN).*/putFloat(value).array();
    }

When bytes arrive, they are stored in an array and the assembled.
hiBytew1 = bufferBytes[9];
//Serial.println(hiBytew1);
loBytew1 = bufferBytes[10];
//Serial.println(loBytew1);
hiBytew2 = bufferBytes[11];
//Serial.println(hiBytew2);
loBytew2 = bufferBytes[12];
//Serial.println(loBytew2);
float conAck = assemble(hiBytew1, loBytew1, hiBytew2,loBytew2);

How can I achieve this kind of conversion assuming that bytes are received in the correct order?

Just cast the pointer.
float conAck = *((float*)(bufferBytes + 9));

This needs parentheses around “bufferBytes + 9”.

Right, otherwise it will advance sizeof(float) * 9 bytes instead.

Grazie Ignacio, so it will automatically assemble the sequence in a float variable? Nice

@UserK: It will tell the compiler that the bytes it will be looking at are a float.

@userk there is no assembly. Floats are already stored as bytes in memory. You are asking android to put the 4 most meaningful bytes in the buffer. Then you are trekking arduino to consider the bytes together as a float. If you are to store the same number in memory it week have the same representation. In a nutshell, this is an O(1) operation.

Ok grazie prakharsingh95

source: Stack Exchange

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

sort: votes


text:
Parsing Int over Serial Slow
I am trying to communicate between my PC and Arduino Mega 2560 using this serial library. It works reliably, however I am having trouble passing messages at a high rate over serial. I set the baud to 460800 bps on both systems, and am using a serial handshake. The Arduino reads the values by parsing a string, however during my testing I cannot parse more than ~240 messages per second. Each message into the Arduino is either of the form "r/n" to reset some variables or "0,0,0\n" where in this case the zeroes are the ints I want to parse, these can change. My Arduino code in the loop is as follows:
if(Serial.available() > 0){
  resultString = Serial.readStringUntil('\n');
  if(resultString.equals("r")){
    countEnc0 = 0;
    countEnc1 = 0;
    countEnc2 = 0;
  }else{
    int counter = 0;
    int lastIndex = 0;
    for (int i = 0; i < resultString.length(); i++) {
      // Loop through each character and check if it's a comma
      if (resultString.substring(i, i+1) == ",") {
        // Grab the piece from the last index up to the current position and store it
        write[counter] = resultString.substring(lastIndex, i).toInt();
        // Update the last position and add 1, so it starts from the next character
        lastIndex = i + 1;
        // Increase the position in the array that we store into
        counter++;
      }
      // If we're at the end of the string (no more commas to stop us)
      if (i == resultString.length() - 1) {
        // Grab the last part of the string from the lastIndex to the end
        write[counter] = resultString.substring(lastIndex, i+1).toInt();
      }
    }
    analogWrite(8, write[0]);
    analogWrite(9, write[1]);
    analogWrite(10, write[2]);
  }
  Serial.println(String(countEnc0) + "," + String(countEnc1) + "," + String(countEnc2));
}

I know there are more efficient ways to parse this, however my attempts to use them yield similar results (Using parseInt(), char*, etc). Additionally, I am using 3 interrupts to read sensor values and store them in variables here, and writing the values I acquire to the PWM. As long as I can read and send up to 1000 messages per second that's all I need for now. Many thanks...been banging my head against the wall on this one.

Yup, parsing is slow. Use raw binary whenever possible.

If you are getting ~240 message/sec, comment out your for loop and see what the maximum throughput might be is the cost of processing your data were 0.  That would be an interesting number to hear from you and would then give us a base line on your expectations.

First off, I would recommend  strtok or even getline to parse comma delimited strings.
Secondly, I'm pretty sure no PWM is responsive enough for 1000 updates per second. But for other purposes this data rate might be needed.
To do this, build a custom cache that does the following:

Reads 1000 characters per go, if available, or less.
Parses on the go. From this set up callbacks to you PWM class, so that you can set PWM values while parsing.

Why this? I am not convinced that the sluggishness is due to the for parsing data. More likely, it's because you are processing every instruction as you get it.
1000 serial reads with 6 length for loops over strings (your case) will be significantly slower than 1 serial read and a 6k length for loop.

The String class is slow. I would get rid of that first. I am confused about whether you are sending or receiving, or both, as your code seems to parse and then send. See this test code here:
int countEnc0 = 123;
int countEnc1 = 456;
int countEnc2 = 789;

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();

  unsigned long start = micros ();
  Serial.println(String(countEnc0) + "," + String(countEnc1) + "," + String(countEnc2));
  Serial.flush ();

  Serial.print ("Time taken = ");
  Serial.print (micros () - start);
  Serial.println (" uS");
  }  // end of setup

void loop () { }

That replicates the time taken for that one line which echoes the three figures. My results were:
Time taken = 1632 uS
OK, yours will be faster at the faster baud rate, but only 4 times as fast.
So, 240 times that and allowing for the faster baud rate gives:
1632 * 240 / 4 = 97920 µS

That's a fair bit of that second gone (a tenth), without even parsing anything.

If your bottleneck is really in the parsing (and you should confirm this before you spend any effort to optimize it), eliminate the parsing.
I usually recommend sending ASCII strings on serial channels to make debugging simpler, and I'd still suggest you get everything working this way first, even if you can't make the sample rate you need.
Once you're convinced your system works except for its speed, you can replace the ASCII communication with raw binary. A simple protocol would suffice: 3 or 6 bytes (do you need int16_ts?) of data and a 1 byte checksum downstream, and an ACK / NAK byte upstream to trigger a resend if needed, will probably be more than sufficient.
The receiver would only have to confirm the checksum and process the already ready-to-go binary sample values.

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


text:
Due ADC specs: full power bandwidth
I'm trying to compute Johnson resistance noise in a simple resistor circuit. However, since all frequencies contribute equally, I am getting an answer of infinity.
It then dawned upon me that the Arduino ADC probably detect frequencies larger than some cut off given by something called the full power bandwidth. Does anyone know this spec for the Due?

Does Arduino.cc not have the specs you need?


text:
Write with SD card; flush versus close?
I've got an application that requires moving to specific points on a file on an SD card, reading, modifying and then writing an update.  The file is fixed size.  The code has no problems moving to the specific offsets required and then reading in blocks of data.
However, when the code does a seek() to the next desired location, then a write() and a flush(), the data is not written.  If my code seeks back to the start of the block just written and reads it back, it does not contain the new data.
The file is definitely open for writing, and the write operation indicates it wrote all the bytes.  No calls are indicating any error.
Since reads and seeks are working I'm assuming this is not a problem with wiring of the device to the Arduino Mega.  The files range from around 100K to almost 2M each, and the code needs to access the entire content of the file, but almost never sequentially.  Writes are almost always non-sequential as well.
Is it necessary to do a close after each write instead of the flush?
Does anyone have any suggestions of things I should be investigating?
Bob

What filesystem layer are you using?

I'm using the File layer.  Ie, File myfile;  myfile.open(), myfile.seek(), myfile.write(), etc.

I just ran an experiment where the code seeks to a record in the middle of the file, writes a new record and then closes the file.  Next, it re-opens the file, seeks to the record and reads in back... the changes are not there.

Can u post example of your code?

This may sound trivial, but did you check if write protect is enabled? I'm not familiar with the library your using, but from the information I gleaned from a  quick google search, it seems like it simply returns the number of bytes written. In some file systems, the number of bytes written doesn't always mean that it was a successful write. It could just mean that x number of bytes were written to a buffer, pipe, or whatever.


text:
Free simulation software for arduino hardware
Hi there i am a beginner and trying to pair some sensors with my arduino. I am looking for some software which will allow me to test my codes in virtual machine also it should be free ...thax in advance


text:
Why the bootloader burn on ATmega328 rather than Atmega16U2 in Arduino Uno
I have been researching about the reason why we have a second MCU in arduino UNO for a while now. finally i understood that its been use as  USB to serial converter. the question that really bug me now, why is the boot-loader is burn on the main ATmega328 not Atmega16U2 ?

The purpose of the bootloader is to get the firmware through the serial
port and burn it into the flash. The 16U2 has no access to the 328's
flash. The job has to be done in the 328 itself.

The normal AVRProgrammer dose not require a bootloader  to burn the code to any  ATmega, why then the Atmega16U2 need the help of the bootloader ?. cant just do the job as any other AVRprogrammer ?

It probably could, but it would need to be connected to more lines of the 328, it would also need more complex firmware, doing double duty of USB to serial interface and ISP programmer.

@Akkilah: It is also worth noting that the 16U2 replaces an FTDI that was used in previous versions of the Arduino board.

so the more complex firmware that  need to be used, it will be used in the 16U2 not  the 328 , did I understood u correctly ?

worth nothing ( the replacement of FTDI with 16U2 )  in sense that we will still need the use of boot loader and there is no advantages that happen because of the replacement  ?

You understood correctly. The only advantage of the 16U2 is that you can reprogram it via ISP if you want to emulate, say, a mouse or a keyboard. A Leonardo would probably be more convenient for that, though.


text:
How to measure direction the car is coming to garage door?
my garage door is pretty narrow, about 10 cm (4") on each side of my car's rear mirrors. So every time I drive to garage, I need to go very slowly because I am afraid I might not be lined up correctly.
I am thinking about using Arduino and some sensors to help me. Output is pretty simple, just two leds, one for each side, showing me if I should turn little right or left to have perfect lineup to center. This I can handle with no problem
What I am asking for is idea how to measure the alignment of my car. I know how to use ultrasonic sensors for measuring distance. But I am not sure they are suitable for this project, because I want preferably to put arduino and sensors in my garage, not in my car.
Any idea how to work this out ?

It is very hard to determine position accurately there is a new project on kickstarter called Pozyx, you can look at that but that's expensive, to be honest this sounds like a job for hanging tennis balls or strings or something like that. But if you have a lot of money to blow and you just want a project go for it, you may be able to do this with ultrasonic sensors but I reckon that would be painful. Anyway good luck

It seems like an ultrasonic sensor on each door-post should do it. You need, I'm guessing, 30cm to the sides of your car as its nose enters the doorway. Smooth the sensor reading, compute a difference and display the sign of the differences as right/left lights. Keep a small dead-band around zero-difference or you'll drive the driver crazy!
Do Ultrasonic sensors have the range and accuracy you need for the job? Time for a feasibility study.
Update:
Is 10cm plus the length of a mirror = a couple of feet? But even if so, you have to keep to +/- 10cm of the centerline to prevent striking the mirrors, so you could project your sensors out into the doorway by an amount the still keeps them > 10cm away from the car. You could mount them hinged (like the mirrors are) and padded to limit any damage from the occasional accidental touch.

I am little afraid, that general ultrasound sensor SR04 will not be useful, because of its wide angle. It might work when the car is pretty close to sensor but it will get false readings when the car is far from the sensors (couple of feet). So I would have to slow down or stop anyway, which is the problem I want to avoid with this project :-)

Try to place two distance ranging sensors like ultrasonic or active infrared at the sides of the driveway or garage door. Make sure that their readings are similar so that you know that you are in the center. If one has a higher reading(farther distance) light an led to your right so you know  to go that direction and vice versa. Use communication through xbees, bluetooth, or something similar.


text:
What is GND on board?
I've looked in several places, and so far can not understand to want to be the GND who is on the board.
There is this documented anywhere?

It is the 0V reference for everything else, as well as the power supply return.
"Ground (electricity)" on Wikipedia


text:
Handle reading timing in Python using pySerial
I'm not sure about how to properly handle timing readings from serial inside a Python script. I need to read a value every 5 seconds.
From Arduino I could do,
Serial.println(value);
delay(5000); // should I wait here?

Inside Python script I could do,
import serial
import time

arduino = serial.Serial('/dev/ttyACM1', 9600, timeout=5) # should I set timeout?

while True and arduino.isOpen():

    try:
        value = arduino.readline().strip()
        print value

        time.sleep(5) # should I wait here?

    except KeyboardInterrupt:
        print "\nClosing..."
        arduino.close()

EDIT: Apart from that, the first reading is always wrong, like if there was something in the reading buffer.
I've found out that to solve that I should add arduino.flushInput() just after opening the port.

Do you need to "read a value every 5 seconds" or "transmit a value from the Arduino to the host every 5 seconds"?

Arduino is writing values to the serial, and I'm reading the serial inside my python script.

Yes, we all get that. What we need to know is which one needs to be in control of the timing.

Sorry, thanks for replying. I'm not sure which, what is the proper way to do this simple stuff? I mean, my sketch just sends temperature values, it's the only thing it does. My python script would read those values and print them every 5 seconds.

Does it just keep sending them as quickly as possible, and the Python program is supposed to only display the ones that show up every 5 seconds?

Well, that should be an option. Another I think would be that Arduino sends every 5 seconds and Python is always listening, waiting for that value. Which one should be better?

The answer is that it depends on what you are actually trying to accomplish. If there is nothing else to be done on the Arduino then it is fine to have it sit and wait; on the other hand if there is nothing else for the python script to do then it is fine for it to sit and wait, but there is no reason for both of them wait.
Arduino delays
You don't need to deal with the timing delay in python if the Arduino is delaying. According to the documentation readline will wait until it has received a value or until the timeout is reached. That said, I would make the timeout slightly longer than the delay on the Arduino side of things.
Note that readline will block your program from doing anything else while it waits. As such, It is pretty useful to explore python threading when you are writing a program which collects data over a serial stream unless the program is only collecting data.
Python sleeps
If there is other stuff to be done on the Arduino (perhaps if you are doing some filtering of the temperature data using the Arduino so as to reduce noise) then it might make more sense for it to push data to the serial stream at the end of each loop, and for the python script to only read the data every 5 seconds. In this case you could have python sleep and use no delay (or a shorter delay) on the Arduino. You can achieve this behavior without resorting to using sleep by using a timer object to periodically call a function that opens the serial stream (possibly flush it), reads the data, processes it, and closes the serial stream.

Thanks! There was another factor in my Python script, and that was the while True statement. In this simple example, it doesn't matter what timeout value is because readline would be called again on the next loop. However, I guess I should notice that readline is blocking everything else in my script, if there was another thing to do.

I was considering the (remote) possibility of your Arduino and computer being perfectly synchronized, such that the readline times out after reading half of the line, and then immediately reads the second half of the line on the next iteration of the loop. This is an admittedly far-fetched possibility, but by making your timeout longer than 5 seconds you limit the likelihood of it.


text:
How to simulate Arduino?
QUCS is the only open source software which offers simulation (and designing PCB layout [in future]) of electrical circuits. But the problem with QUCS is that it is under development and many important features are not yet available in it.
I want to simulate Arduino Uno board in it for my circuit. Does anyone know how to simulate Arduino or any other micro-controller in it?
P.S. Also any other open source software for simulation and PCB designing?

You don't usually simulate an Arduino. You simulate the types of things you're connecting to it.

Oshonsoft have a great AVR simulator. You will be hard-pushed to find an open source Arduino board simulator - especially as the board is nothing more than a crystal, power supply and user-friendly connectors. Hence the need for something that simulates the microcontroller at the specific board's core. The Oshonsoft simulator has almost everything you need to test code, and includes a full list of all registers and their values, viewable instruction by instruction. It's not free, but (in my view) the best you can get for your money.

If open source is a strict requirement than you can look at KiCAD for PCB design. You probably won't find a single piece of software that does both simulation and PCB design well.

I think Labcenter Proteus is the best option to simulate an Arduino with miscellaneous Digital & Analog circutry so far...

I'm confused this (wrong) answer is not corrected. KiCAD is mature open source EDA, with circuit simulator (SPICE) and pretty decent library of components - so you are not limited to passive circuits.

Simulating a microcontroller's program is common, but not as part of a circuit, unless you're into Systems on Chips.
Model the micro interfaces and simulate the peripherals separately
Analog systems cannot be modelled accurately by hand calculations alone, therefore simulation is often a necessary step (on top of that, real circuits might behave differently from the model). Non-programmable digital systems are deterministic in their behaviour, but only if the interfaces are correct - tight specifications on impedances and such often mean simulation is required here as well. Generally speaking, for both simulation becomes a must when the system is not dead simple. Microcontrollers on the other hand are sufficiently deterministic not to require any simulation: they do what they're told, except in very very very rare cases (single event upsets from radiation for example). Now, what they're told might allow glitches to happen, but that's a different story*. Therefore, usually the analog, or digital circuits around a microcontroller would be given equivalent interfaces based on the microcontroller's behaviour and physical specifications, and simulated separately.
*: As the code becomes more and more complex, it gets more and more difficult to follow what the microcontroller might do. Unexpected glitches may arise from e.g. concurrent access (though I can't say this is common in the micro realm), or insufficient resources (that is why dynamic allocation [malloc,new] are highly discouraged, so that the resources allocation is known at compilation time) etc. That's usually why tests are required, and step-by-step debugging is used as a means to locate any error that arises. But inherently, microcontrollers are highly predictable and except in certain cases, it is not worth it to go through simulation (do not mix up simulations and tests, tests are always required!).
Advantages of microcontroller simulators
However, microcontrollers simulators do exist. They are particularly helpful to watch what happens inside the microcontroller when the code executes step by step: call stack, watches on variables, interrupt vectors etc. This can also be done on the actual hardware using in circuit debuggers, but simulators are cheaper and are also good to save on EEPROM erase/write cycles and to avoid damaging your micro if you are afraid that the devices around it might be incorrectly configured (some controllers are very expensive, especially if they are qualified for medical, military or aerospace applications). I have seen such ICD's and simulators for Microchip PICs (MPLABX), but there must be equivalents for AVR (the micro which is on the Arduino's), or perhaps even integrated in an arduino-friendly environment (though I doubt it). You might want to take a look here.
If you've got deep pockets: mixed signal simulators
Finally, there are mixed signal simulators which allow you to simulate analog, programmable and non-programmable digital circuits alike; one component will have an analog SPICE model, another a VHDL model, and ADC/DAC blocks will be added automatically by the simulator between those devices depending on the logic input/output technology you specify. Those are extremely expensive (the one I used is Cadence Virtuoso), you don't want to do that unless you're doing an integrated circuit or something critical.
P.S: DesignSpark PCB v3 has LTspice in it. Never tried that feature in there though, I used to use LTspice directly.
Note that your opening "QUCS is the only open source software [...]" is wrong. There are plenty of simulators out there which are open source. I agree QUCS is a very user-friendly one though.

Downvoted for opening your answer by lambasting the user for not knowing stuff.

True, I could have worded that better and not start with this. I am not judging what the author knows though: I just couldn't leave the author say such things as if they were a fact whereas a quick look online could have shown the opposite. People are reading. I have modified my answer to make it more like a note.

Fair enough then. I'm not sure I agree that "Microcontrollers on the other hand are sufficiently deterministic not to require any simulation", though - programs are deterministic, but we still test them.

Good point. There comes a time when determinism alone is not enough to ensure a program works properly: generally when it becomes complex (or if there may be synchronisation issues), or hogs lots of the controller's resources etc. I'm editing my answer to make it clearer.

Gets a +1 from me, then. :)

You can use 123d.circuits.io for simulation and PCB design for Arduino circuits.
See this one for example.
More generally, a previous answer states that Microcontroller based circuits are not simulated. Maybe that's true when prototyping costs are low (though I doubt it), but in an SoC or complex embedded system, microcontrollers certainly are simulated as part of the overall system.
Sometimes as a highlevel model such as a symbolic simulator or sometimes as a part of the overall mixed-signal simulation environment in which the digital part is usually simulated at RT level.

Either you haven't read my answer entirely, or my answer is not clear enough. There is a progression in it: first section is "for usual DIY projects", the second "when projects get bigger", the third "when requirements are tight and integration is extreme". 123D reminds me of fritzing, I didn't know it did Arduino simulation as well as schematic to wiring; interesting. I hated fritzing, but definitely interesting for those who like it. +1.

See my blog which will explain all steps at http://tutorial4you.weebly.com/blog/arduino-simulation-on-proteus

To add to the list of simulator answers, try out Micro-Cap 12. It was a few thousand dollars originally, but the company has ceased operations now and has provided it for free. Pretty cool.

How to simulate Arduino? What is the best Arduino simulator?
Following are the main features of the wokwi arduino simulator
It is free :)
• Supports multiple file projects
• Supports most of the famous Arduino libraries
• Whatever compiles on the Arduino IDE will compile on the simulator
• Supported by all browsers
• Compiles with latest Arduino IDE
• Supports FastLED and many other peripherals
• No download or installation needed
• Easy to share the code and project with just a single click
• Smart - Code Autocompletion, Code auto-formatting are supported
• Provides standard library demo examples
• Project can be compiled on RUN on Mobile browsers as well
• Tries to be closer to real circuits – Example – Button bounce like in real hardware
• Supports Arduino Mega, Arduino Nano, Arduino UNO, ATtiny85
• Supports assembly instruction execution
• Provides LED power and FPS features for FastLED projects
• Supports a plethora of Arduino peripherals for the project – Ultrasonic sensors, Slide switches, NeoPixel matrix, Potentiometer, Servo motors, SSD1306 OLED displays, temperature and humidity sensors, rotary dialer, membrane keypad and more
• Serial monitor is supported as well
Website: https://wokwi.com
Here are a few examples

Try this: simulIDE
Google: simulIDE for arduino picture
Supports also: PIC, ATtiny, ATR, Arduino...

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


text:
ESP8266 wifi module sending data via jQuery
Hey all I have the ESP8266 module and I have already set it up and it's working good. However, when I run this HTML page code here:
<html>
    <head>
        <title>ESP8266 LED Control</title>
    </head>
    <body>
    <button id="6894" class="led">Toggle Pin 13</button> <!-- button for pin 13 -->

    <script src="jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $(".led").click(function(){
                var p = $(this).attr('id'); // get id value (i.e. pin13, pin12, or pin11)

                $.get("http://192.168.9.60:80/", {pin:p}); // execute get request
            });
        });
    </script>
    </body>
</html>

I have to send the number 6894 instead of 13 because for some reason its not sending out the correct number. If i send 13 then what it receive is 114. When i send 6894 i receive 689.
My arduino code is this:
*/
//====================================================================================
//                                [The SSDI of the current wifi router]
//                                |              [The password of the current wifi router]
//                                |              |
//                                V              V
String SSIDandPW    = "AT+CWJAP=\"xxxxxxwifi\",\"xxxxxx123\"\r\n";

//                                      [The STATIC IP of the wifi module]
//                                      |                [The main IP of the router]
//                                      |                |              [The default submask]
//                                      |                |              |
//                                      V                V              V
String eIPrIPmask   = "AT+CIPSTA_DEF=\"192.168.9.60\",\"192.168.9.1\",\"255.255.255.0\"\r\n";
const int ledDimmer = 5;         // Used to dim the LED strip (digital Pin 3)

SoftwareSerial esp8266(9,10);    // Pin D10 to=> TX on ESP8266 | Pin D9 to=> RX on ESP8266
//================================= End define WiFi Module =================================
//==========================================================================================

void setup() {
  Serial.begin(19200);

  pinMode(13, OUTPUT); //Just for a wifi demo from html page

  //================================ Start Setup WiFi Module =================================
  //==========================================================================================
  esp8266.begin(19200);
  sendData("AT+RST\r\n",                    2000, true); // Reset module
  sendData("AT+CWMODE=1\r\n",               2000, true); // Configure as access point
  sendData(SSIDandPW,                       5000, true); // Pass of current wifi
  sendData("AT+CIPMUX=1\r\n",               2000, true); // Configure for multiple connections
  sendData("AT+UART_DEF=19200,8,1,0,0\r\n", 2000, true); // Set baud of COM
  sendData(eIPrIPmask,                      2000, true); // Default network mask IP
  sendData("AT+CIPSERVER=1,80\r\n",         2000, true); // Turn on server on port 80
  sendData("AT+GMR\r\n",                    2000, true); // Get firmware version
  sendData("AT+CIFSR\r\n",                  2000, true); // Get ip address
  Serial.print("Server is now running!");
  //================================ End Setup WiFi Module ===================================
  //==========================================================================================
}

void loop() {
  //=========================================== Start Loop WiFi Module ===========================================
  //==============================================================================================================
  if(esp8266.available()) {                               // check if the esp is sending a message
    if(esp8266.find("+IPD,")) {
      delay(500);
      int connectionId = esp8266.read() - 48;             // subtract 48 because the read() function returns

      esp8266.find("pin=");                               // advance cursor to "pin="
      int retunedNum = (esp8266.read() - 48) * 100;       // get first number (example: 123.. this would be "1")
      retunedNum += (esp8266.read() - 48) * 10;           // get second number (example: 123.. this would be "2")
      retunedNum += (esp8266.read() - 48);                // get last number (example: 123.. this would be "3")
      String closeCommand = "AT+CIPCLOSE=";               // make close command
      Serial.print("returned: ");
      Serial.print(retunedNum);
      Serial.print("----------");
      closeCommand += connectionId;                       // append connection id
      closeCommand += "\r\n";
      sendData(closeCommand,                250, true);   // close connection
      //digitalWrite(retunedNum, !digitalRead(retunedNum));   // toggle pin
      if (retunedNum == 6894) {
        Serial.print("OFF");
        digitalWrite(ledDimmer, LOW);
      } else if (retunedNum == 6904) {
        Serial.print("ON");
        digitalWrite(ledDimmer, HIGH);
      } else if (retunedNum == 689) {
        digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
        delay(1000);              // wait for a second
        digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
        delay(1000);              // wait for a second
      }
    }
  }
  //============================================ End Loop WiFi Module ============================================
  //==============================================================================================================
}

//                     [The data/command to send]
//                     |                  [The time to wait for a response]
//                     |                  |                [Print to Serial window (true = yes | false = no)]
//                     |                  |                |
//                     V                  V                V
String sendData(String command, const int timeout, boolean debug) {
  String response = "";
  long int time   = millis();

  esp8266.print(command);          // send the read character to the esp8266

  while((time + timeout) > millis()) {
    while(esp8266.available()) {
                                   // The esp has data so display its output to the serial window
        char c = esp8266.read();   // read the next character.
        response += c;
    }
  }

  if (debug) { Serial.print('Returned: ' + response); }
  return response;
}

And the console output is this:
14880AT+RST

OK
14880
"qXÑ{ÂB!É
1Â±þ)ÒBÙa
+ò“H!a5)�#)ÒÂia%YakN‘ J!ÐCÊ!�
÷þˆ2ô
ready
14880AT+CWJAP="xxxxxxwifi","xxxxxx123"

OK
14880AT+CIPMUX=1

OK
14880AT+UART_DEF=19200,8,1,0,0

OK
14880AT+CIPSTA_DEF="192.168.9.60","192.168.9.1","255.255.255.0"

OK
14880AT+CIPSERVER=1,80

OK
14880AT+GMR

AT version:0.22.0.0(Mar 20 2015 10:04:26)
SDK version:1.0.0
compile time:Mar 20 2015 11:00:56

OK
14880AT+CIFSR

+CIFSR:STAIP,"192.168.9.60"
+CIFSR:STAMAC,"18:fe:34:9b:4e:68"

OK
Server is now running!

returned: 689----------148804 HTTP/1.1
Host: 192.168.9.60
Connection: AT+CIPCLOSE=0

0,CLOSED

OK

What I really am wanting to do is have a way to send a 10 charater string to the arduino instead of the limited 3 numbers above. I just am not sure what i need to add/modify in order to make it see letters/numbers and only the first 10 that i send.
Any help would be great!

Just do this straight on the ESP8266 no need for an arduino. You should try it as the ESP8266 is not a Wifi add on for arduino but is a controller with wifi.

  int retunedNum = (esp8266.read() - 48) * 100;       // get first number (example: 123.. this would be "1")
  retunedNum += (esp8266.read() - 48) * 10;           // get second number (example: 123.. this would be "2")
  retunedNum += (esp8266.read() - 48);                // get last number (example: 123.. this would be "3")

Your code always expects the pin number to have 3 digits.
In case of 13, it takes a space character as the last digit.
It reads charachters '1', '3' and ' '. Their ASCII codes are 49, 51 and 32. With this, the calculated number is
(49 - 48) * 100 + (51 - 48) * 10 + (32 - 48) = 114.

With 6894, it just uses the first three digits and ignores the last.
For 1 or 2 digit long number you could just pad it with '0' character i.g. "013".
If you want to read an arbitrary string, you should replace the above code with this code:
String retunedStr = "";
for(;;) {
    char c = esp8266.read();
    if (c == ' ')
        break;
    retunedStr += c;
}

And obviously replace
Serial.print(retunedNum);

with
Serial.print(retunedStr);

With this, you should only use letters (A-Z, a-z), numbers (0-9), dash (-) and an underscore (_) for the string.
If you use other characters, you could have problems with the URL character encoding.

This is what i get when sending "testing123".... returned: 0,298:GET

Actually i take that back. I moved the code to a different part and i do get the correct text from what i sent... but now it takes about 21 seconds to show up when it used to be once i clicked the button 1 second latter it was there in the output. If the code looping too much to cause this?


text:
Sketch Upload to LinkIt ONE Timeout
I've just bought a new LinkIt ONE IoT prototyping board, and I'm having trouble getting started with it.
I'm working on a mac. I've installed the LinkIt ONE SDK onto my Arduino IDE as specified in the instructions here: http://labs.mediatek.com/fileMedia/download/5fed7907-b2ba-4000-bcb2-016a332a49fd
When I go to upload my first sketch to my board, the sketch compiles and goes through uploading, but before it uploads, it stops uploading and the Arduino IDE perpetually tells me "Uploading...". When I look at the console below, it's telling me this:
[txd] AT

[txd] AT

[medrv]: Time out call back

[error] time out
[medrv]: Kill timer, event is AT_TIMEOUT

I've read some forums about an issue similar to this on the MediaTek website, but they don't help with the issue on the Mac. The ability to use LinkIt ONE on a Mac is new only this month, so I believe if we come up with a fix for this issue, it will help lots of people in the future who have this similar problem.

I should add that I'm unable to select the specified USB port when I click Tools > Port > (required port specified by MediaTek)

Disclaimer: I do not have access to one of these devices to test this on.
Section 3.4.1 of LinkIt's developer's guide (which you linked to) seems to indicate that it is necessary to install COM port drivers on OS X before you can communicate with the board. The [txd] report is communication from your computer to the board, so it seems like you are never establishing a connection. The suggestions in the developer's guide are as follows:

If you are using a LinkIt ONE development board on Mac OS X 10.10, then a USB driver is required to enable connectivity with and firmware updates on the LinkIt ONE development board. The OS X 10.10 built-in generic CDC ACM USB driver is not compatible with three ports available on the LinkIt ONE development board. The steps to install a custom driver to enable the BROM port for Firmware Updater are as follows:

Extract the content of the zip file available in LinkIt ONE SDK software’s Driver folder (see 2.3.2, “Installing LinkIt ONE SDK”) named MacOS_USB_COM_Driver_BM_xxx.xx.x.zip.

Run the installation package (BMCDCACM_Driver_v115.05.0.mpkg) and click Next to install it.

Wait until driver installation has finished, then restart your Mac.

BROM USB driver installation is now complete and you have access to the MTK USB Serial ports.


text:
Unable to configure Ethernet using Arduino Uno R3
I have purchased an Arduino Uno R3 board and a LAN shield from these locations:

Arduino UNO R3
Arduino LAN shield

I am trying to configure Ethernet using this sketch:
#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
  0x4,0x2,0x45,0x68,0x5E,0x96,0x56
};

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  delay(5000);
  // this check is only needed on the Leonardo:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  // start the Ethernet connection:
  Serial.println("trying to configure ethernet...");
  while(Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP, retrying after 5 sec");
    // no point in carrying on, so do nothing forevermore:
    delay(5000);
    Serial.println("trying to configure ethernet...");
  }
  // print your local IP address:
  Serial.print("My IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);
    Serial.print(".");
  }
  Serial.println();
}

void loop() {
}

It generates this output in the Serial Monitor:
trying to configure ethernet...
Failed to configure Ethernet using DHCP, retrying after 5 sec
trying to configure ethernet...
Failed to configure Ethernet using DHCP, retrying after 5 sec
trying to configure ethernet...
Failed to configure Ethernet using DHCP, retrying after 5 sec
trying to configure ethernet...
Failed to configure Ethernet using DHCP, retrying after 5 sec
trying to configure ethernet...
Failed to configure Ethernet using DHCP, retrying after 5 sec
trying to configure ethernet...
Failed to configure Ethernet using DHCP, retrying after 5 sec
trying to configure ethernet...
Failed to configure Ethernet using DHCP, retrying after 5 sec
trying to configure ethernet...

I have captured the LED indicators on video on YouTube, it shows Tx and Rx LEDs glowing occasionally, see Arduino not detecting the ethernet connection.
It looks like the Arduino is not able to connect to the Ethernet... I am using the Arduino IDE 1.6.5 on Windows 7.
Is there any debug tool for Arduino that can be used to figure out this issue?

What is the Arduino connected to via Ethernet? (I didn't watch the video.)

There is no debugging on an Uno with reasonable effort, maybe on some other version. This is the main reason I do not understand why it is so popular. It is a horrible way to learn programming, much like learning surgery with knives but no stethoscope, no idea when (and why) you killed the patient.

Might need to set the SD enable pin to output and high.

Is the MAC address correct? Does the Ethernet to which the Arduino is connected have a DHCP capable router (in other words, is there a DHCP server enabled)?

Are you using version 1.0, or above, of the library, as this supports DHCP? see Ethernet.begin(). Earlier versions (v0.x) did not apparently.

Just asking, shouldn't the MAC address have 6 bytes and not 7 like in your code?

I see you have 7 bytes for your Mac address. Most examples I have seen only have 6 bytes. Are you using TCPIP v4 or v6? Strange.

I use more or less the same code to do my networked widgets and it has been quite reliable in my experience. Do you know if you have a DHCP server on the network segment that the Arduino is on? The absence of a server or a configuration that won't respond to the Arduino seem like the most likely explanation for the problem you're seeing.
The way to troubleshoot this would be to get another machine on the same network segment and watch the traffic with tcpdump or Wireshark or a similar tool. If you're running on a "third party" machine (e.g. not the DHCP server) then you'll be able to see the Arduino's side of the DHCP exchange, but I'm not sure if you'll be able to see the server (the Arduino will be broadcasting since it can't know the address of the DHCP server, but I think the server's response is unicast). If you've got a Linux box or some other machine that you can log into where you could run the DHCP server you can watch both sides of the negotiation. But even if you can't get to the server it will help to see if the Arduino is starting the DHCP negotiation.
If you need a fixed IP address on the Arduino, the way to do it is to configure the DHCP server to reserve an address for the Arduino. That way you can have a known address on the Arduino without having to hard code an IP address (which will eventually bite you).

Good answer w.r.t. reserving the IP address on the router/DHCP server

I never used the DHCP feature to assign an IP address for the Ethernet shield, but somewhere in there you have to list the IP of the router that assigns the DHCP.
In everyday use of the shield, you don't want your router to assign an IP address to your device because every time it connects it might get a different IP address. That means if you want to communicate with it, you need to discover the IP address each time. And communicating with it from the WAN side through a port you open in your router would be impossible.
Try one of the fixed IP address sketches, but select a free IP address in your router's IP range that isn't, also, in the router's DHCP IP range (that way the fixed IP address won't interfere with the IP addresses given out automatically).

Good answer w.r.t. using a static address (although it would require reserving on the DHCP server, see diu's answer) and testing the board using the fixed IP address sketches, except that you do not need to specific the DHCP server, or router, address. See Ethernet.begin()


text:
How to use an external clock with the Due timer?
I want to use an external clock signal as an interrupt for the Due timer. How do I do that? I could not find any info on this on the net.

This can help: How to set up one second interrupt/ISR for ds3231 RTC, https://arduino.stackexchange.com/questions/29873/how-to-set-up-one-second-interrupt-isr-for-ds3231-rtc

Everything you need to know is in the SAM3X datasheet:
http://www.atmel.com/Images/Atmel-11057-32-bit-Cortex-M3-Microcontroller-SAM3X-SAM3A_Datasheet.pdf
However, as Atmel's datasheets are some of the most cryptic ones around, you'll need to spend quite some time deciphering it.
There's an entire section just on the timers.  It tells you all about how they work, however, relating that to which registers you need to set to get it to do that is not clear (as is normal for Atmel) since the registers are listed elsewhere in that section with no real relationship between them.


text:
Binary reader with arduino blinking 8 leds
I´m trying to insert a binary raw sequence (01010100, 01101000, 01100001) into Arduino. I would like to make 8-led group blink in a loop, showing with light each 8-group binary sequence when: 0=light off and 1=light on.
It´s possible to do this operation with Arduino-uno ?

i don't think binary is supported in arduino, but you could use bitwise operators with the decimal values of these binaries

You should be able to do what you are asking, however your question is not very clear.  Are you asking how you would turn on/off the LEDs based on the binary value of a variable, or how you would get the raw sequence into the Arduino/source code?  Or both?  How are you wanting to get the sequence into the Arduino?  Is it to be pre-scripted in the source code, stored on some external device (such as an SD card), input by a user from some other hardware (such as a keypad) or transmitted (either wirelessly or via a serial connection)?

@razzak: Binary not being supported by Arduino is the silliest statement I ever heard about this platform. Almost everything inside the Arduino is binary. Decimal is only used for I/O, and only because we, humans, like it better that binary.

@EdgarBonet i was talking about using binary literals not the operations at the cpu level, you can not do int x = 01001001; in arduino. You can however use binary special notation (formatter) like int x = B01001001; which is not actual binary but rather a predefined decimal like doing #define B01001001 73.

Then, in your initial comment, you failed to make clear what you were talking about. The “B” notation is, in actual practice not that different from “0x” for hex. Or even decimal, which is only a notation after all: you do not really care whether it is interpreted by the preprocessor or the compiler proper.

You just prepend the number in binary with B e.g. B01100100 which is 100 in decimal
byte sequence[] = {
    B10000000,
    B01000000,
    B00100000,
    B00010000,
    B00001000,
    B00000100,
    B00000010,
    B00000001
}

And to check the n-th bit from the right in a number you do
boolean bit_set = number & (1 << (n - 1)) != 0;


text:
micro arduino and w5100
I would like to ask if it is possible and how to connect the following module
http://www.ebay.com/itm/TOP-Mini-W5100-LAN-Ethernet-Shield-Network-Module-board-for-Arduino-Best-NEW-/251981053942?pt=LH_DefaultDomain_0&hash=item3aab3dbff6
to the arduino micro
I found some pin layouts but only for Leonardo or Ethernet shield, Uno etc.
Also I've choosen this model because it can be programmed directly in arduino using Sockets API

While it would have been nice to see your research rather then having to spend some time finding this information myself, I did find this http://www.instructables.com/id/Add-Ethernet-to-any-Arduino-project-for-less-than-/ from what I can see this should be compatible to any arduino as long as it has 3 volt pin and 4 i/o pins. While the arduino micro doesn't have a 3v3 pin, as far as I know, that shouldn't be an issue as long as you can drop the voltage from the 5 volt pin, this module should work for you.

actually I though the same but wanted to be sure and ask.
Maybe someone knew more!


text:
Malloc with Objects in Arduino libraries
My understanding of using dynamic memory on the arduino is that new/delete are not available, only malloc realloc and such C functions, as mentioned here:
C++ & the AVR
I am creating a library that defines an object type that needs to contain a dynamic list of other objects. In C++ I would define it something like this:
class Container
{
std::vector<otherObjectType> otherObjects;
};

which obviously does not work in the arduino without the C++ standard library.
My next choice would be to create a dynamic array using new, ie
otherObjects = new otherObjectType[3]
{
    {   (arguments to constructor...)
    },
    {   (arguments to constructor...)
    },
    {   (arguments to constructor...)
    }
};

But this does not work as well, since new is not supported...
finally I could try to use malloc as laid out here, but that also wont work without new.
I am wondering if I should just rewrite everything as structs, since that wont require me to worry about whether the constructor for the object was called when the memory was allocated in malloc.

new actually does work in arduino. it is defined in arduino/hardware/arduino/avr/cores/arduino/{new.h, new.cpp} using malloc. It is not part of avr-libc though (which your link concerns) and has not always been added by arduino.
Both of these work for me:
namespace{ //namespace to deal with .ino preprocessor bug
    class foo{
    public:
        int bar;
        foo(int a){
            bar = a;
        }
    };
}
...
//using new
foo *a = new foo[3]{{1},{2},{3}};

//How I would probably do this with malloc
foo *b = (foo*) malloc(sizeof(foo)*3);
b[0] = foo(2);
b[1] = foo(4);
b[2] = foo(8);

Placement new is not defined right now. I know that copying isn't quite the same, but it should work in most cases.
Of course, if you know exactly how long you want the array to be at compile time, you should probably make it a static/global variable so that you avoid using dynamic memory and the sketch ram usage number will be closer to correct.

Yep, new definitely works. I think my misunderstanding was based off of a really old arduino forum post http://forum.arduino.cc/index.php?topic=2249.0. My mistake


text:
Flash a .hex to an ATtiny45 with Arduino
I'm trying to upload a hex file to an ATtiny45 with an Arduino. I uploaded the Arduino ISP sketch to my board. I connected the ATtiny as shown below:

Then I go to CMD and type:
avrdude -c avrisp -p t45 -b 19200 -P COM6 -U flash:w:main.hex:i

And it gives me this error:
Please define PAGEL and BS2 signals for ATtiny45!

I double checked the connections and i tried to uplad a bootloader with Arduino IDE as written in this article: Programming Hex-code on an Attiny85 with the Arduino. I can uplad sketches with ArduinoIDE with no error.

Googling the error gives this tutorial. Towards the bottom of the page they say

You’ll probably get the following message, but don’t worry, the upload should have worked anyway:
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85

So it seems this can be ignored and the part has been programmed!

But the avrdude dont finish the programming, just write out the error


text:
How to connect a card reader (extracted from printer) to arduino uno
I'v got this USB/SD card/CompactFlash reader from an old DELL AIO 926 printer, it's a double sided PCB board and that's all i know about it.
I tried to google it but couldn't find anything relevent, how can i tell what voltage it takes and what each wire does and how to interface it with arduino?

It seems to me that it has two sets of 4 wires (red/orange - black - yellow - white) and an extra blue wire, i'm guessing that the black is for GND, red/orange for VCC, yellow/white for SDA/XDA I2C serial bus data transfer, but no clue what the blue wire does, i could've tested this with arduino but i don't want to risk frying the board by using a wrong voltage. any help would be greately appreciated. thanks.

If the end is a USB that presumably can work when plugged in to computer, why dont you try it with Raspberry Pi?

I can pretty much categorically say you won't get it working.
I have a similar board here with the same SMSC (now owned by Microchip) chip on it.
The interface is USB plus some other signals.  I have managed to identify the USB portion of the interface on mine, but not the other signals.
The SMSC chip has the option of using an external ROM chip to store its program, and Dell love to do that.  So, it has a custom firmware which means it doesn't get recognized by my computer without Dell's specific drivers installed.  So it's useless.
There's a very very slim chance you may get it working with a USB Host Shield, but unlikely - and at the end of the day, what's the point?  It's just an SD card reader.  Wire an SD card socket direct to the Arduino and save yourself both the headaches of trying to work it out and also the massive pointless expense in buying the hardware you'll need to do the interfacing.

Well it would've been nice to use it as usb host and sd card reader, but what i really want is to learn how to hack such boards. Do you know what voltage should i use as VCC? and do you have a datasheet link to the smsc chip?

Vcc would be 5V as it's USB.  My board actually has a slightly different SMSC chip looking at it - similar thing, but a little newer (and that one is obsolete too).  Getting a datasheet for that very old one would be hard.  I'll see what I can do.

Looks like a no-go.  I could beg the guys at Microchip to head down to the archive room and see if they can dig out an old datasheet in their files, but it won't help you to get it going on an Arduino.  The SMSC chips are pretty much all 8051 based internally, so if there is an external ROM you could wire that up and read off the program from it and disassemble it to see how it works, but that'd be a huge job with no real reward at the end of it (other than a knowledge of old 8051 assembly).  I'd just strip the useful components off it to use elsewhere. Maybe try and rescue the sockets, etc.

It does sounds like a huge job for a hobbiest like me, i would probably strip it from its coponents and throw it in the bin soon, thanks for your help.

Actually, it looks like someone may have already had the ROM chip off it...


text:
0-1 V input to 0-5 V Output
We have an instrument that has analog output of 0-1 volts and we need to convert this to 0-5 volts. What is the best op amp to use for this and how should the resistors be set up? Any help would be greatly appreciated.
Thanks,
Paul

For your frequency needs of course the 324 is the best, and the resistors should be setup for a gain of -5.

What have you tried? This is a very standard circuit; searching for "noninverting opamp" should turn it up. If you have specific trouble implementing it, that would be the time to ask for help with your more specific question.

Input impedance, output impedance, load impedance, frequency response, power supplies available?

Desired precision? Are we supposed to guess 10 bits because of the Arduino tag?

Since you used Arduino tag..., you don't need an opamp. Instead you can select ADC reference voltage on your arduino to 1.1V. This way you don't need any additional parts and you get the whole precision range.
analogReference(INTERNAL1V1);

http://www.arduino.cc/en/Reference/AnalogReference

+1 This is so neat, it's neat. Except if anything else needs the ADC - you are stuffed because the standard Arduinos (although there are so many these days..) only have a single ADC peripheral. Another thing is modular design - the analog instrument may not always be there or maybe needs other circuitry, so a simple general purpose rail-to-rail input/output op-amp with a gain of 5 and perhaps a passive low-pass filter going into the Arduino's ADC would be something I would do in my own design

You can switch between 5V and 1.1V ADC in software as you like, so using mixing various peripherals is not a problem.

I suppose so, but no sure how much that would affect performance.. for a slow sensor-network system or whatever it would be fine - or just scale down all the other inputs to 1V using resistors which is far simpler than scaling a signal up. The resistors wouldn't be ideal if the signal itself was already a voltage divider as you would affect it with parallel resistance.

@KyranF: Taken from the Atmega328 datasheet, Sect 24.5.2, paragraph 3: "the user may switch between AVCC [5 volts]  and 1.1V [Internal Reference] as reference selection. The first ADC conversion result after switching reference voltage source may be inaccurate, and the user is advised to discard this result."

@chaaarlie2 thanks, thats pretty good only losing 1 sample


text:
reversing DC motor rotation using TWO limit Switches Problem !! need help
I'd like to write a code for reversing DC motor rotation direction as follows:

Start the motor rotation clockwise (CW).
When reach Limit Switch (CW) → motor will stop for 5 sec.
after 5 sec. of stopping → the motor will rotate in counter clockwise direction(CCW).
When reach Limit Switch (CCW) → motor will stop for 5 sec.

and repeat point 1, 2, 3 and 4...
Actually I wrote a code for reversing the motor direction using two limit switches and it is working good. But when I added delay the motor did not stop using the limit Switches and continue to rotate...
If any one can help...
Here is my code for reversing the direction with out delay 5 sec. My limit SWs are connected on Normal Open.
int sw1, sw2, sw3;
const int LM1 = 0;
const int LM2 = 1;
const int LM3 = 6;
const int CW = 10;
const int CCW = 9;
const int Buzzer = 7;

void setup() {
  pinMode(LM1, INPUT);
  pinMode(LM2, INPUT);
  pinMode(LM3, INPUT);
  pinMode(CW, OUTPUT);
  pinMode(CCW, OUTPUT);
}

void loop(){
  sw3 = digitalRead(LM3);
  sw1 = digitalRead(LM1);
  sw2 = digitalRead(LM2);

  if (sw1 == LOW && sw2 == HIGH) {
    do {
      digitalWrite(Buzzer, HIGH);
      digitalWrite(CW, HIGH);// change the direction of rotation (DOWN Movement)
      digitalWrite(CCW, LOW);

      sw2 = digitalRead(LM2);
    } while (sw2 == HIGH);
  }
  else if (sw1 == HIGH && sw2 == LOW) {
    do {
      digitalWrite(Buzzer, HIGH);
      digitalWrite(CW, LOW);// change the direction of rotation (UP Movement)
      digitalWrite(CCW, HIGH);

      sw1= digitalRead(LM1);
    } while (sw1 == HIGH);
  }
}

Normally you use state machine for this kind of programming: you have a
state variable that remembers what you are doing, and depending on the
current state you decide what to do next. Below is an example with two
states. I have embedded a few assumptions about the wiring of your motor
and your switches, which may be wrong, so you have to check the code.
void loop() {
    static enum {MOVING_CW, MOVING_CCW} state;

    switch (state) {
    case MOVING_CW:
        if (digitalRead(LM2) == LOW) {  // hit switch
            digitalWrite(CW, LOW);      // stop
            delay(5000);
            digitalWrite(CCW, HIGH);    // restart
            state = MOVING_CCW;
        }
        break;
    case MOVING_CCW:
        if (digitalRead(LM1) == LOW) {  // hit switch
            digitalWrite(CCW, LOW);     // stop
            delay(5000);
            digitalWrite(CW, HIGH);     // restart
            state = MOVING_CW;
        }
        break;
    }
}

This will start in the MOVING_CW state, but you have to actually start
the movement in setup(). It has the drawback of having long delay()s in
the loop, which is undesirable if you have other tasks to perform. These
delays can be removed by “remembering” that you are waiting as two extra
states:
void loop() {
    static enum {MOVING_CW, MOVING_CCW, STOPPED_CW, STOPPED_CCW} state;
    static unsigned long time_stopped;
    unsigned long now = millis();

    switch (state) {
    case MOVING_CW:
        if (digitalRead(LM2) == LOW) {  // hit switch
            digitalWrite(CW, LOW);      // stop
            state = STOPPED_CW;
            time_stopped = now;
        }
        break;
    case MOVING_CCW:
        if (digitalRead(LM1) == LOW) {  // hit switch
            digitalWrite(CCW, LOW);     // stop
            state = STOPPED_CCW;
            time_stopped = now;
        }
        break;
    case STOPPED_CW:
        if (now - time_stopped >= 5000) {
            digitalWrite(CCW, HIGH);    // restart
            state = MOVING_CCW;
        }
        break;
    case STOPPED_CCW:
        if (now - time_stopped >= 5000) {
            digitalWrite(CW, HIGH);     // restart
            state = MOVING_CW;
        }
        break;
    }
}

Maybe the code with the 5 second delay is more usefull. Because you are telling us the code you now deliver is supposed to work?
Probably using delay(5000) will work?

I added delay (5000); at the end of my code -- > Doesn't work also I tried to add delay at the start of my code ---> Doesn't work

You will have to make another state (idle). Here you will have to put the commands low, this way the motor will actually stop. Then you can add the delay to it, so the motor will stop for the 5 second duration.

kindly give me idea or example about this issue

Motor CW > Motor idle > Motor CCW > Motor idle > Motor CW…..
Every change in limit switching should change the state of the motor.
In your program now it is: Motor CW > Motor CCW > Motor CW…
Are you able to put the motor on or off with program code?
Or are you only able to change its direction? If so, would writing both CW and CCW LOW deliver any problems?


text:
Change input reference to 1 - 5 V
I am using a sensor which delivers a 4 to 20 mA output.
Converting this with a 250 Ohm resistor to ground I convert this to a 1 - 5 V output.
My question how can I change the 0V reference, so I can use the full spectrum
I found a way to change the 5V reference (analogReference()).
Is it possible to change the 0V reference of a input to 1V?
Any other solution to my problem is welcome as well! (As long as it doesn't involve I2C or anything which lowers my looptime drastically)

Not possible with the Uno, as it has only GND-referenced single-ended inputs.

On which board is this possible? Is there another way to use the full resolution?

Don't know for sure. The Mega is based on the ATmega2560 chip, which has differential inputs to its ADC. If those are available on the board connectors, and if you can provide your 1 V reference to the negative input, it should work.

The ADC is ground-referenced, and there's no way to change that. The question is if that's necessary. The ADC has a 10-bit resolution, that's good for 1024 different levels between 0 and 5 V. If you convert the 4-20mA with a 250 Ω resistor to a 1-5 V range you still can discriminate between more than 800 different values.
If that's not enough you can use a differential amplifier to subtract 1 V:

By choosing R3 = 1.25 R1 you convert the 0-4 V range to a 0-5 V range.

I like the differntial amplifier answer. But, what are V1 and V2? Why are you talking about 0-4 to 0-5 when I have a 1-5? Thanks in advance!

0-4v is 1-5v with 1v subtracted as the answer says.  V2 is your signal at 1-5v, v1 is 1v reference voltage.  V1 is subtracted from V2 (so 1-5 becomes 0-4) and then amplified by R3/R1 to make 0-4 into 0-5.

Use a 2nd opamp section to make a unity gain buffer (OA out to OA-) use this to buffer a pot that you adjust to 1V (Pot feed OA+,OA out to V1. ) || Make One of the R3's adjustable using a bigger value pot than R3 fixed. eg if R3 = 10K make pot say 15K so you can adjust it either side of 10k slightly. This is used to make gain of V1 & V2 inputs track. || Overall accuracy is limited by balance of resistors so use 1% or better still 0.1%. (may not need pot above if R's are matched well enough).   IF you want to avoid having to supply matched R's buy an "instrumentation amplifier" IC.


text:
Leonardo and micro: high pitch noise when powered from Vin

I have an issue with several Leonardo and Micro boards.
On all of my boards, there is a sawtooth of about 690mV ptp @ 4kHz on the 5V supply when powered from Vin (external power).
The frequency changes slightly when changing input voltage from 7V to 12V.
C12 is a capacitor on the Leonardo board that is making the acoustic noise, it is "singing" with the frequency of this sawtooth. It follows the voltage regulator NCP1117 for the 5V power supply generation.
According to the schematics of the Leonardo and micro, the voltage regulator used on these boards should be the NCP1117, but on the boards I have, there is no number printed on this component, so I suspect an alternative was used, with these annoying results...
For a project I have for generating audio signals, this noise was unacceptable, so I cut out the regulator and powered everything with an external LM7805. One should not power the module via USB then as long as the external power is connected!!!
Anyone having the same trouble with these boards?
Other solutions?
(The Leonardo is a genuine Arduino board.)

How are you generating audio signals?  More specifically, what are you driving in the way of outputs?  Are you driving a low impedance magnetic speaker directly?  Your observed behavior strongly hints that you may be placing a high load on the regulator - normally, with only the micro as a load it shouldn't do that, unless you have a dirt cheap implementation made with substandard components.

Yes, I've had this problem on a number of boards. It seems there are some faulty units coming out of the factory. I've had them replaced by my supplier, but I end up being sent more faulty boards.
It makes any kind of accurate ADC reading impossible.
A quick way to work out if your board has this problem

Place a jumper between 3.3v and A0
Put an analogRead in a loop and println the result
When powered by 5V you'll see a fairly constant value (around 670), varying by 1 or 2
When powered by 12V, if you have a faulty board, you'll see varying values, deviating by 50 or more.

There's a couple of solutions/workarounds to the problem listed here: http://forum.arduino.cc/index.php?topic=235729.0.

It does sound like the regulator is oscillating to me.  That happens when the output capacitor is of the wrong type for the regulator - the ESR is wrong.
My Leonardo, when powered from 12V, is nice and clean.  The regulator has 7CE50Z on it.  I do notice, on the layout of the Leonardo, that the output capacitor is somewhat further away from the regulator than I like to put it - though that shouldn't cause that much of a problem.  800mV is way too much to be considered normal under any circumstances.
What is the power source you are using?

it's 12DC coming from a precision DC power supply (Thandar)

@pascalm It's unlikely to be that then.  It's probably the factory has changed regulators and they don't now have the same ESR requirements.  You can try adding a 100nF ceramic capacitor direct across the Vout / GND pins of the regulator - an 0805 would fit nicely.

just used an "ordinary" ceramic cap 104, gives no improvement :(

Next step is probably to change out the regulator - shouldn't be too hard with desolder braid, though hot air is now a very affordable and useful tool.  What is the origin of these boards?  If it is not from one of the claimants to the trademark, you probably should add "-like" in your title rather than attributing issues with some random work-a-like to the branded product.

it's original Arduino! - in original box

Do you have another power source you can try?


text:
What is the difference between Accelerometer, Gyro, and Magnetometer Sensor?
I'm starting in the arduino world and I'm building an autonomous smart vehicle.
So, after some weeks building and adjusting the vehicle, I got to a point in this project that I want to log it's movements. Talking with a friend, he showed me an Gyro/Accel sensor and I really think that it would be an awesome upgrade to my vehicle
After reading some articles, I'm failing to understand the difference between an Accelerometer Sensor, a Gyro Sensor and a Magnetometer Sensor
So what is the main difference between those sensors?

The Accelerometer measures total acceleration on the vehicle, including the static acceleration from gravity it would experience even when its not moving.
The magnetometer measures the magnetic field around the robot, including the static magnetic field pointing approximately north caused by the earth. Being placed in/around a metal frame or any large motors, diving over/around underground metal pipes or electrical equipment will all make large and noticeable effects on its measurements.
The Gyroscope measures your instantaneous angular momentum around each axis, basically how fast its rotating. Note that angular momentum is not directly compatible with euler angles, but works out similarly for small angles. Very high quality signal in the short term because there isn't much noise, but since your angular position has to be integrated off of the gyroscope, it will build up error.
Gravity is your best reference for angular position, because it doesn't drift like the gyroscope and since your robot is operating in (and causing) a sea of magnetic disturbances, using north is risky. It will not work if you are experiencing a significant acceleration though.
The simplest code would just use the accelerometer for rotations around x and y, the mag for z, and ignore disturbances. The basic idea is "I know gravity is actually down, but its being measured on the accel X axis, so I must be pitched by some amount". The Better sensor fusion algorithms will use the accelerometer/magnetometer to correct for drift in the gyro, but get most of its information about rotational position from the Gyroscope.
Tracking lateral position using a standard 9-dof IMU is not possible. Only the accelerometer measures lateral motion at all, and it needs to be integrated twice to get position. Error builds so fast your position estimate is complete garbage within seconds.
Tracking angular position is possible because all three sensors measure it in one way or another. Angles are tricky though because they are not commutative. If the gyro measures a 90 degree yaw then a 90 degree pitch from north, you are facing down; if it measures a 90 degree pitch and then a 90 degree yaw from north, your facing east turned on your side. Be careful with the math, or download an arduino IMU library that has it taken care of for you.

The main difference is the way they operate and what they sense.  In other words, they are all very very different things.  Yet they can all measure motion in some way.

An accelerometer senses both the gravitational pull of the earth and the inertia / momentum of the motion of the device
A magnetometer senses the earth's magnetic field to get a compass heading.
A gyroscope senses changes in twist and angle.

They can all give information about motion and attitude, but each has both benefits and drawbacks compared to the others.  Some drift more than others, some are slower or lower resolution, etc.
So generally all three are used together to get the benefits of them all and, to some extent, negate the drawbacks of them.
For instance, a gyroscope isn't good at measuring inertia, but it is good at measuring changes in angles.  But those changes in angles drift over time and you lose accuracy.  A magnetometer is good at giving you an exact angle, but it takes longer to get an accurate result, and it's not good at fine changes in angle.  So a magnetometer is used to correct the drift of the gyroscope, and an accelerometer is used to measure inertia.
So to sum up:

Accelerometer for changes in speed
Gyroscope for changes in angle
Magnetometer to correct the gyroscope


text:
Serial communication not working between two Arduinos unless connected to computer
I have a robot with an Arduino Mega that gets data from a bluetooth module and sends it to an Arduino Leonardo to activate some functions. It all works amazing but only if the boards are connected to my computer. As soon as I disconnect them and power them from their own batteries, the serial communications seems to stop working. When I connect it to the PC again the communication between the Arduinos begins working.
Does anyone know why this is happening?
The Mega is powered by a 9V battery and the Leonardo by 4x AA (6V). On the Mega I use TX/RX(2) for communication with the BT module and TX/RX(3) for communication to the Leonardo.

By "stop working" do you mean the RX / TX LEDs don't blink? They never do unless the board is powered by USB.

Nope,from the Arduino Mega I am using TX2/RX2 to communicate with the bluetooth module, and TX3/RX3 to communicate with the arduino leonardo. by not working I mean that the arduino leonardo stops getting data from the MEGA. This only happens when I use a power bank or 9V Battery instead of connecting it directly to the Computer

Can you draw a diagram of how they're connected together? It might be that you need to pair the Mega ground to the Leonardo ground, otherwise the voltages will be all at sixes and sevens.

So the problem may be the change of voltage?

The Mega ends up with 9V and the Leonardo with 6.

Does each board have its own power supply, or does it all come from one place? A diagram really would help - one of how it looks when connected to the PC and one when it isn't. It doesn't need to be a work of art; a picture paints a thousand words and answers twice as many questions!

Great, let me make a simple understandable diagram and I'll upload it

While I am doing that, I'll try to explain. The arduino Leonardo uses 4 AA batteries, and the Mega uses 1 9V battery. They are connected via serial port and they do what they are told to do, but only if they are both connected to the computer and not to their power supplies

Connect any GND pin from one board to any GND pin on the other.

Amazing!! That solved the problem! Thanks a lot. So common ground is important when using different circuits with different power supplies. Why is that?

I'll add a proper answer now I know your situation. I'll also edit your question a little so it helps others in the same boat.

Voltage, Electrical Potential, Potential Difference, Electric Tension - whatever you refer to it as - is the always measured between two points.
Generally of course we mean two points within one circuit, and most of the time we mean between something and the circuit's 0-Volt rail; it's implied whenever somebody quotes a voltage, unless they specifiy otherwise.
We always refer to the 0-Volt rail as 'ground', no doubt stemming from the term 'earth', which is literally a connnection into the ground itself. In the case of a battery powered circuit, the 0-volt rail is only 0 Volts referenced to the rest of the circuit. In such a circumstance, the circuit's ground is said to be floating when referenced to another circuit. Thus, two circuits with independent power supplies and no interconnection cannot be compared to one another in sense of voltage.
This typically doesn't matter, but when you need to interconnect independently-powered circuits you run into a problem. As both grounds are floating, any other voltage on each circuit is referenced to said floating voltage, and therefore is also floating. This makes wired communication between them impossible.
Unless you create a voltage reference between the two.
Simply connect the ground rails of each together; the cicruits are then referenced to one another at 0 Volts. It doesn't have to be the ground rails that are connected - any two points connected together will allow you to reference any point on board A to board B and get a correct potential difference. However, it's pretty useless doing that except in some odd situations.


text:
I am having an issue reading a HIGH LOW signal from a pressure switch
I'm trying to read either high or low from a pressure switch, I do have a pulldown resistor attached but even if I plug in a wire with nothing on it i get a false high. I've changed pins, tried adding INPUT_PULLUP to the program but it it reads false.
The code i'm using is:
const int mainPump = 2;
const int prePump = 3;
const int idleValve = 4;
const int chemTankLow = 5;
const int chemTankHigh = 6;
int pressure = 8; //7 originally removed const
const int chemValve = A7;
const int mem2 = A6;
const int mem3 = A5;
const int mem4 = A4;
const int mem5 = A3;
int tankLow = 0;
int tankHigh = 0;
int pressureFault = 0;
int lpe = 0;
int maxlpe = 2;
unsigned long timer[10]; //number of timers needed
byte timerState[10]; //store timers
int goNoGo = 0;
int readVoltage = 0;
int var = 0;

void setup() {

  pinMode(idleValve, OUTPUT);
  pinMode(prePump, OUTPUT);
  pinMode(mainPump, OUTPUT);
  digitalWrite(mainPump, HIGH);
  pinMode(pressure, INPUT);   //removed _PULLUP after input
  pinMode(chemTankLow, INPUT);
  pinMode(chemTankHigh, INPUT);
  pinMode(chemValve, OUTPUT);
  pinMode(mem2, OUTPUT);
  pinMode(mem3, OUTPUT);
  pinMode(mem4, OUTPUT);
  pinMode(mem5, OUTPUT);

  digitalWrite(mem2, HIGH);
  digitalWrite(mem3, HIGH);
  digitalWrite(mem4, HIGH);
  digitalWrite(mem5, HIGH);
  digitalWrite(chemValve, HIGH);
  digitalWrite(idleValve, HIGH);
  digitalWrite(prePump, HIGH);
  digitalWrite(prePump, HIGH);
  digitalWrite(idleValve, HIGH);
}
void loop()
{

       tankLow = digitalRead(5);
   tankHigh = digitalRead(6);

  if (tankLow == LOW && tankHigh == LOW){ //start day tank refill
   digitalWrite(A7, LOW);
  }
  if (tankLow == HIGH && tankHigh == HIGH){
    digitalWrite(A7, HIGH);
  }
  static int state = 1; // initial state is 1, the "idle" state.
  static unsigned long ts;

  switch (state)
  {
    case 1:
    ts = millis();

  if (delayMilliSeconds(1, 6000)){//600000

  digitalWrite(prePump, LOW);

  goNoGo = digitalRead(mainPump);
  if (goNoGo == LOW) {

    digitalWrite(idleValve, HIGH);
  }
    else {
      digitalWrite(idleValve, LOW);
          digitalWrite(mem2, LOW);
    digitalWrite(mem3, LOW);
    digitalWrite(mem4, LOW);
    digitalWrite(mem5, LOW);
    }

        readVoltage= digitalRead(idleValve);
    if(readVoltage==LOW){

    delay(4000); // wait time motors to stablize
    // read the input on analog pin 0:
    int sensorValue = analogRead(A0);
    // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
    float voltage = sensorValue * (4.83 / 1023.0);

    if (voltage >= 2.00)
    {
      state = 2;
    }

    else {
      delay(56000); //on time for test
    //  if (delayMilliSeconds(2, 51994)){
    digitalWrite(mem2, HIGH);
    digitalWrite(mem3, HIGH);
    digitalWrite(mem4, HIGH);
    digitalWrite(mem5, HIGH);

     digitalWrite(idleValve, HIGH);
      digitalWrite(prePump, HIGH);
      digitalWrite(mainPump, HIGH);
    }
    }

}
//} for if timer
break;

    case 2:
       ts = millis();
      digitalWrite(mainPump, LOW);
      digitalWrite(idleValve, HIGH);
       digitalWrite(mem2, HIGH);
        digitalWrite(mem3, HIGH);
        digitalWrite(mem4, HIGH);
        digitalWrite(mem5, HIGH);
        delay(20000);
        state = 3;

        break;

        case 3:

      digitalWrite(mainPump, LOW);
      digitalWrite(idleValve, HIGH);
       digitalWrite(mem2, HIGH);
        digitalWrite(mem3, HIGH);
        digitalWrite(mem4, HIGH);
        digitalWrite(mem5, HIGH);

      pressureFault = digitalRead(pressure);
  if (pressureFault == HIGH){

    state = 4;
  }
   if (millis() - ts > 3600000){
    state = 5;
  }

   break;

   case 4:
   digitalWrite(mainPump, HIGH);
   digitalWrite(prePump, LOW);
   digitalWrite(idleValve, LOW);
      digitalWrite(mem2, LOW);
    digitalWrite(mem3, LOW);
    digitalWrite(mem4, LOW);
    digitalWrite(mem5, LOW);
    delay(3000);
    digitalWrite(mainPump, HIGH);
   digitalWrite(prePump, HIGH);
   digitalWrite(idleValve, HIGH);
      digitalWrite(mem2, HIGH);
    digitalWrite(mem3, HIGH);
    digitalWrite(mem4, HIGH);
    digitalWrite(mem5, HIGH);
    delay(600); //60000
    state = 1;

    break;

    case 5:
    ts = millis();
        digitalWrite(idleValve,LOW);
        digitalWrite(prePump,LOW);
         digitalWrite(mainPump, HIGH);
           delay(60000); //60000 for standard
           digitalWrite(mem2, LOW);
           delay(60000);
           digitalWrite(mem2, HIGH);
           digitalWrite(mem3, LOW);
           delay(60000);
           digitalWrite(mem3, HIGH);
           digitalWrite(mem4, LOW);
           delay(60000);
           digitalWrite(mem4, HIGH);
           digitalWrite(mem5, LOW);
           delay(60000);
           digitalWrite(mem5, HIGH);

           delay(1000);   // leave this time
         digitalWrite(idleValve, HIGH);
         digitalWrite(mainPump, LOW);
       state = 2;
         break;
         default:

         state = 1;

         break;

  } //switch
} //loop

int delayMilliSeconds(int timerNumber,unsigned long delaytime){
  unsigned long timeTaken;
  if (timerState[timerNumber]==0){    //If the timer has been reset (which means timer (state ==0) then save millis() to the same number timer,
    timer[timerNumber]=millis();
    timerState[timerNumber]=1;      //now we want mark this timer "not reset" so that next time through it doesn't get changed.
  }
  if (millis()> timer[timerNumber]){
    timeTaken=millis()+1-timer[timerNumber];    //here we see how much time has passed
  }
  else{
    timeTaken=millis()+2+(4294967295-timer[timerNumber]);    //if the timer rolled over (more than 48 days passed)then this line accounts for that
  }
  if (timeTaken>=delaytime) {          //here we make it easy to wrap the code we want to time in an "IF" statement, if not then it isn't and so doesn't get run.
     timerState[timerNumber]=0;  //once enough time has passed the timer is marked reset.
     return 1;                          //if enough time has passed the "IF" statement is true
  }
  else {                               //if enough time has not passed then the "if" statement will not be true.
    return 0;
  }

}

As for wiring it is as basic as it gets 3.3v pin off the arduino to a pressure switch and then back to the arduino . but i'm not even making it to the switch before i have an issue literally plug in a 3ft wire not connected to anything and it goes to case 4
I've tried setting the code up to go to case 4 if it detects a LOW but hasn't changed my issue.

Datasheet, circuit diagram, and code where?

Don't be put off by the downvotes just yet; if you add what has been asked then you'll probably find they start to disappear...

Could you post the whole code? What type is pressureFault? And state? Too many questions that can be answered with a simple copy/paste. I'll even format it (again) if you don't know how. HINT: highlight any text you want to turn into block code and click the double-brackets "{ }" button at the top of the text box...

Thank you for uploading the code. I can't spot any immediate errors so you're going to have to strip back the code, as @Trillian86 says, to make sure there are no hardware faults. If case 4 is being reached, i take it you mean the program is correctly navigating to case 3, and then state is set to 4 regardless of the value of pressureFault?

correct, pressure fault is just connected to a spdt pressure switch i just need it to read high or low.

Follow Trillian's advice and just use a barebones code to prove that the switch is working. If you can't use the serial monitor use the onboard LED on pin 13 to be on if the switch reads high or off otherwise.

As a hint.  Start by removing the stuff you added an just try to detect a grounding of your input pin (I'm assuming digitalRead(pressure) is the standard read the digital value of a pin and not some funky function you've written)
Use some code like this to test your hard ware
int    pressure;

void setup()
{
    Serial.begin(9600);  //Start a serial monitor to see the results
    pressure = 4;  // Assumes your pressure input is pin 4
                   // change if need be
    pinMode(pressure,INPUT_PULLUP);  //Sets put to input with pullup
    digitalWrite(pressure,HIGH);      //Activates pullup
}

void loop()
{
     if (digitalRead(pressure))
     {
          Serial.println("Pin is High");
     }
     else
     {
          Serial.println("Pin is low");
     }
     delay(1000);
  }

Now compile, upload and activate the serial monitor.  Every second you will get the read of the pin on the monitor.  See if grounding the pin is detected.  If not, you may have popped the port.
BTW.  3 ft of wire will need some filtering and protection.  That will pick up a lot of noise.
Cheers


text:
Fried two Arduino Nano's but works when powered
It took me about 4 hours to desolder an Arduino Nano I fried and solder on the new one. I'm not exactly sure how but I shorted it somehow while trying to install the nano onto my robot. I could smell a fait burning and the nano no longer powered on or allowed me to upload code via USB.
When I put the second nano on, before properly insulating exposed wire, I fried it again!! This time I actually saw a little smoke and quickly unplugged it. The nano no longer responds to the USB, but...
I have this nano also being powered by an Arduino Uno. When I turned on the battery connected to the Uno, the Nano turned on and everything was working fine!! I was pretty relieved after a short spout of depression! I plugged in the USB to the Nano and I was able to upload code... only with the nano being powered from the Uno. If I turn off the battery to the Uno the Nano doesn't work with USB.
I have no idea what happened exactly and I'm not sure what fried on my Nano but I sure am glad I have this work around instead of replacing the Nano again!
Does anyone know why it's doing this? What did I see smoking? Is it repairable?

Judging by your list of observations:

Cannot power through USB
Can power from external source
Can program through USB

it is most likely that the power feed from the USB to the +5V rail has been interrupted.  There is only one component in that link - the diode D1 (an MBR0520).  That is rated at an absolute maximum constant forward current of 0.5A and most USB ports these days are capable of providing far more than that.  A short circuit on the +5V to ground would draw considerably more current than that diode can handle and the Magic Smoke™ would escape.
The diode is on the underside of the Micro and close examination may show a small crack in the surface of it.  That is if it's still there.  I have used a similar PIC32 based board with 0.5A rated diodes on it, and a short of the power rail when powered from USB caused the diode to completely vaporise (at least I could find no trace of it afterwards).

Can program through USB only while powered from external source*

@MichaelRader The ability to program the board and the ability to provide power to the board (either while programming or at other times) are two separate things.  The issue here is not with programming, since programming works - the issue here is with providing power, which is a prerequisite to programming, not part of the act of programming.

Yes I understand, however it is part of the act of programming if it must have power to program. But anyway, thanks!


text:
is any windows application available for accelerometer based computer mouse
I want to make an AIR mouse using Arduino
and accelerometer, for this i used USB to TTL
converter i have done everything successfully
but can anyone tell me how use it in computer.
I mean i don't know how to make computer
application for this mouse. please suggest me
any application for this. And give any idea for
"how can i use Bluetooth for this."

......................................
......................................


text:
How do I use a 3 legged phototransistor?
I have searched the Internet and found the following circuit to use with my phototransistor but it is not working, I can say so because all analog input i get is 1023 even if i have covered it totally, I have include the phototransistor and the diagram can anyone tell why is it not working!
I used this webpage to check my sensor and it works-I used this page
I have used 10kohm resistor.

This is my phototransistor

I have used a 10kohm resistor

What is your infra-red light source?  That PTX won't respond well to ambient light.

halogen lamp and tv remote both @Majenko

Showing just the relevant portion of your image makes it MUCH easier to view

Thanks Russell @RussellMcMahon do You have any idea about this problem, also I got new info when i made the test circuit as said by this webpage - https://learn.adafruit.com/ir-sensor/testing-an-ir-sensor it works fine

That's not a phototransistor. Phototransistors do not have a "supply voltage" or a "work frequency".

It happens to be an IR phototransistor @IgnacioVazquez-Abrams

It may contain a phototransistor, but it is not a phototransistor.

@IgnacioVazquez-Abrams the same phototransistor so called ir sensor is available at adafruit, so it is basically phototransistor which has a peak sensitivity of Infrared spectrum -http://www.adafruit.com/product/157

You can also check the data sheet below and will you pls care to look at my previous question and maybe tell me an answer. Thanks! @IgnacioVazquez-Abrams

I'm okay with people looking at you sideways with big question marks over their heads, so feel free to believe that you have a phototransistor.

Let us continue this discussion in chat.

@IgnacioVazquez-Abrams The website says so and also I use codes for phototransistor and its working is same and is is doing same thing that a phototransistor is supposed to be

A reasonably generic data sheet is HERE
That is for an AT156 but yours may be an AT138/HT138 based on an ad some years ago from the same seller when they said they had 10,000 for sale.
Basic information here and more in the data sheet.

Following the same guide I am now able to decode my remote signals, though thanks for your effort

First that is not even a photo resistor 2nd you have to put one wire positive and the other negitive and the last one plug it into any other gpio pin


text:
is any windows application available for accelerometer based computer mouse
I want to make an AIR mouse using Arduino and accelerometer, for this i used USB to TTL converter i have done everything successfully but can anyone tell me how use it in computer. I mean i don't know how to make computer application for this mouse. please suggest me any application for this. And give any idea for "how can i use Bluetooth for this."

yeah, except that question is from the same user and now shares the same title (it did not earlier). Something wacky going on with the SO database or the migration, or it is just acting weird in general. Maybe EE migrated, the user re-posted, then they migrated it again?

try "remotemouse.exe"
its a open source application you can modify the codes according to your requirement


text:
Common wireless gadget with rotary encoder to connect with Arduino
I'm looking for a common "wireless gadget" with a rotary encoder that can be accessed by an Arduino. Background: I need a portable rotary encoder to create a simple way to control model railway locomotives. The only one I have found so far is a wireless mouse where the scroll wheel can be easily used as rotary encoder.
But they usually are using USB on the PC side which is not that easy to handle by Arduino. Does anybody knows about other common "wireless gadgets"?

That sounds like a candidate for building your own.  It shouldn't be too hard.
There's plenty of low-cost Arduino-compatible wireless modules available.  My choice for this would probably be the nRF24L01 - dirt cheap, reasonable range, well supported.
Attach that to an Arduino Mini or Arduino Nano (for instance) and connect a rotary encoder of your choice.  Write the sketch.
Add another nRF24L01 to your main Arduino to receive whatever you send.
Due to the way the nRF24L01 works you could quite easily have a number of remote modules talking to the Arduino through the same channel.  I'm sure you could think of other things you could do with that wireless channel :)

Excellent solution. I was about to post a similar answer when I saw yours. +1

In addition to @Majenko,
If your device is going to talk to a PC/Laptop (or cellphone!), then HC05 or HC06 bluetooth serial module may be a better fit. You will still need to write software to receive the data, but you won't need another Arduino at the other end.