text:
Protecting your computer from stupid (arduino) mistakes
I recently ran way to much voltage through my Arduino and back into my computer via the USB connection. I'm looking for a USB hub with a fuse or some sort of protection to protect my laptop from these types of mistakes.  Any suggestions as to products that would serve this function or other precautions I might take?

If you used the barrel jack, the voltage wouldn't have reached the usb connector. So unless you connected the higher voltage to the 5V pin directly there isn't a problem.

Thanks for the advice all. In case you are wondering this is what I did http://electronics.stackexchange.com/q/223983/104362.  The board that I was attempting to probe was powered externally at 16vdc regulated to 12vdc.

Both the arduino and a USB port do have some protection against wrong connections and such. The arduino has a diode to prevent wrong polarity to reach your power supply, it also have a resetable fuse (the kinda big, often green SMD part close by your USB connection on your Arduino) that should protect your USB port pretty good from its side of the cable. Your USB port also have some good protections going on as far as i know, so basically it should be hard to break a USB port by accident.
That was the theoretical part, In real life things aren't always what they claim to be, so I use a cheap powered USB hub, that i always use as a first line of defense.

Not all Arduino have such protections: the Uno does, but a Nano is also part of the family.

The Nano is missing the polyfuse, but does have a diode to protect the USB

What happens on a UNO vs a Nano when you short +5v and GND? A completely different thing, and that is my point.
Anyway, +1 to cheap powered USB hub when unsure of schematic.

Anyone knows about nodeMCU? (Do they have some protection against wrong connections?)

There are a number of USB Isolator products available all around the world.
Here is a list of just a few:

Adafruit - USB Isolator
OLIMEX - USB Isolator
Avantech - USB Isolators
CESYS - USB Isolator
Hjelmslund Electronics - USBISO-AA

Please note, that I have no experience in this field, this is simply what I found after some digging.
I was concerned about connecting a Raspbery Pi Pico device to my brand new computer and did some digging in the "USB Power Delivery" specification:

7.1.7.1 Output Over Current Protection
Sources operating in SPR mode Shall implement over current
protection to prevent damage from output current that
exceeds the current handling capability of the Source. [...]

"Shall" means, that this is a mandatory requirement:

1.4.2.11 Shall/Normative
Shall and Normative are equivalent keywords indicating a mandatory
requirement.  Designers are mandated to implement all such requirements
to ensure interoperability with other compliant Devices.

At this point I am already confident enough to plug the device into my computer, so I'll stop digging into the details here.
My understanding is, that the USB controller will detect the fault, disconnect the device and then upon reset and/or reboot it would start working again.
External protection circuits should not be required, at least that is my takeaway.  Maybe for really old computers?
Edit:
It doesn't seem quite that simple after all, over-voltage protection may not be covered:

6.4.6.1.6 Over-Voltage Protection Event
The Over-Voltage Protection Event bit May be set when the
Source detects its output Voltage exceeds its limits triggering
its protection circuitry.

It seems advisable to use some sort of external device after all.  Not sure how realistic this failure case is for devices which are powered from the host, but for devices with external power this seems smart.

This answer is about overcurrent protection. The question was about overvoltage protection. Not quite the same!

@EdgarBonet Thanks for pointing this out, it seems, over-voltage protection is not always present, so this is an important correction.

You get used to what not to do fairly quickly :)
Perhaps what you're after is a ruggeduino - http://www.rugged-circuits.com/ruggeduino/
I get the feeling that this sort of thing encourages bad habits, but then it also encourages more exploration.
You need to think carefully about what you're doing, if you put in any second source of power (e.g. USB + power plug, or USB + a signal from another device).


text:
How to recover from DHCP Renewal and Rebind failures?
I'm using an Ethernet shield with the built-in Ethernet library. I obtain an IP address using DHCP, and call Ethernet.maintain() periodically to ensure that the DHCP lease is renewed as required. So far I've never seen this fail, but maintain() can return error codes for renew fail and rebind fail and I assume that I should be handling them. What conditions would cause these errors to occur, and what's the best practise for recovering from them? Is it enough to call Ethernet.maintain() repeatedly until it returns cleanly, should I call Ethernet.begin() to reinitialise the Ethernet shield, or would it be best to reset both the Arduino and Ethernet shield using the watchdog timer?

You would have to set some requirements. Like, you can only lose connection for +5 minutes. Than you can try 5x once a minute (or smh). And if that won't work, you can call Ethernet.begin();. And if Ethernet.begin keeps failing, ultimately a buzzer sound/red light with diagnostic messages over your USB connection ;). This way you avoid your system being bricked when you never get a renew or new lease. The diagnostics may also prove very useful.

Possible causes:

The DHCP server might be down.
Or it might have lost its state (but I think they try really hard to preserve the list of leases).
Or some other cause which makes the server unavailable/unwilling to renew the lease.

Solutions:

If you can wait, you can retry, but otherwise I'd just say try to obtain a new lease, unless for some reason you really want to stick to the IP from the previous lease.
If you control the server and your network is kinda stable, you could assign a fixed IP to your device configure the server to associate it with the MAC address you gave to your device. In general, when the network setup is really stable, this might be preferable, since other entities on the network will probably cache the IP of your device and use it, should the DNS fail as well (ex: dnsmasquerade works both as dhcp server and dns). Similarly, your device doesn't have to worry anymore of the DHCP lease, because it's permanent.

What you described is not so much Arduino specific. Whenever you have a device in a dynamic network, you can experience the same effects.

I appreciate that the problem of DHCP errors isn't Arduino-specific, but the best way to recover from them probably is. I wondered whether repeatedly calling Ethernet.maintain() was guaranteed to renew the lease at some point (i.e. whether either the Ethernet library or DHCP server would have the intelligence to begin a new lease, possibly with a different IP address, if the old one couldn't be renewed). However, calling Ethernet.begin() to guarantee starting a new lease seems more sensible, and from the testing I've done it doesn't appear to have any negative side-effects.

source: Stack Exchange

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

sort: votes


text:
Difference in Arduino pin distance
I have an Arduino Uno rev 3. Today i tried to mount a breadboard as a shield for my Arduino on top of it. I plugged in the pin headers i bought and was surprised that the breadboard won't fit. As you can see in the picture below the distance between Vin and A0 is exactly the size of a pin, but the distance between pin 7 and 8 is less than that and so the breadboard won't fit on this side. What's the reasoning behind this (in my eyes) bad design ?

It is a mistake that became a feature for polarizing the shields: http://forum.arduino.cc/index.php?topic=117441.0

Thank you. If that wouldn't be so sad it would be a joke...

http://forum.arduino.cc/index.php/topic,22737.0.html is the older discussion, with pics of early prototype boards.

Arguably, if shields could be plugged in either way around (and the wrong way damaging the Arduino and/or the shield) then that could be called bad design.

@NickGammon  That's the feature part.    Maybe a better way to key a protoboard/shield would be to block a pin or two.  I think I remember seeing a red plastic plug used to block/key a in the socket on a IDE disk drive connector.

That is probably a better idea. Ah well, it's like the old joke: "There's no reason for it, it's just always been done that way!"

It is a mistake that became a feature for polarizing the shields: forum.arduino.cc/index.php?topic=117441.0
In an 2008 discussion Massimo says:

"I made that mistake, when I made the first arduino board."

at http://forum.arduino.cc/index.php?topic=22737.msg171839#msg171839
with:

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


text:
XBee unstable sensor data transmission
I am using two XBee Series 2 modules (Zigbee), an Arduino Uno, and a HC-SR04 Ultrasonic sensor to send distance readings from the coordinator XBee on the Arduino to the XBee connected to my computer. I configured the ArduinoXBee as "Zigbee coordinator AT" and the ComputerXBee as "Zigbee end device AT" with the following networking settings:
Coordinator:
PanID: 1234
DH: 0
DL: FFFF
End Device:
PanID: 1234
DH: 0
DL: 0 (so it can only talk to the coordinator)
The problem I am facing is that when I open the End Device terminal on X-CTU, the distance readings I get are accurate yet very unstable. Like it receives the correct readings but the transmission is unsynchronized as it sometimes receives 5 numbers in one transmission and lags for 10 seconds then receives the next bunch and lags for another 10 seconds and so on...
The arduino code is:
#include <SoftwareSerial.h>
const int trigPin = 13;
const int echoPin = 9;

SoftwareSerial xbee(10, 11); // RX, TX

void setup()  {
   xbee.begin( 9600 );
   pinMode(trigPin, OUTPUT);
   pinMode(echoPin, INPUT);
}
void loop()  {
long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  xbee.println( distance );
  delay(500);
}

Can anyone help me?

Probably the end device is set into sleep mode. Check the Sleep Mode(SM) and the sleep period(SP) because what I can see is the XBee gives readings for every 10 seconds.


text:
How to sleep a whole circuit?
I have just completed my first project, a clone of the Simon game of the eighties. The main parts of the circuit are an ATMega328, a 1602 2x16 LCD, and a small joystick.
It is powered directly from 3x1.5V batteries with solder bridges connecting all power pins on each part directly to the batteries. Therefore, if I sleep the ATMega, it won't change a thing comsumption-wise, as the LCD will still be powered.
What are (my first project, I am very unknowledgeable) the possible strategies to sleep the whole circuit?
I thought of using an ATMega pin as a positive lead for the joystick and LCD. Is that feasible?
Another strategy would be to interface some component (a relay?) between the battery and LCD, and command that component from an ATMega pin. Does someone know the right part for the job (I have a 220V relay in my parts, but it seems overkill)?
Lastly, even though it seems unlikely, is there a possible strategy without using any ATMega pins, as I currently use every single one (4 buttons, 4 leds, joystick x, y, and button, 1 buzzer, and 6 pins for the LCD, for a total of 18) except Rx and Tx?

The LCD should use that much current, as long as you turn of the backlighting. By the way, are you using a bare ATMega328, or are you using an arduino board, like e.g. an UNO?

You could use an NPN transistor between the battery and the Gnd for the circuit.  As soon as you want to sleep the circuit just take the Base pin down to Gnd.

I am using a bare ATMega328, Gerben. Thanks for the NPN transistor hint, Matt; I didn't know of their existence until this moment :)

@Matt there is just a problem with your approach: to take the pin down to ground you need, well, ground. If you detached it you will have problems. In this case, you'll have to use a pair of complementary transistors (PNP and NPN) to invert the logic. Then, I think it is much better to cut the positive rail instead of the ground one. And.. I tend to prefer MOS transistors over bipolar ones ;) Check my answer for what I think is the best solution

@frarugi87 I think picking fault with an answer just because it won't work is mean :)  I'll give your answer a try next time I get chance.

See my post about power saving.

@Matt sorry, I didn't understand your comment ;) Anyway I know that the single transistor solution doesn't work because, well, I actually implemented it in one of my circuits. Then I told myself "you are stupid!", threw away the circuit (which, since there was no ground, was never really off) and started using a dual transistor solution every time I needed it ;)

The first and most smart solution is to use a switch between the batteries and everything else. This way, you slide the switch in the off position and the whole circuit is completely detached from the batteries: power consumption: 0.
If you can't (because, for instance, you want it to automatically power off after a while) you can use a transistor (PMOS, for instance) instead of the switch. you have then to put a complementary transistor (NMOS) on its gate, then a button in parallel to it. Just another passve component is required: a resistor (value e.g. can be 100k). When you press the button, the circuits becomes momentarily powered on. You will have to pull the nmos gate to a logic 1 with the atmega to keep the circuit powered. When you want to turn everything off, pull the pin to a logic 0 and your circuit will immediately shut down.
If, third solution, you want to give the atmega complete control over the powering, it needs to be always on. You can then omit the complementary transistor and use a reverse logic on the pin (so 0 = on, 1 = off) and then you can do whatever you want with the power (turn on and off whenever you want).
edit: as a comment suggests, it can be better to put a resistor to set the appropriate voltage on the gate at power up. Even if the commenter told to put a pull-down, I suggest you to put a pull-up (pull-down = normally on, pull-up = normally off). edit 2 as Paul suggested, there could be cases in which you need to be able to turn on and off automatically the circuit, and then store it for longer times without consuming battery. In this case it could be a good idea to put something (a mechanical switch, a jumper, a detachable wire) to completely detach the battery even from the arduino (even if, in this case, you can just remove the batteries from the housing).
Here is a small paint-made sketch to show the solutions. If you have any questions just ask ;)

EDIT: If you want to let the atmega control the power, you'll have to give him a way to do so. Which means.. You should use a pin. If you want you can use safely the RX and TX pins, as long as you don't enable the serial interface. If you need more pins, you can try to optimize your pins usage (for instance using a 4:1 multiplexer for the buttons you will have 2 control pins and 1 input, for a total of 3 pins, instead of 4), even if I think that the best solution is to use a port expander. for instance in the past I used the MCP23017, which has a I2C interface, or the MCP23S17, with a SPI interface. You will have to use the serial interface you choose (I2C: 2 pins - SCL and SDA, SPI: 4 pins - MISO, MOSI, SCK, SS, but they are the same pins used for programming), and then you will have 16 more pins for your uC
EDIT BY foivaras:
The same result can be achieved utilizing an NMOS instead of a PMOS.This would have an advantage over PMOS solution if power line was >5v and arduino was powered by a dc to dc converter. On this scenario, PMOS solution would need one more transistor to work.
Notice that the NMOS has to be placed on the low side of the power line and it will cutoff the power to joystick and lcd with 0v  and enable the power with 5v on its gate.(See 4th image)

COMMENT BY fra87
This solution is not a valid alternative in my opinion. Usually interrupting ground is a bad idea, because usually the rest position of the I/O pins is ground: if you interrupt the ground for the LCD, for instance, you will have +5V on the VCC pin, and a floating ground, but you will have 0V on all the I/O pins, possibly damaging the internal circuits. Moreover having a floating ground is bad in terms of noise protection.
The only advantage COULD be in the particular case explained by the editor, which is a DC/DC converter powering the arduino but not the LCD and the Joystick. This is a strange setup, though, and the proposed solution is better at a first glance (requires one less transistor), but is wrong. For instance, let's suppose the joystick is powered at 12V. If you detach the ground, the joystick will "shut down", which means that all its pins will float up to 12V. This means that on the arduino pin you will see 12V: you can damage it.
So, in the end, I discourage this solution. The only case when you can need it is when you are in a hurry and do not have any feasable PMOS: even in this case, however, I suggest you to replace the NMOS with a PMOS as soon as possible.
Just one more note: edits to the posts, in my opinion, should be done to improve the quality of the answer, by better formatting the content, removing orthographic errors and so on. If someone needs to add some comments or other solutions, it's better to use the comments or add another answer to the thread

I 'd consider putting a pull down resistor on the gate of the PMOS(3rd image) as the pins of arduino on power on or restart, are on high impedance state hence PMOS's gate state will be undetermined until the corresponding arduino's pin is declared output.

I would also consider adding a physical switch in front of the Arduino, to avoid draining your battery.

@foivaras I definitely prefer a pull-up, to keep everything powered off until requested. Anyway thanks, I added this to the answer

@Paul the physical switch solution is the first one I proposed (and the one I think is the best). In the third solution a switch is completely useless in my opinion, because the only reason to implement it is when you want to power up everything automatically, and switching off would prevent you from doing it

@frarugi87, it's actually pretty common on TV's.
You can put them on standby, to allow switching it on with a remote.
And you can totally power them off, with a physical switch.
If you don't use any sleep modes, and use an Arduino board, your battery will get drained significantly, so you can't really store it (withouth disconnecting the battery).
If you use a barebones microcontroller with the deepest sleep options, a switch might not be needed, since the current draw can be lower as the self-discharge rate of a battery.
But yea, it's a combination of the options you gave, but well.

@Paul In this case usually you can just, well, take the batteries out ;) if they are not soldered, of course. Anyway I added your contribution to the answer, so the reader can think at what is the best solution (and maybe think about this before doing the whole circuit) ;) thank you. And, BTW, I haven't seen a power switch on TVs for years ;) with modern TVs you have to pull away the power cord if you want a complete shut off

@frarugi87, old ones indeed. But yeah, fair enough ;)
Standard 1800mAh batteries will "only" last 150u with 12mA load.
(https://www.avrprogrammers.com/howto/atmega328-power) "At 8MHz the ATmega328 draws 11.68mA @ 5V. (1Mhz will be half of it).
So indeed, use sleep modes (or a switch). If you don't want to unplug the battery everytime. (having to change batteries every 8-16 days is not going to be nice)

You wrote: “if you interrupt the ground for the LCD [...] you will have 0V on all the I/O pins, possibly damaging the internal circuits.” You should obviously tri-state the I/O pins on the ATmega side before disconnecting the LCD ground. “a floating ground is bad in terms of noise protection”. Just as bad as a floating Vcc.

@EdgarBonet I've always been taught that ground should be only one; having different gnd (except when you have analog and digital ones) is a bad idea. All the noise immunity methods presume you have a common ground; the vast majority of circuits have ground planes, not vcc planes (only 4+ layer boards also have power planes), DC/DC converters create Vcc with respect to ground, not vice versa, if you have a shielding it should be connected to ground, never to vcc. Then, there are a lot of cases when interrupting gnd or vcc is the same, but I always try to interrupt gnd only when strictly needed

@Paul of course you need to have to possibility to set a deep sleep mode on the uC if you want to permanently power it from a battery; the only time I used such an approach was with a Texas Instruments uC which consumed around 0.8uA in sleep mode. Powering a uC not in sleep permanently is always a bad idea, unless you are a battery manufacturer ;)

In CMOS circuits, GND and Vcc (or rather, Vss and Vdd) play symmetrical roles. The fact that we always take the negative side of the supply as the reference, and call it GND, is essentially a matter of convention and history. Like or choice for the direction of the “current”, which is actually backwards relative to the electron flow.

@EdgarBonet sure, for standard CMOS circuits everything is highly symmetrical. But as soon as you take something else (analog circuits, RF, power supplies) things change. Switching DC/DC are an example: you can safely detach VCC from it, but you can't detach GND without careful thinking at every possible drawback. Even CMOS logic ports can have problems: for instance the AHC family has no parasite diode from the input pins to vcc: this means, for instance, that you can apply a 5V voltage to a 3.3V powered device without damaging it. This also means that if you power it off detaching vcc you

won't have to tri-state the input pins controller. If you detach ground, however, a logic 0 of the controller means -5V for the input pin, thus possibly damaging it.. Usually powered off means at ground, so everybody designing circuits will refer to this as the common powered off condition: if you pull everything to vcc, well, maybe it's the same, maybe not

thanks frarugi87 for the answer and everyone for the lively discussion. I'll be less dumb today than yesterday :)


text:
Standalone chipset, power regulation & pinout
I have succesfully (or so the ide says) burned a bootloader on an ATMega328P-PU chipset, and uploaded my sketch on it.
It appears a voltage regulation is absolutely needed, if I want to solder a pcb with the standalone chip, rather than an arduino. Is that correct? Can I build one out of my starter kits parts (assortment of transistors, diodes, zeners, resistors and capacitors)?
In the meantime, I would like to make sure the chispet is functional. Can I power it from GND/5V of an arduino? Will it take care of that power regulation?
If I can, what is the correspondance between the arduino pins, and the ATMega328P-PU pins? I have this page here : http://www.learningaboutelectronics.com/Articles/Atmega328-pinout.php
referencing the chipset pinout. Am I correct in assuming there is a correspondance with the arduino pinout in the reading order of this chart, ie. :
PD0 to PD7 are Rx, Tx, digital pins 2 to 7 on the arduino, PB0 to PB5 are digital pins 8 to 13, and PC0 to PC5 are A0 to A5 on the arduino?
Thanks for reading.

You are correct about the pin correspondence. C.f. this Arduino Uno pinout diagram.

Voltage regulation is needed if the voltage you are providing to the chip is outside (or can drift outside) the allowed range for the chip to operate.
At the upper limit that is 5.5V. The lower limit is 1.8V. Note that at lower voltages you can only reliably run at lower clock speeds.
If your power source is between those two voltages (say a 3.4V LiPo battery) then you don't need a regulator.
If your power source is above 5.5V (say a 9V PP3 battery [urgh]) then you definitely need a regulator.
A proper regulator is quite a complex device, and it is highly unlikely that you have the components to make one.  A simple, very inefficient one, though, can be made using a resistor and a 5V Zener diode if you have one.

Until you have your own regulator of whatever form, yes, you can power the chip from the 5V pin of the Arduino.
The pin mapping for the chip -> Arduino IO numbers is in the file pins_arduino.h for the Uno variant in the IDE.  In the top of that file is this handy drawing:
// ATMEL ATMEGA8 & 168 / ARDUINO
//
//                  +-\/-+
//            PC6  1|    |28  PC5 (AI 5)
//      (D 0) PD0  2|    |27  PC4 (AI 4)
//      (D 1) PD1  3|    |26  PC3 (AI 3)
//      (D 2) PD2  4|    |25  PC2 (AI 2)
// PWM+ (D 3) PD3  5|    |24  PC1 (AI 1)
//      (D 4) PD4  6|    |23  PC0 (AI 0)
//            VCC  7|    |22  GND
//            GND  8|    |21  AREF
//            PB6  9|    |20  AVCC
//            PB7 10|    |19  PB5 (D 13)
// PWM+ (D 5) PD5 11|    |18  PB4 (D 12)
// PWM+ (D 6) PD6 12|    |17  PB3 (D 11) PWM
//      (D 7) PD7 13|    |16  PB2 (D 10) PWM
//      (D 8) PB0 14|    |15  PB1 (D 9) PWM
//                  +----+
//
// (PWM+ indicates the additional PWM pins on the ATmega168.)

Thanks, very nice answer with additional material for me to read! :)


text:
Proximity sensor without proximity sensor; is my hand magic, my competency crap, or my arduino fried?
here is a very simple circuit, with a LED between pin 2 and ground, and a loose wire in pin 8.

Here is the sketch that was intended for use with a small 4-contact switch like these in every arduino starter kit :
int yellowCIn = 8;
int yellowCOut = 2;

void setup() {
  pinMode(yellowCIn, INPUT);
  pinMode(yellowCOut, OUTPUT);
}

void loop() {
  if (digitalRead(yellowCIn) == HIGH) {
  digitalWrite(yellowCOut, HIGH);
  }
  else {
    digitalWrite(yellowCOut, LOW);
  }
}

However, simply moving my hand near the loose white wire is enough to light the LED, moving it away to put it off. As I am writing this, with the arduino connected by usb, rather than on the blue battery visible in the picture, I notice moving my hands away from the keyboard lights the led, moving them close to the keyboard powers it off...
So back to my title : are my hands magic, my electronics competency crap (well, it is, for sure) enough that I never heard of such a tremendous static electricity effect (and never fried one of the many computers I built from parts), or does this board have dire problems?
Thanks for your attention :)

Nothing's broken; you have discovered  the nature of a floating pin.  Unfortunately, that means that strange things happen...
A very small charge from your hand is triggering the logic because the state of the pin (high or low) is not set.  To fix this, you need to add a pull-up or pull-down resistor (or activate the internal input-pullup resistor).
You can read about how to accomplish this here.

Sorry for the dunce questions, hopefully I get to the level of not being a dunce soon enough to not get SE to hate me. Thanks :)

It was NOT a dunce question by the way - it's the difference between building a computer from ready-made parts (motherboards and slot-in cards), and the far more complex business of building those parts yourself.

@pouzzler I had the exact same problem when I first started using buttons :D. You're not at all alone; that's what this site is for

Try configuring your input pin as INPUT_PULLUP instead. This connects an internal pullup resistor to stop the input value from drifting around.
I would only use the "INPUT" mode on its own if I have that pin wired to something on the board and the levels won't be erratic.
Your hands are magic - they pick up interference from various sources and the high impedance input of the chip pick this up...
(There's a bit more on the modes here: Arduino DigitalPins page)


text:
Audio/Voice Recording Device
I'd like to build a little voice recorder for my grandmother. She told me "I get a lot of idea when I'm driving but then I forget them. I want a necklace where I can just press a button and it'll record my voice and I can press a button and it'll stop recording." She wants each recording to save as a separate file. I was thinking of concealing a mini Arduino board or Rasberry Pi or something in a necklace, with a removable micro sd card. Or something like that. I just don't know where to start, I don't have much experience with this. Does anyone have any tips on what kind of device I could use or where to start? I suggested that she just have Siri take notes for her on her iPhone but she wants something around her neck, and she wants me to make it.

Try this amazing breakout board. Its all you need. SparkFun Voice Recorder Breakout - ISD1932
Moreover, If you thinking on letting that device talk back, try this: VoiceShield
Well, there is also an instructable for this, HERE. This Instructable will show you how audio input can be repeatedly added to a 512 byte buffer and then transferred to a SD card in real time. The audio file can be played back on a standard audio application or analysed byte by byte.

Thank you for the start! The SparkFun breakout board seems to have been discontinued, do you know of any similar ones? The closest thing I could find was the ICStation ICSH041A, and I really couldn't find much of a description of it.

This one is easily available and easy to use. And One that is mentioned here is amazing but might be little expensive.


text:
Arduino countdown timer preventing rest of program running
have a program that checks to see if an RFID tag has been read, if it has, it runs some code.
I also have a count down timer function (timer) that I'd like to run in the background. It displays the clock on the bottom of the LCD.
The problem I'm having is that when I put timer(); in the main loop, the rest of the program is delayed for the duration of the count down which means that no RFID cards are read.
The timer works, but nothing below timer(); is running. I assume this is because of the use of delay.
Does anyone know how I can prevent this? Thank you.
    #include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

int readflag;
int initstate = 1;

int nextred = 4;
int nextblue = 8;

uint8_t readCard[4];

int minutes = 1; //start min
int seconds = 0; //start seconds

MFRC522 mfrc522(10, 9);
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

///////////////////////////////////////// Setup ///////////////////////////////////
void setup() {

    //Protocol Configuration
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();
  mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max);

  lcd.begin(20, 4);

}

///////////////////////////////////////////////////////////////////////////////
  // Main loop
///////////////////////////////////////////////////////////////////////////////
void loop () {

 do {
   readflag = checkread();
if (initstate == 0) {
  timer(); //start timer - timer works but nothing below timer(); is running.
   lcd.setCursor(0,0);
   lcd.print("Red team next: ");
   lcd.print(nextred);
    lcd.setCursor(0,1);
    lcd.print("Blue team next: ");
    lcd.print(nextblue);

}
  }
  while (!readflag);
  tone(8, 850, 15);
  recordid();
  updatenextteamnumbers();
}

///////////////////////////////////////////////////////////////////////////////
  // Function to update team next numbers
///////////////////////////////////////////////////////////////////////////////
void updatenextteamnumbers() {
//If Blue Tag scanned show team info
  if (*((uint32_t *)readCard) == 0xACB7D573) {

    Serial.println("Blue Tag detected, showing team info");
    initstate=0;

   }

//Red Team (sequence 4, 5, 2, 1, 9)
else if (*((uint32_t *)readCard) == 0x29FDC9F5 && initstate == 0) {
    Serial.println("CARD 4 detected");
    nextred = 5;

      }

else if (*((uint32_t *)readCard) == 0x3FCE7832 && initstate == 0) {

    Serial.println("CARD 5 detected");
    nextred = 2;

}

else if (*((uint32_t *)readCard) == 0x3FCCECE2 && initstate == 0) {

    Serial.println("CARD 2 detected");
    nextred = 1;

      }

  else if (*((uint32_t *)readCard) == 0x3F7AB752 && initstate == 0) {

    Serial.println("CARD 1 detected");
    nextred = 9;

    //activateredrelay

      }

  else if (*((uint32_t *)readCard) == 0x00000000 && initstate == 0) {

    Serial.println("CARD 9 detected");
    redwins();

      }

//Blue Team (sequence 8, 6, 3, 7, 10)

else if (*((uint32_t *)readCard) == 0x00000000 && initstate == 0) {
    Serial.println("CARD 8 detected");
    nextblue = 6;

      }

else if (*((uint32_t *)readCard) == 0x00000000 && initstate == 0) {

    Serial.println("CARD 6 detected");
    nextblue = 3;

}

else if (*((uint32_t *)readCard) == 0x3F7ABA82 && initstate == 0) {

    Serial.println("CARD 3 detected");
    nextblue = 7;

      }

  else if (*((uint32_t *)readCard) == 0x00000000 && initstate == 0) {

    Serial.println("CARD 7 detected");
    nextblue = 10;

    //activatebluerelay

      }

  else if (*((uint32_t *)readCard) == 0x00000000 && initstate == 0) {

    Serial.println("CARD 10 detected");
    bluewins();

      }

 }

///////////////////////////////////////////////////////////////////////////////
  // Stores the ID of the card that's been detected in readCard byte array
///////////////////////////////////////////////////////////////////////////////
void recordid() {
    mfrc522.PICC_IsNewCardPresent();
    mfrc522.PICC_ReadCardSerial();

    for (int i = 0; i < mfrc522.uid.size; i++) {
        readCard[i] = mfrc522.uid.uidByte[i];
        Serial.print(mfrc522.uid.uidByte[i], HEX);
        }
Serial.println("");
    mfrc522.PICC_HaltA();
  }

/////////////////////////////////////////////
  // Returns 1 if a card has been detected
/////////////////////////////////////////////
int checkread() {
   if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return 0; }                                        //no card detected

    mfrc522.PICC_HaltA();
    return 1; }                                       //card detected

/////////////////////////////////////////////
  // Runs if red team wins
/////////////////////////////////////////////
void redwins() {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Red team wins!");
      lcd.display();
      Serial.println("Red team wins!");
      delay(36000);
}

 /////////////////////////////////////////////
  // Runs if blue team wins
/////////////////////////////////////////////
void bluewins() {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Blue team wins!");
      lcd.display();
      Serial.println("Blue team wins!");
      delay(36000);
}

 /////////////////////////////////////////////
  // Count down timer
/////////////////////////////////////////////
void timer() {
lcd.setCursor(0,3);
  lcd.print("Time left:");
 while (minutes > 0 || seconds >= 0) {
  lcd.setCursor(15, 3);
 (minutes < 10) ? lcd.print("0") : NULL;
 lcd.print(minutes);
 lcd.print(":");
 (seconds < 10) ? lcd.print("0") : NULL;
 lcd.print(seconds);
 lcd.display();
 decrement();
 delay(1000);
 }
}

 /////////////////////////////////////////////
  // Decrement timer
/////////////////////////////////////////////
void decrement() {
      if (seconds > 0) {
          seconds -= 1;
      }
      else      {
         if (minutes > 0) {
           seconds = 59;
           minutes -= 1;
          }
          else  {
            timeup();
          }
       }
}

 /////////////////////////////////////////////
  // Called when time expires
/////////////////////////////////////////////
void timeup() {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Time up!");
      lcd.display();
}

Does the timer count at all? Show us an image of what u see on your LCD and in the serial monitor

Of course not - your timer() function is blocking meaning that it does not return, and so does not permit anything else to execute, until its timing is completely done.
You will need to re-design your program.  Some options include:
1) Capturing an initial timestamp from millis() and comparing to it on each iteration through loop() to decide when your time has approximately elapsed, and to update the display with an appropriate value if that point is not yet reached. This is probably the best choice for your application, but be aware that after about 50 days of uptime, the difference calculation can be briefly incorrect, unless you account for overflow.
2) Place a short delay in the main loop (maybe 100 ms), and count iterations of the main loop until you have reached your desired time.  Beware though that your effective time will become longer if other parts of the loop take time (especially variable amounts of it) to execute.
3) Set up an event timer in the background with interrupts.  This is a lot more complex and probably not advisable in your application.


text:
Flickering LCD backlight with fingerprint scanner
I have the following problem: for some *** reason, my LCD is flashing when my fingerprint scanner turns on. Here is a video of the behavior: https://www.dropbox.com/s/mqk4u0vu8yvhiwz/IMG_3171.m4v?dl=0.
More details: I have a membrane keypad. When I start typing on it, the LCD turns on, and when I type the correct code, the fingerprint scanner turns on, and the LCD prompts the user to press a finger upon the scanner. However, then the LCD backlight starts flashing badly. Interestingly, if I just plug the wall adapter into the arduino and try the scenario, the LCD does not flash. However, if let's say 10-15 have passed since the adapter is plugged in, the LCD flickering becomes visible and irritating (again, when the fingerprint scanner is turned on). So, what could be the reason and how to fix it? Why if I just plug the adapter and execute the scenario, the LCD does not flash, and if I wait some time with the adapter plugged in, and then execute the scenario, the LCD flickers?
Just to add: My fingerprint scanner is GT511C1R (https://www.sparkfun.com/products/13007) and I am using the standard scheme for wiring it (560/1000 ohm for the RX). I am not using lcd.clear() command as I know it's heavy, and even if I don't write any text, the still LCD flickers.
Best regards,
Nike

Sounds like lack of power. What kind of power supply are you using? Is the regulator on the Arduino getting hot?

I have tried with two supplies: 1. simple small wall adapter, can't recall it's exact specs, but given its size, it will not be more than 10 watts 2. big 150 watt supply dedicated to carry a lot on it. If by regulator you mean the stuff surrounding the female 12v plug of the arduino - then, yes, it's hot.

Interesting why at the beginning (first ~10 secs) of the 'life' of the charged Arduino everything seems ok and then little by little, the LCD starts to flicker.

It sounds like you are on the cusp of thermal shutdown. Power the LCD and fingerprint scanner from a separate 5V power supply.

I sooo much wanted to avoid  that if possible, and therefore trying to find another cause of the problem. Interestingly there are tutorials on LCD + FPS on the internet like this one: http://www.instructables.com/id/fingerprint-arduino-with-16x2-LCD/ or this one: http://www.instructables.com/id/DIY-Fingerprint-Scanning-Garage-Door-Opener/ but nobody's talking about flickering in the tutorial, nor getting power from two power supply as far as I can see.

Just to mention that if I only try the FPS on another Arduino board, I get the same effect - in the beginning all seems stable, but next moments further the FPS light starts flashing: https://www.dropbox.com/s/4qe4qrd66x631en/IMG_3168.m4v?dl=0

You can use the same power supply to give a global 12v rail but step that down to 5v separately using a small switching regulator. They are cheap enough on eBay etc and avoids having another brick.

The backlights on these LCDs are just an LED array with a series resistor so the intensity will be directly proportional to the input voltage; flickering voltage = flickering backlight.
Check these things:

Measure the output of the 5V regulator with an AC volt meter to see if the regulator is oscillating when the backlight flickers, i.e. AC voltage >> 0V.  If it is, then you probably need to increase the size of the output and possibly the input capacitors.
Measure the Input-to-Output voltage differential of the regulator and multiply it by the output current.  If you dissipate more power than the thermal design allows this will heat the regulator making (1) more likely as well as driving the regulator into thermal shutdown.

If the regulator is linear, i.e. 7805 etc, you can solve both (1) and (2) by changing the regulator to a drop in switching type.  These will dissipate heat as a percentage of the output power instead of as a function of the input voltage and can be made self contained with regard to input/output capacitors which would be on-board instead of off-board.  A switcher can also do something a linear can't do:  Supply more current than the source.  A 12V 0.5A power supply into a 5V regulator can supply 5V at 0.5A with 3.5 watts of waste heat.  That same 12V supply into a decent switcher can deliver 1.14A at 5V with only 300mW of waste heat!
This PDF is an example circuit that runs about 95% efficient and fits on a 7805 footprint.
This PDF is the circuit of the 1516 switcher linked above configured to replace the NCP1117 linear regulator use on the Uno Rev3.
This PDF is a full thermal analysis of the Arduino Uno NCP1117 regulator running under the conditions stated in your question.  As you can see, you were right on the edge of what the NCP1117 could handle at 200mA (LCD plus scanner).  I have included a thermograph showing the same unit supplying 1.85A at 5V using a drop in switching regulator with no issues.

It looks like the Uno uses a SOT-223 linear regulator that has a 150C/W thermal resistance with a 150C die limit:  (150C-25C)/150C/W = 833mW.  At 12V in and 5V out, this limits the output current to 833mW/(12V-5V) = 119mA max output current.  A typical 2x16 LCD with green backlight draws 115mA at 5V leaving 4mA in your current budget for everything else.

The fingerprint scanner that you indicated has a supply current specification of <130mA, but I'm pretty sure it's closer to 130 than zero!  I'm surprised your circuit runs at all.

A huge thanks for your detailed replies! They lead me into the very right direction. So here is what was it: As I mentioned, the situation gets worse as more time passes with the 12v jack plugged in. At the same time, the regulator was getting damn hot, I could not stick my fingers to it for more than half a second. So, I kind of did what you recommended - got a regulator and put down the voltage to 7V (with 5V the display did not want to show any text). With 7V the regulator is still getting warm, but even if I left it for 10 minutes running it's not getting hot any further further. The display - it's flickering very little and only if you look at it at a specific angle, but it's not flickering overall if you look straight at it. Interestingly, I also took a look at the schemes of the display and the fingerprint scanner and it sounds like it would not be possible for the arduino to feed these two. But, the whole project is running flawlessly (at least looks so). I just hope that math equations in regards to the mA would not cause harm to the fingerprint scanner or the arduino.
So, thanks again, for your kind and detailed replies, much appreciated.
All the best,
Nike


text:
How can I power an Arduino Nano with a LiPo battery, preferably 3.7v
I am a newbie to Arduino, so please bear with me. I am trying to figure out how to power an Arduino Nano with a LiPo battery. I want to use a 3.7v if possible, as my project needs to be lightweight. There are two possibilities I know could work:
-Taking a USB to Mini-B USB, cutting off the normal USB end, and soldering a connector (based on the battery I use) to that end. I would then plug the Mini-B USB into the Nano, giving it power.
-Using the 5v and Ground pins.
I would prefer to use the USB cable solution, however the 5v/Ground or any other solution is perfectly usable.
Also, would 3.7v be enough to power the Nano, two Infrared LEDS (Launch and Receiver), and a 7-segment LED display. I also have a button.
                                                             Thanks, saddlepiggy!

In short: not reliably.  The Arduino Nano expects either a 5V regulated supply or a 6-20V unregulated supply (https://www.arduino.cc/en/Main/ArduinoBoardNano).  Even if you plugged it in and it worked initially, the battery voltage will decrease gradually as it discharges (LiPo cells can drop as low as ~3.2V), making it more and more unreliable.  You'd technically be overclocking the processor, since the Nano runs at 16 MHz and the datasheet for the microcontroller requires at least a 4.5V supply to run above 10 MHz.
A safer solution would be to use a 2S LiPo battery (~7.4V), which would be plenty to supply the regulated input pin (VIN).  On the other hand, if you're set on using a 3.7V LiPo, other Arduino boards (like certain versions of the Pro Mini) run at 3.3V.
As for your second question, 3.7V is plenty to power a few LEDs so long as they are connected in parallel (or to separate pins).  The only thing you need to be aware of is current draw--more current means shorter battery life.  For example, if your circuit draws 100 mA total from the battery, and your battery is specified at 500 mAh, you will get approximately (500 / 100) = 5 hours of battery life.

You could set the fuses so that it runs on the internal 8Mhz clock. I'm not sure if powering the chip with 7.4V would do any good, since it's rated 5.5V (unless you use the regulater input).

So just to clarify, if I use a 7.4v LiPo,then I can hack the USB cable right? Or if I don't do that, could I use an alternate battery, like a AA pack or something?

Late to the convo but quick comment in case anyone else reads this thread still. Arduino uses a linear regulator on Vin. In that case the “extra” voltage gets wasted. You’d get a much more efficient battery use by using a buck or boost circuit to provide it the correct 5V on the 5V pin (or usb) rather than feeding a 2S LiPo into Vin. It would work both ways but you’d get noticeably longer run time with a switching power converter.

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


text:
Random numbers being printed back after entering data
I am currently working with an Arduino Micro / Linduino and making a program based on a lot of switch statements to execute certain functions that will be passed to a microprocessor (LT2974) on a board serially. For the most part, all of the functions I have work, except there is one that I am trying to determine if it is my program that is causing issues, or the Linear Tech libraries that are provided. Upon research, I did discover something strange in my code that I cannot explain.
Here is a quick snippet of my code:
unsigned long serialdata;
int inbyte;

long getSerial()
{
  serialdata = 0;
  while (inbyte != '/')
  {
    inbyte = Serial.read();
    if (inbyte > 0 && inbyte != '/')
    {
      serialdata = serialdata * 10 + inbyte - '0';
      Serial.print(serialdata);
      Serial.print("test \n");
    }
  }
  inbyte = 0;
  return serialdata;
}

void loop()
{
  getSerial();
  // Switch statement represents Slot choices
  switch (serialdata)
  {

    case 1:
      {
        commands(Slot1);
        break;
      }
    case 2:
      {
        commands(Slot2);
        break;
      }
    case 3:
      {
        commands(Slot3);
        break;
      }
    case 4:
      {
        commands(Slot4);
        break;
      }
  }
}

I have left out the following switch statements that are found in the commands function as they are not where the issue lies.
For some reason, when I pass data through to the Arduino, and then go to reprint it out with my Serial.print command in getSerial(), there is an additional number printing, and I believe the issue to lie here.
So, for example, if I type "/1/" (the slashes were used to pass multiple variables as shown in the function, but I'm only passing one for now), the Arduino reponds with:
1test
4294967268test

here is "/2/"
2test
4294967258test

and here is passing multiple variables with "/2/9/"
2test
9test
4294967258test

All of the values I just showed you do not correspond to any of my switch statements implemented, and so no actual data is being returned besides the print command from getSerial(). So can anyone explain what is going on here?
EDIT: I added the data types of serialdata and inbyte to the top of the post.

4294967268 is (unsigned long)(20 - '0').

The problem is that you are blindly reading serial data without first looking to see if there is actually any serial data available to read.
If there is no data there Serial.read() will return -1.  Since you have only provided a snippet of your program I can't say what data type inbyte is, but my guess is it's some form of unsigned 32-bit value, since -1 mapped into an unsigned 32-bit value is 4294967295.
You need to be checking the presence of data, and only reading when you should read, and also looking for the end of your data sequence (add some terminating character, like a line feed) to know when to stop looking for and reading characters.

I edited my post. Did you mean to say that you believe serialdata is a 32 bit unsigned int? because that is what I am printing and that would make sense. Also, I am reading the data and storing it to inbyte, but shouldn't it not go through the Serial.print part since the last character i am entering is '/' and I told it to ignore that?

Ah yes, serialdata of course I meant.

So it seems the issue is that my getSerial() function reads the data, stores it to inbyte, and doesn't recognize the data as <0 or '/' so it is going into the loop and printing that value to serialdata, which looks strange but is actually correct? So the next question is why is it going into the loop again then?


text:
Motor shield and sensors
While making a Arduino programmed maze runner Will bipolar motor shield be more beneficial than using tb6612fng motor shield???? Also which type of sensors will be better??

No. Especially with battery power you want to use a low-loss FET bridge rather than a bipolar one.  Sensors choices depend a lot on the maze pathway size, rules such as if you can see over the walls, etc.


text:
Arduino serial non-blocking
I'm writing an Arduino program to communicate with another module using RS485, so I need to control data flow with one pin. But when I set the pin to HIGH (line 88) it almost instantly falls (as you can see in the image, line 70). So my guess is that Arduino Serial.write() function is non-blocking, but I need it to be blocking so the flow control pin stays high during whole packet transmit. Please help. Thank you.

Please post the code as text rather than image. And indent it by selecting it and clicking the {} button. It makes things easier for those who want to help you.

You are right: Serial.write() is non blocking: it puts the data in a
buffer and waits for an interrupt routine to send it through the UART.
If you want to wait for the transmission to complete, you can call
Serial.flush().


text:
Arduino uno simulation software for windows
Could anyone help me for a good free arduino uno simulation software for windows.Hope I get an answer.

See Can I program for Arduino without having a real board?

Autodesk offers a service called 123D Circuits which works in a web browser provided you have an Autodesk account. It allows you to construct (simple) virtual circuits and run code on a virtual Arduino Uno. Regrettably, it doesn't offer very much in the way of diagnostics tools, isn't open source, and won't work offline. The advantage of a service like this is that it requires no installation and is functional for simple setups with a few components. It can be found at 123d.circuits.io

Thank you for that but Could you suggest me anything offline.

Can you please expand your answer? There is no link to anything (not that we want link-only answers) and nothing explains what "works in browser" means.

123d.circuits.io is the web address. Works in browser means it works in a modern web browser like Google Chrome or Mozilla Firefox. The answer has been edited to reflect this.

Indeed. Currently this answer will be useless if the service goes down. Please add more detail to make the answer useful even without the link.


text:
Arduino digital I/O pins
I heard that using digital io pins in INPUT_PULLUP mode is much reliable and stable than in the case of using them in INPUT MODE.Then why is INPUT MODE still used...I mean Why isn't INPUT_PULLUP mode put as default ??

I don't think that first statement is correct. It really depends on the application. Sometimes a pull-up is needed, sometimes it's not, or worse sometimes a pull-up will even make the circuit not work or damage external components.

When the internal pullups are activated, a small amount of current is sourced by the pin's circuitry whenever the input is low.
That means that to drive the signal low, an external driver must not only sink current to discharge the capacitance of the internal and external circuitry, but it must continue doing so to dominate the attempt of the internal pullup to make the line high so that the voltage of the resistive voltage divider formed by the internal and external resistors is low enough to be an unambiguous low.
This means that the external circuit must be stronger - not normally a problem for an active device, but potentially an issue for monitoring some very high impedance external circuit.  So for example, if you wanted an external pull-down resistor, it would have to be substantially lower in value than the internal pull-up.
It also makes low power design (long life on batteries) difficult, as a system cannot take advantage of the best micropower suspend modes when any signal is being asserted against the direction of a pulling resistor.  With just one or two such cases you might still get reasonable life when using flashlight batteries, but not with a coin cell, something a well designed ATmega circuit can presently do.
After seeing Igor's comment, and re-reading your post, it seems maybe you are asking why the default is to have them disabled, rather than why you have the ability enable/disable them at all.  Most likely, the reason the Arduino core software has them disabled by default is because the ATmega resets that way.  As to why the ATmega resets that way, you might have to ask the design engineers, but generally it has been the norm to have an MCU reset to a state where it has the least influence on the external circuitry.  However, that is not necessarily the best - floating (undriven) inputs can potentially cause a typical CMOS input structure to consume more power than ones weakly driven to a known value.

I haven't done any low power with AVR, but on larger SoCs it's common to have different pin configuration for sleep mode, where only the wakeup sources are left configured active, while the rest is programmed to minimize overall battery current. In this case the pullup could be disabled during sleep and re-enabled after wakeup. Assuming that the input is sufficiently stable. But most likely one wants to debounce it anyway, if it's a button or similar jittery source.

I guess I had actually misread the question a little bit, and instead answered a different one about why the pullups are not permanently enabled, rather than why they merely default to being disabled.  In terms of what to do during sleep/suspend, typically if you have something like a switch rather than a bipolar external driver, you want a pulling resistor holding the signal in the state expected while asleep, and to wake and deal with any change.


text:
atmega328 raspberry pi 2 communication
I have an atmega328p (running on it's internal 8mhz clock) receiving data over rf. I need the data received to be communicated to the raspberry pi 2 using its gpio pins, I cannot use USB. I don't have the budget for a gertduino. Is there any way to do this directly? I only need to be able to receive serial output on the pi, no uploading sketches.

Both the Arduino and the Raspberry PI have interfaces like SPI, I2C and UART. These interfaces will make it easy for you to communicate between the two. I suggest you search for UART unless you need a very high data throughput, then you need to go for SPI. But unless you want to send over a thousand messages per second UART will work just fine.

Just remember that if you power your uC with 5V you will need to level translate it, otherwise you can fry the raspberry and/or the atmega will not hear the rPI


text:
Relay doing opposite to digital pin
I have a Arduino UNO with a Ethernet shield which hosts a basic HTML page with a button on it which controls a Relay module.
I'm trying to connect to a computer's power button so I can turn it on remotely.
I have found out that the relay basically does the opposite to the digital pin's output
Normally open Relay
HIGH = Open
LOW = Closed
I connected it through a NOT Gate made using a NPN transistor and it works perfectly how I wanted it.
Now to the question... Is there a way to write the code to make the digital pin = HIGH straight away and fast enough to not allow the relay to close the circuit and accidentally turn the computer on/off when the Arduino restarts, so I don't have to use a NOT Gate.

It sounds like you have a relay module with an opto-coupler that is wired so HIGH = IR LED on = Phototransistor ON = power transistor OFF.  Either that or the IR LED is wired so that HIGH = OFF and LOW = ON.  You will have to show your schematic and relay module for us to be sure.

@Majenko Yes I think your right, I can't find a schematic but here's the link to it.
http://www.amazon.co.uk/gp/product/B009P04ZKC?psc=1&redirect=true&ref_=oh_aui_detailpage_o05_s00

What you actually have is one of these: http://www.sainsmart.com/arduino/arduino-components/relays/sainsmart-2-channel-5v-relay-module-for-arduino-raspberry-pi.html

I've solved the problem,
Thanks to everyone who helped.
I don't need a NOT gate anymore, here's what I added to make it work:
void setup() {
  startup();

}
void  startup() {
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
}
void loop() {
}
(I removed the rest of the code to keep it simple and easy to understand)

The relay module you have is this one from SainSmart:

http://www.sainsmart.com/arduino/arduino-components/relays/sainsmart-2-channel-5v-relay-module-for-arduino-raspberry-pi.html

The schematic is like this:

As you can see you connect VCC to +5V and IN2 to your IO pin.  Setting the IO to LOW will then turn on the LED and the optocoupler together.
But that's not the only way you can connect it up.
Connect VCC to the IO pin and IN2 to GND instead.  Then you set your output HIGH to turn it on.
The arrangement shown in the schematic is commonly done because some MCUs are able to sink more current than they can source thorugh an IO pin.  That is not the case with an Arduino which has symmetric IO pins that can sink and source the same amount of current.

Try This:
const On  = LOW;    // For non inverted logic swap on and off.
const Off = HIGH;
const pump = 5;

void setup() {
  pinMode(pump, OUTPUT);    // sets the digital pin 13 as output
}

digitalWrite(pump, On);
digitalWrite(pump, Off);

You could use a less invasive way to turn on your computer: wake on LAN. In this case you only need to generate the magic packet.
It won't work in forcibly turning off the PC, but it's more generic and doesn't require HW hacking.

The motherboard is too old to support Wake On LAN (it still has a floppy disk driver on it :D )
By the way, can a Arduino be used to send Wake On LAN packets?

Did you check in the BIOS? I can't remember having a PC without this feature, for at least 15 years. If you check the link I provided, you will see that you only have to generate an UDP packet with the specific content described and send it in broadcast mode. I have not tried it, but I do not see why it shouldn't work.

To ensure that relay doesn't switch between NO-NC when controller is away relay will need some memory.
Imagine having a 1 bit memory driving relay. If arduino dies/restart, its own GPIO may change, but relay's memory will remember last state and stay there, till controller instructs otherwise, granted relay circuit and its memory element don't lose power.
This also means there will be at least 2 lines required from uC to control this relay now.
I'd prefer to use some kind of serial shift register, e.g. CD4094, CD4042, CD4099 etc because that allows me to control more than one relays from same 2 lines on uC.
You may find some other part more suitable for your application.

I could also think of an alternate. If instead of BJT, you were using a mosfet, with low gate capacitance, you could just keep a capacitor at the gate to hold the charge, in absence of driving inputs from uC. This design would require that uC's lines go tristated when not driven, e.g. restarts. Such a capacitor would be able to hold the charge for a limited time, so your uC must reappear within some time limits.

Great idea, however I was trying to operate the relay with having a circuit between the Arduino and Relay board. At the moment I've build an NOT gate on a bread board which seems to be working.


text:
How is AVR Assembly in Eclipse or at Linux command line done?
I'm trying to learn AVR development in C and Assembly for the Arduino Uno (Atmel 328p microprocessor) in Linux.
I've found many good guides on how to install and setup the AVR plugin for Eclipse, and I've no problem building and uploading C code.
However there doesn't seem to be any menu options for creating an assembler project, nor can I seem to find the correct syntax for using the cli avr-as for assembling my programs into a .hex file.

In some cases you can simply feed a gcc variant with an .S file instead of a .c one and it will figure out what to do with it.  But that depends on having valid assembly files, and a compatible build setup.

If you don't mind using make, I'd recommend copying the Makefiles from ChibiOS. For me it works quite well and it's much more aligned to my daily experience with Linux.

The Arduino IDE and the arduino eclipse plugin support assembly.
Taken from the platform.txt
"{compiler.path}{compiler.c.cmd}" {compiler.S.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"

compiler.S.flags is empty and so is compiler.S.extra_flags and builds.extra_flags
leaving us with something like
avr-gcc -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {includes} "{source_file}" -o "{object_file}"

Which is something I think you can handle.


text:
How much voltage/current do I need for multiple chips?
I have a Huzzah ESP826 Wifi breakout chip which requires 3.3V power voltage and peaks at 500mA of current, and an LED strip which requires 12V and 1A.  How can I power both with one dc jack (I have a 12V 5A power supply) on one breadboard?

You need a voltage regulator for the esp. Preferably a dc-dc step down, which will neither waste power nor heat up. Other, passive solutions are possible but not desirable. The regulator can be found on ebay amazon etc.
EDIT:
One more thing about the LEDs: depending on the model you have, they might or might not work with 3.3V input (I'm assuming you want to drive the LEDs from the esp).
In case they take only 12V input, you will need some interface solution, like this one, for example.


text:
Trouble while using Arduino DUE as programmer
I'm trying to use the arduino DUE board as a  AVR Programmer. My target device is atmega328p. After uploading the ArduinoISP into the DUE Board. I've tried to let a pin toggle using the following code:
#define F_CPU 10000000
#include <avr/io.h>
#include <util/delay.h>

int main (){
    DDRD |= (1<< PD7);
    for(;;){
        PORTD ^= (1<< PD7);
        _delay_ms(1000);
    }
    return 0;
}

I want to use the internal oscillator and based this example  I've adjust the makefile:
DEVICE     = atmega328p
CLOCK      = 8000000
PROGRAMMER = -c arduino -P COM10 -b 19200
OBJECTS    = main.o
FUSES      = -U lfuse:w:0x62:m -U hfuse:w:0xd9:m -U efuse:w:0xff:m

the problem that I have is that when run :
make flash

I get the following :

and yes the port COM10 is definitely correct.
does anyone have a suggestion how to solve this ?
thanks in advance !

What are the fuses on the Atmega328P? And does it have a bootloader? You can find out this stuff if you have a spare Uno or similar around.

I'm voting to close this question because questions about avrdude errors that are long abandoned without followup from the asker are effectively unanswerable.

As there's a chance a specific keyword combination will direct people here from Google, I think it's better if it's marked as duplicate, so there's a link on top of the page that contains possible steps to solve this problem.

There error you have is from avrdude failing to get a communication link established to the 'programmer' (which manipulates the target.)
Here is a link that may help with the connection
Stk500 error
Here is another relative link that may help
Arduino ISP on DUE
Best of luck.


text:
Converting RGB from color sensor into the Munsell Color System
I am hoping I could get some help developing a an idea I have for archaeologists/soil scientists using an arduino and the TCS3200 colour sensor. The idea I have is a simple device which can determine munsell colours with more accuracy and speed. The current conventional method is to use colour chips/swatches found in the Munsell system booklet and match them as close to examples of sediment/soil found at archaeological sites. The problem with doing this method is that it is highly subjective, and time consuming.
My idea is to use the Adafruit TCS34725 to read and detect the RGB colour of the sediment (in the RBG colour space) and convert the data into the Munsell System. I have all the data of what RGB ratio corresponds to each Munsell colour -- which I have downloaded from this site: www.cis.rit.edu/research/mcsl2/online/real_sRGB.xls
My problem is that when I use the sketch provided, I can not figure out how to use the "if" statement to "Serial.print" what the munsell colour corresponds to the RGB colour detected by the sensor.
My ultimate goal is to modify the colour view sketch here see: colorview
I would like to keep the everything provided but change two things, I would like to convert RGB into Munsell using the data provided by the RIT link and also add a screen and button to start the read process and display the colour.
If some one would be willing to help me that would be great!,

Maybe use the routines at https://www.cs.rit.edu/~ncs/color/t_convert.html

That would be a helluva lot of IF statements. What you need is a Look Up Table (LUT) - i.e., an array in PROGMEM.

Yeah, I figured there would be a better way than using the IF statements, However I am not sure if I can generate the LUT with the sensor. What I might do is use a python program that preforms the conversions. And input the data from that using my raspberry pi.

Before you even think of implementing this on an Arduino, you should set up a system where the Arduino reports the RGB readings over a serial link to an easily monitored, size-unconstrained, "thinking in code"-friendly piece of experimental software running on your PC.  Only move an algorithm to the Arduino after you have a good idea that it is sound.

Which if statement? Your link points to the github repo, not to a particular line.

Also: are you asking for help with the board? If so, you may have better luck posting at the Adafrut fora; engineers from Adafruit also read those, and you may get an answer directly from the designer.
if you are asking for programming help, it is a really inappropriate thing to do. Learn to code, or hire someone to do it for you.

@JayEye Thanks, for your suggestion to look at the at the adafruit forum, as for learning code that is what I am trying to do. I just was asking if it would be even possible use the serial.print and if statements,  in that way. Sorry that you felt it was inappropriate I am not asking someone to write the code for me I was asking for suggestions/help.

None of us were born knowing how to code (well, most of us at any rate :) ). Sorry if I sounded harsh. Sometimes I type too fast and don't think about how my answer might sound. Cheers!

@JayEye Not a problem :) Its a bit of a learning curve for me but this is just a side hobby project.

I have some thoughts on your task. First of all colorimetry is a science on its own. I know people working in this field for decades with equipment costing many millions of €. They all share some basic wise words. One is: "Because we all see colours we think measuring colous is an easy task. The opposite is true. Many of the best colorimetrists are colour blind." One second is: "Without light there is no colour". I will write on this later.
Colorimetry in fact is a complex matter. Between a colored piece of stone and a numerical value normally lie a lot of transformations and convolutions. And inbetween there are also lurking many error sources.
This said, I'm sure it will be possible to produce somewhat acceptable results with your sensor. Provided you do a proper calibration and add a calibratable light source.
Speaking of light source. A piece of stone can only reflect incident light (except some uranium/radium salts, you don't want to deal with). Pigments are basically LTI-systems (aka passive filters). This means they can only reflect wavelengths which are present in the incident light. And the will reflect a well defined and individual proportion of each wavelength regardless the luminous flux of the incident light. This means, if your incident light contains nearly no blue light then the stone or whatever you want to examine will reflect only the fraction of "nearly no light" it typically does reflect of any amount of blue light.
So the remission spectra of all pigments get shaped (multiplied) by the spectrum of the incident light. Your sensor sees only the reflected light and therefore will give totally different results for one and the same object depending on the incident light. Look up the spectra for daylight and incandescent light and think about the results of your sensor.
To make a long story short, you can only yield reproducable measurements if you supply your own light source along with the sensor. This is in fact the way all colour meters work.
The only other way was to measure the full spectrum of the incident light. Reasonable portable spectroradiometers for this purpose cost 5000 €. So it's better to go for a light source :).
As they are rather affordable I recommend using LEDs to make up a light source for examination. But LEDs suffer from several drawbacks. They tend to change their output spectrum with their chip temperature and ageing processes. So you have to supply a proper calibration procedure for your measuring equipment. And you better do the calibration sequence before every measurement.
You then have to design an apparatus which allows the light from your LED fall onto your samples (stones, sediments or so) but prevents other scattered or direct light to enter your sensor. Otherwise all measurements will be crap.
While this is not a direct answer to your question, I think the topic is important enough to write an elaborate pamphlet.
Update
Now some more words more closely related to your problem.
In general loading a huge excel table into your arduino is not necessarily a good idea, even if a big "if"-code array was possible. Storage is scarce on this platform.
If you combine a lookup table with interpolation, you can save much space. You would have to omit 90% of all datapoints and estimate all in between when measuring. Still the table will be rather big, because you have three degrees of freedom.
Another drawback of big tables and LUT with interpolation is, that it makes calibration difficult. Normally, when you calibrate your sensor, you have to adjust the parameters along the calculation. If you rely on a table, you have to exchange the whole table, regardless if it is something like that excel thingy or a condensed lookup table.
If you go for an analytical solution, as suggested in one comment, the number of parameters you have to update after calibration reduces drastically. Effectively you have to adjust some factors and offsets in the equations for this problem. Of course you will have to learn the ropes of the photometric equations, but you will  have to do that anyway, I think.
Some more words on the design of your appartus. Your idea of a cylinder in front of your probe is good. I recommend to fit it with a rim of black foam rubber, so you can seal light coming from outside. And you have to paint the inside of your cylinder as black as you can. See the interiour of a camera objective for reference.
If it is white you will have multiple reflections and multiple filtering which deteriorates your measurement results vastly.

Thank you for your help, I am fortunate that the sensor that I am using comes with its own light source :). So I think the design I am working up in my head is a tube around where the sensor will be placed, I am hoping that  I could then cover the sample/rock leaving only the LED light falling onto the sample. The sensor has a built in IR filter as well as the ability to detect the temperature of the ambient light reflecting off the sample.

I agree that it is a difficult science which I why I am hoping to find help on this forum. I am glad that there are people kind enough to offer opinions/comments on how to achieve this goal I have. I am looking at developing more tools for archaeologists to use in the field that are both cost-effective and simple to operate while providing accurate data. In archaeology I find that the methods we apply to answer particular questions could use improvement. Once, again thank you for your suggestions hopefully I can keep everyone updated on my progress.

I spent some more thoughts on your problem, let's see if we can get that going. Some of the problems perhaps might fit better into another SE community

I have been working on a python code that takes a user input defined input and converts it into munsell using a if/elsif print statement. It is a bit impractical, doing it this way but it works. I know that there is a python library that can work with excel files, and I am currently looking at using that as an alternative to printing 1000+ esif statements :p. I am thinking that the arduino may not be the best device to use for this project. I don't think it would have enough memory to run the program and run an small lcd. I am currently in the process of looking at drivers for the Rpi

The Arduino is able to do that task. You would need only roughly 6 (!) if statements an a while-loop to find corresponding munsell values for a given RGB from this table. Your only task was, to transform the table to something usable written in C and write a code to find the values in the table. I take bets it is possible with less than 50 lines of code. Moreover I strongly recommend to solve this problem analytically otherwise you will get into trouble if you want to calibrate your system.

Right so after a little looking around the net, I came across the colormine library. It is written in C# and the code can already convert the RGB color space into xyY mathematically. This is good because I don't have to re-invent the wheel.  Now I have to import the library into the code and use the serial data of the sensor into the formula. It's progressing at least :)


text:
Arduino uno and ttl laser
I am using my uno with gshield for my cnc. I would like to put laser on it. Laser have 3 wires. Red wire to power supply +, Black wire to power supply -, White wire to Arduino digital pin. I need to Connect the Arduino board ground to power supply -, but don't know how... Simple diagram (like child is using painter) would be great.
Thanks for help,
Urban

The Arduino board's ground connection is labelled.  Where the ground on the rest of your equipment is, and if it is safe to connect exposed low voltage circuitry such as an Arduino to (particularly if it is safely close to the earth potential or the ground of the AC mains) is a serious question, but one which this site is not the appropriate place to ask.

You take a wire, connect one end to the ground on the Arduino board and the other end to the ground on your power supply. Don't forget to strip the insulation. It doesn't get simpler than that.


text:
Draw polygon on LCD from GPS latitude and longitude
I'm working on a personal project  (a usefully tool based on ublox GPS and Arduino Mega that can measure distance between 2 points, compute area, speed, save data on SD card)
Now I want to add new feature and when I show the area(in m^2) on LCD, I want to show the polygon built by more coordinates.
I tried all I know, I searched for solutions but without success.
How can I "scale down" coordinates to make them fit in a x,y system with max size (320*480, LCD size) ?

It's called "division"...? Surely you did it at school?

@majenko : I did the dividion at school. But there is a problem, eg:
Lat1 = 44.456798, Lng1 = 25.563478
Lat2 = 44.672323, Lng2 = 25.894578
Let say with this 2 points I want to draw a line on the LCD, I can draw it but on the display will be almost a single pixel, and If i want to scale it up, I will obtain every time a small one ...  because there are changed only decimals ...

@ChrisStratton i did the math myself. The map function is amazing and I think I will convert actual code to on that use map function. Thanks for suggestion!

Over a small area lat and long are just simple Y and X coordinates respectively.
Dynamic scaling of the points is a very simple matter.  All you need to do is work out the range of each dimension - so subtract the lowest latitude from the highest, and the lowest longitude from the highest.
That gives the full X and Y dimension of your area. Then just divide those by the dimensions of your screen.  That gives you a scaling factor for each direction.
For each point, subtract the lowest longitude and latitude, and divide by the scaling factor for each direction.
If you want to be more fancy and retain the aspect ratio then you just need to work out which of the two scaling factors will allow all the polygon to remain on the screen - that is, divide and offset all your points by one factor, then by the other, and pick the smallest factor where all the points are within the area of your screen.

I'm trying now to do your method, I think is what I want ...

I did the code for Arduino and it works really nice. I added an dynamic X offset to center it on the screen.
// lat = coordinatesForArea[i][0]
// lng = coordinatesForArea[i][1]
// cntr is the count of points

float newPoints[100][2];
float maxLat = 0;
float maxLng = 0;
float minLat = 180;
float minLng = 180;

for (int i = 0; i < cntr; i++) {
  maxLat = max(maxLat, coordinatesForArea[i][0]);
  maxLng = max(maxLng, coordinatesForArea[i][1]);
  minLat = min(minLat, coordinatesForArea[i][0]);
  minLng = min(minLng, coordinatesForArea[i][1]);
}

float ySize = maxLat - minLat;
float xSize = maxLng - minLng;

float scaleFactor = ySize / 300;

float maxY = 0;
float maxX = 0;

for (int i = 0; i < cntr; i++) {
  newPoints[i][1] = (coordinatesForArea[i][1] - minLng) / scaleFactor;
  newPoints[i][0] = (coordinatesForArea[i][0] - minLat) / scaleFactor;
  maxX = max(maxX, newPoints[i][0]);
  maxY = max(maxY, newPoints[i][1]);
}

float newScaleFactor = maxY > maxX ? maxY / 300 : maxX / 300;

float newMaxX = 0;

for (int i = 0; i < cntr; i++) {
  newPoints[i][1] = newPoints[i][1] / newScaleFactor;
  newPoints[i][0] = newPoints[i][0] / newScaleFactor;

  newMaxX = max(newMaxX, newPoints[i][0]);
}

float newOffsetX = (320 - newMaxX) / 2;
float newOffsetY = 100;

for (int i = 0; i < cntr; i++) {
  newPoints[i][1] = newPoints[i][1] + newOffsetY;
  newPoints[i][0] = newPoints[i][0] + newOffsetX;
}

for (int i = 0; i < cntr-1; i++) {
  myGLCD.drawLine(newPoints[i][0], newPoints[i][1], newPoints[i+1][0], newPoints[i+1][1]);
}

myGLCD.drawLine(newPoints[0][0], newPoints[0][1], newPoints[cntr-1][0], newPoints[cntr-1][1]);

Thank you Majenko


text:
ESP8266 blink not building to esp-01
I am trying the esp8266 esp-01, and did all it asked on the arduino IDE side, but i am having problems compiling and building the blink example into the board
Using: FT232RL usb-ttl in the 3.3v configuration, two 1.6v (new) batteries to power the esp, and all the conections as indicated here (not using the led though).
when I hit (go) it compiles, but as it transfers both boards blink sincronously and I recive the following errors:
O sketch usa 219.479 bytes (50%) de espaço de armazenamento para programas. O máximo são 434.160 bytes. Variáveis globais usam 31.172 bytes (38%) de memória dinâmica, deixando 50.748 bytes para variáveis locais. O máximo são 81.920 bytes.
error: failed reading byte warning: espcomm_send_command: cant receive slip payload data error: failed reading byte warning: espcomm_send_command: cant receive slip payload data error: failed reading byte warning: espcomm_send_command: cant receive slip payload data error: failed reading byte warning: espcomm_send_command: cant receive slip payload data error: failed reading byte warning: espcomm_send_command: cant receive slip payload data error: failed reading byte warning: espcomm_send_command: cant receive slip payload data error: failed reading byte warning: espcomm_send_command: cant receive slip payload data error: failed reading byte warning: espcomm_send_command: cant receive slip payload data error: failed reading byte warning: espcomm_send_command: cant receive slip payload data warning: espcomm_sync failed error: espcomm_open failed error: espcomm_upload_mem failed
I looks to me as a newbie that its trying to establish a link and failing... what could it be?
the configurations are default, programmer is "AVRISP MKII"

You did not put ESP8266 into programing mode.
the easiest way to do so is to make your own programing board, something like shown here. Go down to middle of the document to title "Writing a program to the ESP8266" where you will see a schematic of simple programing board. You will need two switches and a 10k resistor.
The voltage regulator can be omitted if you are powering it by 3.3v power. Also its a good idea to put a small capacitor (100uf) between vcc and ground to stabilize any drops in voltage which is primary cause of esp8266 rebooting it self.


text:
How to import data from SDcard on Arduino to the computer using Arduino serial/COM port?
I have Arduino UNO with Adaruit wifi shield. I store some data on the sd card successfully and now I need to import that data on to the computer.
I am sending some token, say "1", to the UART port of Arduino (COM port), there is a code written on the Arduino which responds to that token and sends data (byte by byte) in the bulk amount on the serial of the Arduino. I have to accept bytes and store in a file on the local machine (computer) and upload to the server ultimately at the same time.
(It will be good if the process has the browser support i.e I will send request from web browser to API and that API will connect to serial port/ COMP port of my Computer and somehow the file will be created on the local machine and the data from the Arduino will be saved in that file; the file created will be uploaded to the server ultimately.)
What is the proper way to this, is there any API or software for it?
Please help me out.
Thanks in advance!

There is an example for the ESP8266 (using the Arduino IDE) called SDWebServer which might give you some ideas, I would suggest you try it but I doubt the libraries would work on an Arduino.
If you are going to support a web API, I would suggest you implement a REST API on the Arduino, that is a commonly used API for these type of things.

The client (PC) sends a HTTP GET request to the server (Arduino) with the token you want.
The server responds with the data the token corresponds to.

You are using standard HTTP (you can do it through a browser), so it should go through firewalls without a problem.  Its a very common format, there are plenty of tools to debug it and tutorials for all sorts of platforms that you should be able learn from.
The problem is REST API isn't the best solution for Serial comms, I'm not saying its impossible you could send the network messages via serial, but it wouldn't be pretty.  I think you would be better keeping your custom interface for the serial and moving as much of the code into common functions so you can share it between the two interfaces.
Hope that helps


text:
How to connect an LED to Arduino LilyPad Mp3
can anyone help me with connecting LED to Arduino LilyPad Mp3  in a way, that each switch (1 of 5) light up a different LED?
I tried connecting an LED between the switch and the board, then the LED light up, but the speaker does not play the audio file.
I also tried connecting an LED directly to the speaker, then LED lights up and the speaker plays the sound file, but the problem is that all of the LED´s light up at the same time....

What kind of switches? How are they wired?

You might try connecting the anode side of your LEDs through a current limiting resistor to the positive side of the supply.  Then connecting the cathode side of the LED to the switched pin on the Arduino LilyPad Mp3.  So, in this diagram:

...that would be the pads where the switches are connected.
The current limiting resistor depends on the specifications of the LED.  Check the voltage and current required to light the LED.  Subtract the voltage needed from your supply voltage.  Then use the V=IR equation and solve for R.  That is, V = the voltage difference between your supply and what is needed by the LED and I is the current (probably in milliamps, so watch your math!) that the LED needs to light up properly.  You will probably need small current limiting resistors somewhere around between 100 and 800 ohms.
Added later...
Thanks to @Gerben we have a diagram of what I was describing:

In Gerben's diagram he has used the regulated 3 volt output of the Arduino LilyPad Mp3.  We can double check all the pin labels using a diagram from Sparkfun:

You should be able to repeat this circuit for each switch.  Sparkfun has an LED tutorial here.  But I'm not very happy with their guess approach when picking out a current limiting resistor.  Ah, this tutorial is much more to the point.
So, if we assume the LEDs you are using need 3mA @ 3V (remember to use values for YOUR LEDs!) and use this equation (Vs = supply voltage and Vf = LED voltage):

...then we set it up like (3 - 3) / (0.03) which is zero.  That's because I was using LEDs that work at 3 volts.  But if I used LEDs that worked at 3mA at 1.8V then I need... (3 - 1.8) / (0.03) = 40 ohm resistors.  Or there about. As most resistor values are on a log scale I suspect there should be a 47 ohm available.

You mean like this, right?


text:
Best Actuator to Behavioural Positive/Negative Feedback on Cat
Rhetorical, yet silly question: Given an Arduino to manage, what would be the easiest way, in terms of available actuators (price/availability counts) to:
a) Apply a positive feedback to a cat, in exchange for a good action?
b) Apply a NEGATIVE feedback to a cat, like trying to reach forbidden places?

Err, don't we have an actuators tag?

This constitutes animal abuse. You should not have a cat if this is how you are thinking of treating him.

To anyone downvoting: Next time you laugh at Blender Defender, please remind of your hypocrisy. I'm not aiming at torture, just negative feedback.

That's what the CIA said; it wasn't torture, it was advanced interrogation techniques. I don't know what blender defender is. If what you are doing induces discomfort in the cat, it's animal abuse. You should also try to improve your English.

For the negative feedback, you could use a loud, screetching noise. I would suspect, however, that the cat would eventually get used to it and ignore it.
Depending on your cat's tastes, you could use the same hardware for positive feedback - playing, for example, a Mozart tune if that's what your cat is into.
I know, a silly answer, but what can you do with a silly question? ;-)


text:
Led blinking in the loop in condition
so I will explain what I want to get.
I am reading temperature from DS18B20 and showing it on the LCD.
I have one LED o pin 3 which is blinking when there is a temp reading and screen update. I have another LED on pin 4 which should lit when temp is more than 25 and less than 30, and I want it to blink when temp is more than 30. What I am getting is a blinking but not like one blink every 10ms but it waits for whole loop to start again to blink.
Can I do it separately that this LED will blink indepentantly when condition is true? With set interval for example 10ms which wont be waiting for whole loop.
here is my example code:
    #include <OneWire.h>

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

//LiquidCrystal_I2C lcd(0x27, POSITIVE);  // Set the LCD I2C address
OneWire  ds(2);

unsigned long previousMillis = 0;
const long interval = 1000;
int ledState = LOW;
void setup()
{
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);

  lcd.begin(16,2);               // initialize the lcd

}

void loop()

{
  unsigned long currentMillis = millis();

  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius;

  if ( !ds.search(addr)) {
    ds.reset_search();
    delay(250);
    return;
  }

  Serial.println();

  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
      Serial.println("  Chip = DS18S20");  // or old DS1820
      type_s = 1;
      break;
    case 0x28:
      Serial.println("  Chip = DS18B20");
      type_s = 0;
      break;
    case 0x22:
      Serial.println("  Chip = DS1822");
      type_s = 0;
      break;
    default:
      Serial.println("Device is not a DS18x20 family device.");
      return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end

  delay(850);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.

  present = ds.reset();
  ds.select(addr);
  ds.write(0xBE);         // Read Scratchpad

  Serial.print("  Data = ");
  Serial.print(present, HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print(OneWire::crc8(data, 8), HEX);
  Serial.println();

  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;

  digitalWrite(3, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(10);              // wait for a second
  digitalWrite(3, LOW);    // turn the LED off by making the voltage LOW

   lcd.home ();
   lcd.print("Reading 1");
   lcd.setCursor( 0, 1);
   lcd.print("temp:");
   lcd.print(celsius);
   lcd.print("*C");

   if (celsius >= 25 && celsius < 30) {
    digitalWrite(4,HIGH);
   } else if (celsius >= 30) {
blink1();
   } else {
    digitalWrite(4,LOW);
   }

}

void blink1() {
digitalWrite(4,HIGH);
delay(50);
digitalWrite(4,LOW);
}

Here try this:
#include <OneWire.h>

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

//LiquidCrystal_I2C lcd(0x27, POSITIVE);  // Set the LCD I2C address
OneWire  ds(2);

const long interval = 1000; //İnterval at which to blink(milliseconds)
unsigned long previousMillis = 0;
int ledState = LOW;
void setup()
{
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);

  lcd.begin(16,2);               // initialize the lcd

}

void loop()
{

  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius;

  if ( !ds.search(addr)) {
    ds.reset_search();
    delay(250);
    return;
  }

  Serial.println();

  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
      Serial.println("  Chip = DS18S20");  // or old DS1820
      type_s = 1;
      break;
    case 0x28:
      Serial.println("  Chip = DS18B20");
      type_s = 0;
      break;
    case 0x22:
      Serial.println("  Chip = DS1822");
      type_s = 0;
      break;
    default:
      Serial.println("Device is not a DS18x20 family device.");
      return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end

  delay(850);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.

  present = ds.reset();
  ds.select(addr);
  ds.write(0xBE);         // Read Scratchpad

  Serial.print("  Data = ");
  Serial.print(present, HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print(OneWire::crc8(data, 8), HEX);
  Serial.println();

  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;

   lcd.home ();
   lcd.print("Reading 1");
   lcd.setCursor( 0, 1);
   lcd.print("temp:");
   lcd.print(celsius);
   lcd.print("*C");

   if (celsius >= 25 && celsius < 30) {
    digitalWrite(4,HIGH);
   } else if (celsius >= 30) {
blink1();
   } else {
    digitalWrite(4,LOW);
   }

   unsigned long currentMillis = millis();

   if (currentMillis - previousMillis >= interval) {

     previousMillis = currentMillis;

     if (ledState == LOW) {
       ledState = HIGH;
     } else {
       ledState = LOW;
     }

     digitalWrite(3, ledState);
   }
}

void blink1() {
digitalWrite(4,HIGH);
delay(50);
digitalWrite(4,LOW);
}

and also note that i choosed 1000 milliseconds for interval (equal to 1 second) so if you want 10ms as in your first post then change const long interval to 10


text:
Arduino Nano clone doesn't fit into breadboard. How can I work around this?
I have bought an arduino nano clone (called funduino) and upon trying to place it into my breadboard to work with it I realised that the pins do not line up with the holes on the breadboard so I simply can't use the funduino...

Does anyone have any recommendations on how I can get around this?

Is it your breadboard or the funduino that doesn't have the 0.1inch pitch ;)
I see that the last pin (VIN?) is a little bent, you might check if any of the pins is a little of and bend it back in line. Then it should work, given they're both 0.1inch pitch (but I don't see why not).

What is a 0.1inch pitch?

0.254 centimeters pin spacing. The space between two pins.

Have you tried just patience and persistence?  Some of mine feel tight but in the end they go in.  (Bent pins can be unsoldered and new pins can be put in, if you need to do so, but it is best not to push too hard until you are convinced it can be made to work)

bruh I've forgot how to even use my arduino I've not touched it in that long, thanks for the reply though lol

Because of the same issue, I use mine with a miniature breadboard:

Is there a link to that breadboard type? I have found one on bitsbox that looks similar but I'm not sure if it will fit

Image

How is that a help?  These have exactly the same pin spacing as larger breadboards.

Here is a link to the above breadboard. And the spacing is different, at least when I compare it to my standard size breadboard.

I use these, and they work well.  They are available from the usual sources, and with US suppliers can be on your workbench in 3-4 days.

You might be able to use these female to female jumper wires and these headers and hook up the board and breadboard like this:

Note, the square female cable ends may not fit closer than 0.1 inches on center.
A more compact and (possibly) mechanically difficult solution may be implemented using wire-wrap sockets.  You may be able to leave the sockets intact and deform the pins to match the breadboard.  Or you may need to remove the pins from the plastic in order to accommodate your (different) Nano:

I was thinking about that initially, I just didn't want to spend anymore money/ wait for them to arrive haha, would you recommend me attempting to disfigure the device at all?

I thought the Nano's pins were already 0.1 inch on center.  So a picture of why this board doesn't fit into your breadboard would be helpful.  W/o that, I can only guess.  But guessing, what I would do is not disfigure the Nano's pins but to plug it into a "hacked" wire wrap socket(s) (long stiff pins) and disfigure the socket such that it can plug into the breadboard.

These seems much simpler than your current answer. Update it and I'll accept it :)

Found a good wirewrap pin picture. I'll update answer.