text:
My Arduino code will not compile, when I can't see anything wrong with it
It keeps on giving me the error:
Error compiling for board Arduino/Genuino Mega or Mega 2560.

Other sketches work fine, but this one will not compile, even though I have all the libraries.
Here is the link for the code:
https://drive.google.com/open?id=0B3R5NMiGZ3RPSk9WS0Y1amtEYms
The full error:
Arduino: 1.8.3 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':

(.text+0x0): multiple definition of `__vector_13'

libraries\IRLibRecv\IRLibRecv.cpp.o (symbol from plugin):(.text+0x0): first defined here

d:/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.9.2/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions

collect2.exe: error: ld returned 1 exit status

exit status 1 Error compiling for board Arduino/Genuino Mega or Mega
2560.

This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

Thank you everyone. all i had to do was get rid of the tone() function.

ps. is there a way i could still use it?

Link is now dead, so your question is not of much use to others. This is why it is always best to include the code in the question and not a link. If the solution was to remove the tone() function, why don't you post that as an answer, explaining why that helped fix your code?

@Greenonline This thread is almost 2 years old...

There are questions on Electrical Engineering that are 10 years old which are still useful ... I came across your question whilst looking for a solution to an issue that I'm having, but it wasn't as useful as it might have been. That's all I'm saying... :-)

What do you need help with? I haven't used arduino for a while, but I might still be some help

It was a simple compile error, I have fixed it now, thanks :-)

There are a number of issues with your code besides the actual error:

You are dividing an unsigned long by an integer which results in an unsigned long, then rounding it. Makes no sense.
You are assigning (I assume - without seeing your code I can't be sure) long constants (eg 0xFFE01F) to an integer - which overflows and whinges.

However your main problem is that you have two interrupt service routines (ISRs) for the same interrupt (vector 7). What that interrupt is I can't say, since it is different on different chips, and you don't seem able to make your mind up if you're using an Uno or a Mega (you tagged your question both for some reason). So you will have to change code and/or libraries to use different interrupts or combine the two together to use just one ISR.

should i change the int 'heldDown' to a long?

Yes. Better still, uint32_t.

what is uint32_t. ?

and how should i fix the vector errors?

I can't see you code, but my guess is that you are passing an unsigned value into round().
millis() returns an unsigned long, this means it can never be negative, so if you test millis() >= 0 it will always be true.  That is your issue.
Write you own round function that doesn't check its greater than 0.

I don't think that's the error, it's just a warning. The real problem is in: (.text+0x0): multiple definition of `__vector_7' (link error)

just some warnings about generally unsafe/unsound code pieces.
the major issue (potentially unresolvable) is the vector-7 error. you should look into the datasheet to see what interrupt vector it is referring to first. There are more than one of such ISRs declared in your code.

how should i fix that

I searched but couldn't find an answer, then I suddenly released my Arduino external power caused this problem. When I shut down the external power I could install it in my device. I hope it works for your problem.


text:
How to control Arduino using mBlock and Bluetooth?
Is it possible to control an Arduino using mBlock and Bluetooth?
Assuming yes, I tried various things, but was not able to come to a conclusion.
I am trying to get this combination working using a HC-05 Bluetooth module. I am not sure if my Bluetooh setup is the problem or is mBlock is not able to recognize the COM port provided by Bluetooth.
I can see the COM device (in fact two?) when I pair HC-05 with PC. I have the following questions based on whatever I have tried so far:

When I connect HC-05, should I connect TX to TX OR reverse them?
There are varying articles describing both ways of connection.
How much baud rate do I need to set on the Bluetooth device?
Do I need to use the voltage divider for RX? Again there are varying tutorials.
Is mBlock default Arduino firmware sufficient for such setup?

I got it working. Following are steps.

Set the Bluetooth baud rate to 115200. The mBlock firmware uses
this baud rate for serial communication.
Connect Bluetooth to Rx and Tx of Arduino.
Upload default Arduino firmware (orion firmware) to
Arduino using mBlock.
Use mBlock to interact with Arduino using Bluetooth.

Please note that Bluetooth cannot be used to upload
the sketches to Arduino for offline mode.

Connecting Bluetooth COM device to PC in AT mode to set baud rate.

Upload empty (default) sketch to Arduino using USB cable.
Connect 5V of BT shield to 3.3V of Arduino.
Connect EN or BT to 5V.
Connect Tx to Tx and Rx to Rx.
Use USB cable to power on Arduino.
Before turning the power ON, keep pressing the EN
button on BT shield. The LED should blink with almost
a second delay. That is the indication that it is AT mode.
Start Arduino IDE, and connect to the COM port of Arduino
and NOT that of the BT.
Start serial monitor.
Set the baud to 38400 and terminate character settings to
"Both NL $ CR".
In the command input field of Serial Monitor type at twice. First time response will be error, second time it should be ok.
Now use the at commands to set baud rate using "at +uart=115200,0,0" e.g.
Use "at +uart?" to see what is the baud rate set on the device.

Connect Bluetooth device to Rx and Tx of Arduino.
Arduino  <-> HC-05
   =======      =======
   5V            Vcc
   GND           GND
   Rx            Tx
   Tx            Rx (Via Voltage divider)
Some of the articles talk about connecting 3.3V of Arduino to the
Vcc of HC-05 and not using the voltage divider at all. However this
combination fails as once increases the baud rate.
Check out more details about voltage divider here. https://electronics.stackexchange.com/questions/280500/why-do-you-have-to-use-a-voltage-divider-with-hc-05-bluetooth-module-arduino
What is the story of two COM devices for Bluetooth?

https://electronics.stackexchange.com/questions/13741/bluetooth-module

When I connect HC-05, should I connect Tx to Tx OR reverse them?

There are varying articles describing both ways of connection.

Yes, swap them. TX on the HC-05 to RX on the Arduino. However you could struggle to use pins 0/1 since they are the USB connection. SoftwareSerial (which is nasty) is what most people use instead.

How much baud rate do I need to set on the bluetooth device?

Whatever rate you want to communicate at. It's up to you. However all baud rates must match throughout the system - the baud rate on the Arduino, the baud rate of the HC-05, the baud rate of the SPP port on your PC, etc.

Do I need to use the voltage divider for Rx? Again there are varying tutorials.

Which RX? Arduino TX to HC-05 RX yes. HX-05 TX to Arduino RX no.

Is mblock default arduino firmware sufficient for such a setup?

What is mblock?

thanks for the comments. mblock is the visual programmer tool which has arduino eco system integrated. http://www.mblock.cc.

Majenko Could you please explain why using 0/1 is not good idea? I think the default firmware that I use for mblock may be expecting the serial communication to happen over 0/1 pin of arduino.

0/1 is used for communication with the PC and uploading new sketches. You can't do that whilst at the same time communicate with an external module such as bluetooth.

source: Stack Exchange

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

sort: votes


text:
Arduino USB and 9V
I'm working on a project for interfacing the Arduino with the Raspberry Pi. I need to be able to exchange serial data between the two using the USB port.
My question is, can I do that while having the Arduino powered, by using a 9 V battery connected to the DC pin and at the same time have serial data connection using the USB port?

Why bother? If you are going to use the USB why not just run the Arduino from the Pi power?

@Milliways I'm using the arduino to power many sensors and relays and don't want to damage the pi.

Then you shouldn't use an everyday 9v battery either, as they are not intended for high currents and will quickly die when used in that way.  When the battery dies, you'll be drawing power from the pi.  Likely what you should do is run the Arduino from the pi, but give your sensors and relays their own suitable power supply with common ground to the Arduino/Pi.

@ChrisStratton you are right because when it drops below 6.6v the arduino will use the usb connection for power and ar high currents that might damage the pi.

@ChrisStratton i think im going to use a 12v source to power the arduino not a 9v battery. Thank you

A 12v source is a bad idea and will cause excessive heating at high currents.  Don't power your loads from the Arduino, power them directly.

Yes, you can. Arduino can be connected to multiple power sources at the same time.
From this excelent page about Arduino power, I cite:

Arduino is provided with a comparison circuit that controls a type P MOSFET; if a tension is found on Vin (powering from the JACK or from the Vin socket), the MOSFET is interdicted and the possible presence of voltage coming from the USB port is ignored; in the opposite case, the MOSFET will connect the USB port’s 5 V to the 5 V socket, hence below the regulator, thus powering Arduino.
Therefore it is clear that if you apply the voltage to the USB port and an external source to the JACK socket at the same time, it will be this last one to power the circuit, while the USB connection will keep working for the data exchange with the computer and no longer as a power source. We remind that in both cases the 5 V socket cannot be used as input, but only as output.

Thank you very much, i tested it on a 12V source and it worked perfectly and i got serial data working as well.

A 12v source will cause heating of the Arduino's regulator if you start drawing lots of current.  You really should not run relays, for example, from the Arduino's supply, but rather give all of these off-board loads their own appropriate supply with only a common ground to the Arduino.

While this truthfully answers the question first asked, the reality is that the question has become an X-Y problem - the question asked isn't the one the poster, or likely future readers, actually need answered, and the lack of appropriate cautions in this is disappointing.

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


text:
Feasibility of project with 50 leds working independently
I don't have much knowledge in Arduino and I'm about to start a new project which I believe can be done with it.
There will be 50 boxes with a led in top of each one. The user will type a number in a keyboard (1 to 5 for example), and then based on a table, the leds according to that number should light up.
It will have some overlaps, for example, Number 1 would light led 1, 2 and 3, while Number 2 would light leds 1, 2, 3 and 4.
Could I build such a project with arduino? Or are there too many inputs/outputs (keyboard, 50 leds)? I was thinking to buy an Arduino Uno to start learning, but first I'd like to know if it's feasible.
Thanks already

Look up "Charlieplexing" as used in the "LOL shield" - it isn't without tradeoffs, but an ordinary Arduino can drive at least 64 LEDs this way.

depending on how you want to control your LED's there are several options.
firstly to be clear you could not feasibly connect that many LEDs to an arduino that could all be turned on at once (if that was needed) without damaging the arduino.
if all you need is on/off level of control then you could look at shift registers or if you have pre built arrays of LEDS in a grid type layout you could look at the MAX7219/MAX7221
if you also wanted to be able to control the brightness individually then you could look at the TLC5940
if we look at the pros and cons of each approach:
74HC595
pros:

cheap to buy
simple to use

cons:

each LED needs its own resistor
cannot vary brightness
if not using the hardware SPI pins can be slow for large numbers of outputs

MAX7219/MAX7221
pros:

lower current draw than 74HC595
only needs one resistor per IC which can drive 64 LEDs

cons:

actually flashes LED's really fast to look like they are always on
costs more than 74HC595

TLC5940
pros:

can vary brightness with a high number of steps (4096 steps from fully off to fully on)

cons:

uses more output pins than either of the above methods
requires resistor per LED
costs more for the IC than 74HC595

so to sum up, each method has its merits. if you are driving individual LEDs the the 74HC595 is probably the best/simplest route, if you are driving an array then the MAX7219/MAX7221 is best, and if you need variable brightness then the TLC5940 is probably best.

just as a side note, i currently have a project that controls some RGB LED strips that each consist of 3 RGB LEDs per strip (red, green and blue LEDs in a single housing) and a total of 16 strips individually controlled for a total of 48 individually controled outputs with PWM brightness control using three of the TLC5940 ICs. so what you are asking for can definately be done, although my project may be more complicated than you are after.

If you need many resistors, you also can use resistor arrays.

@MichelKeijzers true, just depends on how the circuit is being made/wired up.

Thanks for your answer @JamesKent I have a pre-built array of leds for each number, it can change with time though. I should be able to change the leds that will light up just by changing my code. Is it possible with 74HC595 or MAX7219/7221? Or would I need to set up all my wires again when I want to change the leds that will light up?

chances are if you have a pre made array they it will be wired in a grid pattern rather than giving an individual pin for each LED plus a power pin, instead they will be arranged in rows of shared positive pins and columns of shared negative pins (or the other way round) in which case the 74HC595 cannot be made to work without a lot of hard work. if your led array is something like this: http://www.circuitstoday.com/wp-content/uploads/2016/04/8X8-Matrix-Pinout.png then use one of the MAX chips. the 7219 is usually cheaper and should do what you need

any of the methods i put in my answer are aimed at letting you control which LEDs are lit up purely in code rather than having to re wire any of your circuit.

Do I need a proto shield or something like that for that project? Is it feasible for longer distances (from the arduino to the leds, I'm talking about a couple meters here)?

as for needing a proto shield, it depends how comfortable you are with soldering. and for the distance that depends on a number of factors, the faster you want to send the data the less distance you can send it. if you are aiming to have all the electronics in one place and run wires to LEDs then thats not a problem. if you wanted to keep the amount of wire to a minimum then you'll want to spread the ICs further apart, at which point you may need to slow the data rate down. i think you should be ok, but it depends how electromagnetically noisy the environment is.


text:
Is it possible to make normal pins act like ground pins?
So what exactly I am trying to do is control a motor and be able to turn it both ways without any extra parts.
So if the hmp was on (the plus pole) and the hmm (the minus pole) acted like ground the motor should start turning right.
But if the hmp acted in this case as ground and the hmm like the plus pole it should start turning the other way.
I know that it's probably not going to work. I'm just experimenting.
int Hmp=12; // the plus pole
int Hmm=11; // the minus pole

while (HR=0 || Sr > Sl+300) {
  pinMode(Hmp, OUTPUT);
  digitalWrite(Hmp, HIGH);
  pinMode(Hmm, INPUT);
}

while (HR=1 || Sl > Sr+300) {
  pinMode(Hmp, INPUT);
  pinMode(Hmm, OUTPUT);
  digitalWrite(Hmm, HIGH);
}

"I know that it's probably not going to work." it will work. it is called low-side switching. most bi-directional motors are in part driven this way for example.

@dannyf - no, it won't work, and the user already stated that it did not work.  This is because while topologically similar to a half-bridge of power FETs, the output drivers on chip aren't up to the task of running a motor.  You've developed a very bad habit of posting throwaway incomplete and as a result at times misleading things like this, though fortunately at least this time you didn't abuse the answer form to do so.

You have to put both pin in OUTPUT mode. You digitalWrite() the "positive" pin HIGH and the "negative" pin LOW.
But, it's not a good idea in this case:

Motor's power requirement exceeds digital output pin current of 40 mA.
Back EMF. Every time you stop the motor, there is a brief current pulse back to your pins. Bad.

The proper ways to control a motor is this:

This will control only one direction. For changing directions, you need a H-Bridge. An H bridge is an electronic circuit that can drive the motor in both directions.

This is also improper - you should not be powering the motor from the Arduino.  Also bipolar transistors as you have drawn do a poor job of motor control compared to modern FET's, and using a 2.2K base resistor will likely limit things further.  When bipolar transistors are used, effectively "dual stage" darlingtons are the norm.

@Chris. You are right. The proper way to do is using an opto-isolator to drive a relay connected to proper power supply. Thank you for your valuable insight.

No, a relay is not a good way to do this either.  As already explained, one should use an FET driver.

@Chris. Waiting your proper answer to this question.

Perhaps next time if you wait before you post you might see one.  I came here from the question review page intending to post an answer, but given all the noise that's been made around the actual topic which had to be dealt with first, the actual question just doesn't feel interesting enough to bother with any more.

No, it's not going to work - even worse, you risk frying your Arduino -, for the following reasons:

The Arduino data pins can't source (neither sink) enough current for that to work.
The inductive kickback of the motor could fry Arduino pins.

The right way to do what you want to do is using an H-bridge controlled by your Arduino data pins. There are lots of Motor Driver PCB modules for Arduino (most of them based on the inefficient L298 driver IC, which you should ignore and look instead on those based on the TB6612FNG driver IC or similar, because it would be a far better solution) that implement this function.

The L298 and L293 are very antiquated high-loss devices best avoided.  Especially in a battery powered application, one cell of the battery pack will go largely to feeding the losses of those driver chips, rather than turning the motor.  These really need to stop being mentioned by default - use an FET solution instead, for example the TB6612FNG replaces the L29x on better motor shields.

Thank you for your comment, @ChrisStratton. I agree with you and I'll update the answer accordingly.

I don't think that's going to work.
You'll be better off using a cheap module like the Pololu Pololu DRV8838 which implements a MOSFET H-bridge.
(Note: I'm not related in any way with Pololu.)

I just tried what you suggest, and it works fine, with only one (big)
caveat: you can only power this way very low power motors. I did this to
drive the linear motor that moves an HDD head assembly. This motor works
perfectly fine with less than 18 mA.
Note that I switch the Arduino pins between the HIGH and LOW states,
not going through INPUT. Setting the pin to INPUT would send the
motor's inductive kickback through the pin's protection diodes. On the
other hand, the inductance of this motor is presumably tiny...
For anything that can draw more than 40 mA, I would use an
H-bridge. For something between 20 and 40 mA, I may take the
risk of driving it directly if it's for an experiment where I am not
too much concerned about the risk of loosing my Arduino.

I just tried what you suggest, and it works fine,... It shouldn't surprise anyone that it worked. Because the structure of a typical GPIO pin is a h bridge or a low side switch. So it has to work. That's just basic electronics.

with only one (big) caveat... And that's no surprise as well. Whenever you drive a load, you have to understand its limitations. And in this case the limitation is severe in terms of drive current and drive voltage.

A big advantage is that those pins generally have clamping diodes. For inductive loads, they act as free wheeling diodes.

is it possible to make normal pins act like ground pins?

the answer is yes: i'm looking right now at a blinking led that straddles between two GPIOs with one of them permanently (via code) grounded so i can blink it via the other GPIO pin.
Obviously the usual limitations that apply to a GPIO pin apply here.

This is bad, bad advice. The LED you're looking at likely draws 30 mA maximum. Even a small DC motor will draw many times that amount, and far more than the GPIO pins can sink.


text:
Arduino PC to RS232 not reading data
I am trying to read data from RS232 Shield with an Arduino Mega.
This is the schematic pin, TX is 3 and RX is 2.
Wiring:
PC > USB-RS232 cable > Arduino RS232 Shield.
Software to send/receive data:
Hercules Setup Utility
From Arduino, I can transmit data to RS232, the TX led blink and I got the value at PC.
From PC, I send the data, the RX led blink but nothing is showed in Arduino Monitor.
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello, world?");
}

void loop() { // run over and over
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}

I also tried to move RX and TX to Pin 15 and 14 but worked as the same as before.

What does the 'RS232 direction pin' do?  If its only working one way then that would be the first place I would look at.  Also do you have you SD Shield plugged in at the same time?

@CodeGorilla Sorry, it was direction to RS485. And no, SD Card.

You're going to need to clarify if you have RS232 as in the title or RS485 as in the code, and you're going to need to show the full system wiring.  When you say PC, do you mean the one connected to the RS232 or RS485 connector, or do you mean the one connected to the Arduino USB port?   On the end which is not the Arduino serial monitor, what are you using to send/receive data?

@ChrisStratton forget RS485, just deleted that code, I wont use RS485 for nothing. I am using Hercules setup utility.

Ok, but the question remains too incomplete to be answerable.

@ChrisStratton What info I should provide?

Everything needed to debug the signal from one end to the other. For example your board seems covered with switches and options.

@ChrisStratton The switches are set to RS232 and SoftSerial, the other options are for RS485.

Found the problem, cant use PIN 2 as RX.

Note: Not all pins on the Mega and Mega 2560 support change
  interrupts, so only the following can be used for RX: 10, 11, 12, 13,
  50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69


text:
Detect where pressure is being applied by using force resistors
I have 3 force resistors in a row, on top of which I have placed a board. I read values from the resistors through analogue ports. My goal is to be able to detect whether someone is pressing on the top, middle, or bottom of the board.
So far I can easily detect the left and right, like this: I first calibrate the 3 sensors for 2 seconds. Then I detect if pressure is applied on any of the calibrated sensors. If yes, I sum for all of them the values that they return on each round of the loop, until force has stopped being applied. I finally compare the 3 values against each other and I find which received higher pressure in total. This works perfectly fine for the left and right. However, when the board is pressed in the middle, pressure is applied on all 3, since the board is flat. Sorting the values does not help, because very often the left and right sensors have recorded a higher value than the middle.
I noticed that when the board is pressed on the left, the right sensor records very few values, and the same for the other way around. So, I get a high success rate in detecting middle presses like this:
int threshold = 80;
if (left_sum > threshold && middle_sum > 80 && right_sum >80)
    return middle_pressed;

However, when someone presses hard enough on the left or right, the if statement is satisfied.
Is there a more accurate way to detect where force is being applied?
(Following is a quick schematic I made - I am not at all an expert so please excuse me for my mistakes, I just hope it illustrates more or less what it is supposed to)

simulate this circuit – Schematic created using CircuitLab
Please ignore the double arrows right on top of the resistors.

Is there something between the board and the FSR ? To spread the pressing force over the FSR ? For example a sheet of 1mm silicone. I don't know a smart mathematical solution, because the board does not bend. A resistive touch screen detects the middle of the force, but the top layer bends. I would use a threshold at the end of a calculation. First I would calculate which one is most likely to be pressed (using all three sensors for each calculation), and after that I would apply a threshold to check if it will be accepted. Do you really need the middle FSR ? It does not give more information.

Thank you for your answer! To clarify, the board on top is too thick to bend, so I cannot do much about it. You are right that the middle one does not do much, so I will consider removing it. Another thought I had is if both left and right detect pressure to return the middle if left/right < threshold. This will probably minimise the risk of getting the middle if you pressing too hard.

Okay, removing the middle FSR is a good idea, it is only confusing. Be sure that the FSR are attached to a flat surface. There must be something (1 mm silicone sheet) between the FSR and the board. This is really important to get consistant values. Now you can do math. Calculate with two sensors where the force is pressed, determine the position and the total force (if possible in Newton). Use the threshold at the end of the calculation when the position and total force is known.  In the code you might need to check two position limits and one threshold limit for each virtual button.

Yes you are right about the silicone, I had already put on the sensors these silicone "legs" that you stick on things that you don't want to slide. Here is my code if anyone is interested. At the moment the results are almost perfect (it fails to detect ~1/20 trials) and I am looking into how I can improve it further https://gist.github.com/jackgu1988/085fb432b1d0005083cbd5570a55d6ab

As I wrote before, I would calculate the position and the total force, and after that decide which virtual button was pressed. You are making decisions before any decision should be made. I'm sorry, but I can't put it into code right now.

Sorry about my ignorance but I come from a different background so I don't know much about this yet. What do you mean "position of the total force"? If you can explain it I can put it into code. Thank you very much!

the position and the total force. I have made a (very long) answer.

Let's assume that you have only two FSR sensors. With those you can make three virtual buttons (above the left sensor, above the right sensor and in the middle).
To measure someone's weight, it is allowed to have a scale under each foot and add both weights. We can use that to calculate the total force pressing to the board, by just adding the two forces.
The FSR sensors have a curve to calculate the force in newtons. It is very inaccurate, but works more or less. That can be added later. For now let's assume that it is linear to the ADC value of the Arduino.
Are the FSR sensors connected to an analog input and GND ? Do you have a resistor between the analog input and 5V ? I assume you do. You need the resistors so that a nice pressing force to the board results somewhere in the middle of the ADC range.
Pseudo code:
setup()

  Measure both ADC values (or a number of values and use the average)
  Store them as offsets in a global variable.

loop()

  Measure both ADC values, substract the offset.

  Translate the ADC values into force.
  The more force the higher the number should get.
  Any range is okay for now.
  They can be translated into Newton later.

  The total force is by adding the two forces.

  The position in percentage is the force of the right sensor
  divided by total force times 100.
  Then the position will be 0 for left sensor, 50 for middle
  and 100 for right sensor.

  If the total force is above threshold, then check the position.

  for example position -50 to 20 for left virtual button.
  for example position 30 to 70 for middle virtual button.
  for example positition 80 to 150 for right virtual button.

You can start by printing the forces to the serial monitor. Press the board and check if the numbers increase when pressing more.
Don't get confused when you print the position. It will be very noisy when no force to the board is applied. It should be valid when the total force is above the threshold.
For the position I allow a large error of 50 percent left of the left sensor and right of the right sensor. It depends on the mechanical construction and the rest of the code if that makes sense.
Print the results to the serial monitor.
If that is working well, then you have to detect a single press.
Let's assume that as soon as the threshold is reached, a press to a virtual button is accepted. Let's not wait until the peak of the force is reached.
The State Change Detection example can be used to create a single event for pressing the virtual button.
Any jitter or noise (for example a single press to the board results into two events for the virtual button) can be solved by averaging or filtering in software. I think that it will be needed.
I'm not sure if all of this is okay. I hope that someone else will look into it as well.

Thank you very much! This makes sense to me and I agree that this is the best way that it should be done. I will both waiting for the peak of the force (and take the decision after state change) and calculating on each round of the loop and see what works faster. I do not mind taking the decision afterwards, as I am more interested in the system being as fast as possible in detecting state changes.

If you make a variable active when a virtual key is pressed (as long as it is being pressed), then that variable is the same as the digitalRead of the State-Change-Detection example. I see no advantage to wait for the peak. The virtual key press is already accepted when it was above the threshold, it does not matter what follows (small peak or big peak). It has to drop below the threshold to be able to accept a new virtual key press. The State-Change-Detection is for one key, you have three virtual buttons and only one button can be pressed at a time, so there is a little difference.

My assumption is that force will only be applied on one spot at a time and then released (no sliding or whatsoever). So, I am treating as a change of state when any of the FSRs is measuring something (above the calibration threshold). By checking on every round if some threshold is exceeded, I have to sum two numbers and then run an if statement. If I check afterwards, I just store two numbers on each loop and afterwards run the if statement once.

I prefer clean programming above getting into troubles. It's no problem to check everything thousands times per second. You might need to slow the sampling down to about 100 times per second with millis. That's just optimizations for later.

I totally agree in general, but in this case I am trying to get accuracy as close to the millisecond as possible, because I also care about exactly for how long a button was pressed. Based on your help (especially from this answer) I have managed to significantly reduce the complexity of the code already.

Is there a more accurate way to detect where force is being applied?

normalize your measurements vs. the static values of those strain gauge readings obtained during calibration.


text:
What is the relationship of an Arduino .ino file to main.cpp?
Is the .ino file an alternative from a main.cpp file?
If yes, then could someone mind explaining the structure of the .ino file in main.cpp and its relationship?

... ... What ... ... ?

No need to put on hold. English is not my native language, and I had no problem with the question.

As well, closure is usually applied for obviously off-topic questions or worse infractions. Why was this closed rather than just held for clarification? Voting to re-open.

@JRobert, the Answer by Jot is good. The Question should be edited.

The Arduino uses the gcc compiler. That compiler wants a normal main function of course. Arduino has put a layer on top of that with setup and loop.
The hidden main function for basic Arduino boards is in main.cpp (click on it to see it).
You see that init is called, and setup and loop and a few other things.
To learn how to use setup and loop, you can try a few examples. They are in the menu of the Arduino IDE and they are also online.
The .ino files are all combined together and presented to the compiler as a single .cpp file to compile. The Arduino libraries are compiled from source as well, and everything is linked into a binary.
When you know how to use setup and loop, try the Blink Without Delay example. It can be used to run different software timers and do all kind of tasks and keep everything running smooth.

It solves my query, thanks for explaining the int main function in main.cpp. Also I would try the blink w/o delay example as you suggested.

The link to main.cpp has moved to a new repository, here is the new location.

@LukeBayes Thanks, I have adjusted the link in my answer. The old standard avr has been moved to "ArduinoCore-avr".

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


text:
Pressure Sensor-MPX10DP with amplifier and Arduino UNO - output to kPa
I'm working with an Arduino UNO. I'm trying to use this Sensor to obtain the pressure in kPa. I'm using a tl084cn to amplifier the signal. But I don't know what values I'm getting and what to do with them.
Not applying  pressure prints 0, if I apply air pressure it's goes up to 800-900 as max. What mean this values?
What is the maximum pressure that I should get? 10 kPa? I don't understand that very well. Because the data sheet says:

Maximum Pressure (P1 > P2) PMAX 75 kPa

I can understand what is the differences between Max. Pressure and Max. Differential Pressure.

Your previous question: https://arduino.stackexchange.com/questions/40234/how-to-connect-a-pressure-sensor-mpx10dp-to-an-arduino The TL084 is not an instrumentation amplifier. The MPX10DP can measure from 0 to 10 kPa differential pressure and it breaks at 75 kPa differential pressure. The sensor output has a offset of 20mV and a range of 35mV. When no pressure is applied, you measure the offset.

@Jot So, I can't use the TL084 to amplify the output?

You can amplify the signal with a TL084, but depending on the circuit the impedance of the circuit could influence the bridge output of the sensor. Measuring the exact pressure would be disturbed. The output impedance of the sensor is about 1 kΩ. Are you really determined to get into more and more trouble instead of buying a MPX5010 ? With a MPX5010 all your troubles are gone at once.

@Jot, the problem is that in my country there is no place to buy a MPX5010, that's why I was trying to accomplish it with this sensor from my college laboratory.

And what about a INA125 or similar instrumentation amplifier ? Those are made for wheatstone sensors. Or what about an Arduino Leonardo or Arduino Mega 2560 ? Those have internal differential mode with a gain, that is somewhat similar to a instrumentation amplifier.


text:
Communicate between NodeMCU ESP8266 gateway and multiple sensor nodes
What is the best wired way to communicate between multiple NodeMCU ESP8266 boards for home automation.
Every room should get at least a light, temp, PIR and xx relay modules to switch things on and off.
To connect all these sensors the GPIOs from one NodeMCU are sometimes not enough.
To reach this goal I planned to install in every room one NodeMCU as gateway and multiple NodeMCU as nodes for my sensors. The gateway will receive and forward information from/to my openHAB center via MQTT messaging.
I thought to use an RS-485 2-Wire connection between my sensor nodes and the room gateway. The gateway from my room will be connected via wifi or wired cable to my network.
I2C seems more to be for communication directly on PCBs or only short wiring.
Do you have any suggestions for me, is my plan possible? Any better ideas?

I2C max distance depends on the load of the bus and the speed you run at. In typical applications, the length is a few meters (9-12ft). The length can be increased significantly by running at a lower clock frequency. One particular application - clocked at about 500Hz - had a bus length of about 100m (300ft). If you are careful in routing your PCB's and use proper cabling (twisted pair and/or shielded cable), you can also gain some length.

If you really wanted wired communication then yes, RS-485 is the way to go.
In any installation where you will be running cables in the vicinity of mains wiring you will have noise. I2C is very bad with noise and not a good choice for any off-board wiring. RS-485, however, owing to the balanced line nature of the signalling, is designed to reject common mode noise such as is induced by mains wiring.
I would ask, though, why use ESP8266 as remote wired nodes? It seems a real waste to use a WiFi module for wired communication - a smaller, simpler, lower powered board (Arduino Micro / Mini maybe [3.3V, 8MHz version for simplicity of interfacing]) would be far more suitable for such a role.

Many thx for reply. What is about the speed from RS-485, is it faster or slower than I2C and could I ran into problems if multiple nodes try to submit their values at the same time to the gateway? I'd like to use the ESP8266 because of the more memory and faster cpu. Or do you know similar device without wifi module? During my research the ESP was the fastest and cheapest one...?

You shouldn't need much power and memory for simple sensor data acquisition and transfer. To prevent collisions have the ESP8266 request data from the remote nodes rather than have them send blindly. RS-485 can be as fast as your UART will go. 1 Mbps is certainly possible, though as with all comms, the higher your baud rate the shorter your maximum distance.


text:
Stepper motor not working in Arduino 101
I am trying to connect a stepper motor ( this model exactly https://create.arduino.cc/projecthub/trduunze/grove-starter-kit-for-arduino-stepper-motor-driver-66471d ) in an arduino 101 but it does not work for some reason. I have tried connecting everything ast they tell in the website with no results:

And then I tried connecting directly to the board without using the shield, and still getting nothing.
The code I am using is this :
#include <Stepper.h>
int t =0;
const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

int stepCount = 0;  // number of steps the motor has taken

void setup() {
   Serial.begin(9600);
}

void loop() {
  // set the motor speed:
  int motorSpeed = 15;
  if (motorSpeed > 0) {
    myStepper.setSpeed(motorSpeed);
    // step 1/100 of a revolution:
    myStepper.step(stepsPerRevolution / 25);
  Serial.println(motorSpeed);//print how fast the motor is going in the serial monitor
  }
}

Connecting the stepper motor and the driver, and launching the sketch in an arduino UNO board works perfectly, so I am really worried about that maybe the Stepper.h library might be different for the Arduino 101 but I couldn't find anything about that. I just have no idea why the project is not working in the 101 but working perfectly in the UNO. Any help or tips would be highly appreciated.
Cheers!
EDIT
After a lot of messing around, I have only been able to light up one led in the controller connecting one of the motor cables to GPIO5. None of the other GPIOS seem to work with the step motor controller.

After reading the Stepper library and searching for several, I saw that in an example using an EDISON ( I want to thanks to Guimficus for posting his code here: https://communities.intel.com/thread/99133) they changed the pinMode of the GPIOS they were using in the setup function :
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);

And after adding that seems to work like it is supposed to work.
Cheers!


text:
Running a 7 pin OLED with 4 pins (I2C)
I have an OLED with this 7 pin pinout:

I want to use an existing code i found that makes use of U8Glib.
But in the example, use uses 4 pins to control the OLED via I2C.
This is the pinout he uses:

Is it possible to control my OLED via 4 pins and use U8Glib to simplify my project by making use of the example code i found?
EDIT: Here is also a picture of the back of the OLED PCB that mentions how to use IIC but i do not understand it!

That looks like it may be an SPI interface, not I2C, so no. You can't.

Unless of course U8Glib has an SPI example for that board. I assume it's an SSD1306? Most small OLEDs are...

Looks configurable to I2C / 3-wire SPI / 4-wire SPI depending on the presence / absence of R1-R4.

This page has the answer to your questions. For reference:

Setting up SPI/I2C Connection with GMS096A OLED Module
Being a new entry to the market, only limited resources are available
  on this small piece of miracle (GMS096A). I2C/SPI configuration always
  demands helpful resources as in any case. For the SPI setup, the
  module comes in 4 wire SPI configuration by default and to make it
  work with the arduinos you can use these libraries from Adafruit.
For the I2C setup it demands a little bit of work on the module.
  Actually it was one of our customers who shared these simple
  configuration steps with us, start with resoldering the resistor from
  position R3 to R1 and then short the R8 resistor with some solder tin
  (0 Ohm resistor). The R6 and R7 pullup resistors are already soldered,
  nothing to do there. Once done, the module is ready for I2C
  communication! The CS Pin is not necessarily needed, so just connect
  it to GND. The DC Pin selects the address. For standard address wire
  it to GND. The RES-pin needs a low pulse at startup and high voltage
  during operation (as in SPI mode), a 100nF capacitor to GND and a 10k
  res to VCC would be ideal!

Your module might differ sightly. But you should be able to figure it out from there. The pulse on the RES-pin needed at startup took me a while to figure out!

Yes, it works IIC as described above, with my Arduino MEGA.
You can also connect RST Pin at Arduino RESET signal, so no need of extra R and C components

That is a SPI interface. Often the CS is missing, but you seem to have that pin. I suggest to start with the software PCI mode of the U8Glib.
This is the best explanation that I can find: Github: SSD1306 based OLED connected to Arduino
Would you consider using the newer U8g2 library ?
It is easier to use with Arduino boards that have more memory. But it has also the same mode for low memory usage, just like the U8Glib.

Is it possible to control my OLED via 4 pins and use U8Glib to simplify my project by making use of the example code i found?

i'm sure somewhere there is an i2c->spi bridge. if not, you can always code your arduino to behave like one.
short of that, you can simply code to control the board via spi.

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


text:
Hiding WLAN password when pushing to GitHub
I have started to use GitHub to store Arduino code. However some of my code uses the SSID and password for my WLAN which I don’t want published.
A common way of handling this in non-embedded programming is to use a configuration file, but that doesn’t seem to be a viable approach in programming the Arduino. I’m currently just commenting out the sensitive information before pushing it to GitHub, but one day I’m sure I’ll forget.
Is there another – better - way of handling this?

Sure you can use a config file. It's called a "header" file, and you just #include it in your sketch.
[config.h (not pushed)]

const char *password = "DOD982yp398fhgpwbn09tupf0p04";

[sketch.ino (pushed)]

#include "config.h"

// Now you can use the password variable.

Another method, which is better if you have multiple files in your sketch, is to use #define instead of variables in your header file:
[config.h]

#define WIFI_PASSWORD "348r0yp80ytwp85tpj8yjp98y97t8t"

[sketch.ino]

#include "config.h"

const char *password = WIFI_PASSWORD;

Of course! It never occurred to me to use a header file in this way. Many thanks for the answer.

One thing to watch is if you have multiple files in your sketch and you include that config file in each you will get errors about multiple definitions. In that case it's probably better to use #define instead of defining the variables directly.  I'll post an example.

You could commit the following file into your project, named
credentials.h:
// Replace with your actual SSID and password:

#define WIFI_SSID "Your SSID here"
#define WIFI_PASSWD "WLAN AP password here"

Near the beginning of your sketch, you add:
#include "credentials.h"

const char ssid[] = WIFI_SSID;
const char password[] = WIFI_PASSWD;

Now, you can edit credentials.h to add your real SSID and password, and
go on with your normal git workflow, with one exception: never
git add credentials.h again, nor git commit -a.
Now, git will always remind you that credentials.h has been modified and
is not staged for commit. It will do so even if you add the file to your
.gitignore. If you always review your changes before committing, this is
only a minor inconvenience. If, on the other hand, you tend to
git commit -a without reviewing what you are committing, then this
solution is likely not for you.

Edit: An idea I got from reading Chris Stratton's comments. If
you use a Makefile in your own workflow (this has already been discussed
in this site a few times), you could commit this credentials.h to your
repo:
#ifndef CREDENTIALS_H
#define CREDENTIALS_H

// Replace with your actual SSID and password:
#define WIFI_SSID "Your SSID here"
#define WIFI_PASSWD "WLAN AP password here"

#endif

Make a copy of this file named true-credentials.h and put the real
credentials there (but do not rename the include guard). Then add to
your Makefile
CFLAGS += -include true-credentials.h

Keep true-credentials.h and the Makefile out of the repo. You can add
them to your .gitignore or, better yet, to .git/info/exclude.
Now you have a compilable version with dummy credentials in the
repository, you have the true credentials when you compile on your own
machine, and git does not bother you about credentials.h being changed.

Interesting points and thanks. Looks like I am going to have to be more careful in how I use git.

This is a better solution, however, no, git will not tell you about changes to files in .gitignore unless you explicitly add them.  And adding a file explicitly excluded by .gitignore typically requires adding with a force flag.

@ChrisStratton: In my test, I added and committed the dummy credentials.h, then modified the file and added it to .gitignore. Git kept telling me “Changes not staged for commit: modified: credentials.h”. My point was to have a compilable version on the repo, hence the dummy credentials.h added there.

If you commit a dummy version, yes.  You may want to give the dummy version a different name, like credentials.h.CUSTOMIZE_ME or something, and perhaps back it up with a #ifndef #error giving instructions to make a copy without the suffix and edit.

Actually, nevermind, my idea won't work since the #include will fail without the custom message.  Really shows the primitiveness of the Arduino IDE compared to something permitting a sensible project file or a custom Makefile.

Eventually settled on the approach of adding the credentials.h reference to the .git/info/exclude file and having  a dummy credentials_CUSTOMIZE_ME.h file tracked by git (as explained above).  Also, added a README.md file to explain everything. Not using a Makefile at the moment, but that may change. Many thanks all for your help.

Building upon the shoulders of giants I took Edger Bonet's answer and used a slightly different twist.  I went this route because I don't use a makefile and found this solution works well for me in my project.
I created a placeholder credentials.h file with the following info (Edger's answer).
#ifndef CREDENTIALS_H
#define CREDENTIALS_H

// Replace with your actual SSID and password:
#define WIFI_SSID "Your SSID here"
#define WIFI_PASSWD "WLAN AP password here"

#endif

I further added the reference to this new file in the .ino file.
#include "credentials.h"

const char ssid[] = WIFI_SSID;
const char pass[] = WIFI_PASSWD;

Now the twist.. I excluded the file from being checked for changes using the --assume-unchanged command.

git update-index --assume-unchanged credentials.h

You can then modify the credentials.h file and wont be prompted to add it to github.
Note, to re-check the file use --no-assume-unchanged.

Kudos for the --assumed-unchanged tip!


text:
Encode & decode boolean values into a single integer?
I'm trying to record the state of some pins over time. To save memory, I'm thinking about encoding the pin states into a single integer, like this:
Pin 1: TRUE
Pin 2: FALSE
Pin 3: FALSE
Pin 4: TRUE

Pin 1 = 1, Pin 2 = 2, Pin 3 = 4, Pin 4 = 8
1 + 0 + 0 + 8
Result: 9

This is pretty efficient.
But how do I decode the pin states from this best?
Or do you recommend a better way to do this?

use the AND operator.
for example:
pin 2's state would be (result & 0x02)?TRUE:FLASE

It took me a minute (well, more like 5 ;) ) to figure out these are hex values, but the solution is simple and working perfect. Thank you!

You are almost there with that. Personally I'd use OR not +:
This is a better way of defining the pins instead of using 1, 2, 4 etc. It results in the same thing, but you can see the bit number in there. The << is left shift.
#define PIN0 (1 << 0)
#define PIN1 (1 << 1)
#define PIN2 (1 << 2)
#define PIN3 (1 << 4)

Now you can combine:
uint8_t val = PIN0 | PIN3; // 9

And you can check if one is set:
if (val & PIN3) {
    // ....
}

To loop through the pins you can use the << again:
for (uint8_t pin = 0; pin < 8; pin++) {
    if (val & (1 << pin)) {
        // ....
    }
}

etc.

Pretty cool. I will keep that in mind as another great solution, thank you for your help.


text:
weird output from keyboard program
I am trying to write a keyboard (Key-glove) program. There are 4 buttons, and inputs should type specific keys. when the keyboard is active, I get output, but not what I am expecting for output. I get "EnE" and "EC".
The Hardware is an adafruit Circuit Playground
Here is my source:
//keyboard control for TuxKart power Glove
#include <Adafruit_CircuitPlayground.h>
#include "Keyboard.h"

// set pin numbers for the five buttons:
const int Fire = 6;
const int Nitro = 9;
const int Eagle = 10;
const int _Esc = 12;

bool slideSwitch;

void setup() { // initialize the buttons' inputs:
  pinMode(Fire, INPUT);
  pinMode(Nitro, INPUT);
  pinMode(Eagle, INPUT);
  pinMode(_Esc, INPUT);

  Serial.begin(9600);
  // initialize mouse control:
  //Mouse.begin();
  Keyboard.begin();
}

void loop() {
  if (!CircuitPlayground.slideSwitch()) {
    return;
  }

  // use the pushbuttons to control the keyboard:
  if (digitalRead(Fire) == HIGH) {
    Keyboard.write('KEY_SPACE');
    Serial.println("A");
  }
  if (digitalRead(Nitro) == HIGH) {
    Keyboard.write('n');
    Serial.println("B");
  }
  if (digitalRead(Eagle) == HIGH) {
    Keyboard.write('KEY_BACKSPACE');
    Serial.println("Z");
  }
  if (digitalRead(_Esc) == HIGH) {
    Keyboard.write('KEY_ESC');
    Serial.println("Y");
  }
delay(700);
}

What does this have to do with Adafruit, and what board are you running it on?    What program on the PC or USB host is interpreting the keystrokes, and how exactly where you expecting it to respond to the escape key?  How exactly are your input switches or devices wired?  Does HIGH mean active or inactive?

Remove the single quotation marks for Keyboard.write. Use Keyboard.write(KEY_SPACE); and so on. Keep them for 'n', but not for the others.


text:
How to programmatically choose "board model" and "port number" in Arduino IDE?
I'm testing three different Arduino (nano, Uno and Mega) each of them having a nRF module. The codes (sketches) are different for each module.
I've connected the arduinos to my single laptop via 3 USB ports.
Problem is, whenever I want to re-upload a sketch and fix a bug, I have to choose board model and port number of that sketch by using the menus. It has become frustrating using mouse each time I need to change something.
How can I set these parameters in code so each sketch knows which port and model it is related to?

I don't think you will be able to do that with the Arduino IDE. You may have more luck with a Makefile-based workflow.

You can do it in UECIDE...

You can't in the Arduino IDE, it's not designed that way (you can't even have different board/port settings in different windows - it's stored in the Java equivalent of a single global).
Instead you will have to switch to a different programming environment.
Personally (since I am the author) I would suggest switching to UECIDE. That has far more advanced facilities than the Arduino IDE, yet still retains most of the simplicity of use.
In UECIDE you can not only have different ports and boards selected in different windows, you can also configure individual sketches to automatically select their board and port.

Sketch -> Sketch Properties... -> Objects tab

Tried to install it in Linux, but update fails: GPG error: http://majenko.co.uk/debian stable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 8386A4D0CA9F00A1

You have to install "majenko-keyring" first from the same repository. It adds the public key for you.

Or you can manually download the public key and add it with apt-key add: http://majenko.co.uk/debian/key.asc

Just following the script: First, update. Update failed. So, next install also failed:  "Unable to locate package majenko-keyring".

Darn, looks like I only had that package in unstable. Just backported it to stable.

That works. I'm working in a project with a nodeMCU talking I2C with an Arduino and I really need this.

Let us continue this discussion in chat.

NodeMCU support is sometimes a little shaky. The development tools provided by the ESP crowd aren't always the most stable of beasts. If you have any troubles with it head over to the UECIDE forums and I'll adjust whatever needs adjusting.

Take a look at the (similar) question and answer in https://arduino.stackexchange.com/a/9182/22924
It talks about multiple UNOs, but the solution should help here.


text:
Send AT commands programatically to ESP8266 without Arduino
Let me explain my question in more details. I want to use ESP8266-01 as standalone micro-controller for my project. I don't want to use Arduino or any other board with that.
Using Arduino i can use two of the pins as software serial and can send different AT commands to ESP module to ESP's Tx and Rx pins, but now what I want is to eliminate the need to Arduino.
What I want to do is to to program ESP itself to toggle mode from AP mode to Host mode on press of a push button. for that I has to send AT commands to ESP from the code while i will write to the ESP itself. Is there any way to achieve the same.
I tried searching a lot but what I found everywhere is how to send AT commands from Arduino.
Thanks in advance.

You don't use AT commands. You install the esp8266 boards package and program the esp8266 as if it were an Arduino. That means learning the esp8266 WiFi API which has plenty of examples included.

https://github.com/esp8266/Arduino/

This is what I am trying to do, I connected ESP using FTDI, and now I am programming it using Arduino IDE. Is there any provision such as software serial or anything like that ?

For doing what?


text:
If (serial.available()) conditional statement
I am very new to Arduino and I have a question I would like to clarify on Serial.Available()
According to Arduino documentation, Available() returns the number of bytes that are stored in the buffer, ready to be read. Why then, both If function below works, when there are data in the buffer? For Scenario A, it appears to me that there is no conditional statement, how then, would the IF function evaluates to TRUE?
Scenario A: IF(Serial.Available())
compare with
Scenario B: IF(Serial.Available()>0)
Thanks in advance!

Mind the case: neither IF nor serial or Available exist.

the do the same thing; the 2nd is a pedantic long-hand way of writing it more explicitly

In C, 0 is false and anything else is true. So if Serial.available() returns 0 it is considered false. If it returns 7, 23, 44, etc it is considered true.

But it is bad programming. It should be "if(Serial.available()>0)". The Serial.available does not return a boolean, but an integer. Therefor it should be tested against an integer. Off-topic: was there something with 'bool' and 'boolean' ?

@jot Boolean doesn't actually exist. There's a typedef in C++ (and in "stdbool.h" for C) that links it to an unsigned char. 0 is false, anything not 0 is true. There is absolutely nothing "bad" about it.

In my opinion an integer should be treated as an integer. Trying to be smart and rely on the compiler to fix bad programming is not okay. I think the 'boolean' and 'bool' problem have been fixed: "bool x = (bool) 23;" sets x to 1 and the same for boolean.

Personal opinions don't count. C and C++ are what they are. If you don't like it then program in visual basic.

Ha ha, visual basic. The 'c' and 'c++' is all about writing good code, because they allow to make a big mess of the code. Call it personal if you want to, I prefer code that shows what is going on. @user35336, Majenko has explained how it works, but we disagree if it is nice programming.

if( x ){ in C/C++ reads "if x is not equal to zero". If x is numeric, that expression could be considered an idiomatic shorthand. If x represents a boolean, it reads quite naturally. Consider, f/ex, the character-class test isdigit(). Most people (in my experience) write if( isdigit(x) ){, not if( isdigit(x) != 0 ){; even though the latter states in explicit detail, what test is to be made. It comes to stylistic preference, and like discussions of which programming editor is "best", & what placement of braces or indentation is "best", rapidly devolves into a religious argument.

@JRobert Hence "personal opinions don't count". A personal opinion doesn't make something "bad", only "not the same as I think". My personal opinion is that all footballers are overpaid pansies. Does that make it true? I think so, but millions of football supporters disagree with me. Neither is right, neither is wrong, they are just opinions. And we don't like opinions on this site - hence we can close a question as "primarily opinion based". It'd be nice if we could do the same with comments ;) - but that's just an opinion :P

Thanks for taking my point and running with it! I couldn't have constructed a better example. :)

@Majenko, I take back the "bad programming" and turn it into "some use the fact that 'true' is everything but zero, as specified by the 'c' language. Others prefer to test the Serial.available against an integer to show that the function returns an integer". I think everyone is happy now.

For certain functions I agree, for others I don't. if(!strcmp(...)) reads wrong. It looks like "if the strings don't match" when in fact they do. if (strcmp(...) == 0) is better in that instance. if (Serial.available()) says"if there is some serial data available" which is fine. It's more to do with how it reads to the human eye than what type it returns.

Scenario A, it appears to me that there is no conditional statement, h

The first is a test on if available() returns a non zero value.


text:
How can the sensitivity of capacitive touch sensors be limited?
I have an Adafruit circuit playground classic, and the touch-pads are so very sensitive. From a centimeter away, they trigger.  I would be happy to just have regular inputs, or to have the sensitivity reduced. How can I do this?
To clarify, here is my code:
//keyboard control for TuxKart power Glove
#include <Adafruit_CircuitPlayground.h>
#include <Keyboard.h>
#include <Mouse.h>
// set pin numbers for the five buttons:
const int Fire = 6;
const int Nitro = 9;
const int Eagle = 10;
const int _Esc = 12;

bool slideSwitch;

void setup() { // initialize the buttons' inputs:
  pinMode(Fire, INPUT_PULLUP);
  pinMode(Nitro, INPUT_PULLUP);
  pinMode(Eagle, INPUT_PULLUP);
  pinMode(_Esc, INPUT_PULLUP);

  Serial.begin(9600);
  // initialize mouse control:
  //Mouse.begin();
  Keyboard.begin();
}

void loop() {
  if (!CircuitPlayground.slideSwitch()) {
    return;
  }

  // use the pushbuttons to control the keyboard:
  if (!digitalRead(Fire) == HIGH) {
    Keyboard.write('KEY_SPACE');
    Serial.println("F");
  }
  if (!digitalRead(Nitro) == HIGH) {
    Keyboard.write('n');
    Serial.println("U");
  }
  if (!digitalRead(Eagle) == HIGH) {
    Keyboard.write(0xB2);
    Serial.println("N");
  }
  if (!digitalRead(_Esc) == HIGH) {
    Keyboard.write(0xB1);
    Serial.println("K");
  }
delay(200);
}

This code or any other, where capacitive touch sensitivity has not been specified, yields pins having extreme sensitivity. I have read the comments, that say the MCU doesn't feature this natively. If that were true, how would the pins remain sensitive?
My solution to this is to set sensitivity so low, that it is negligible. If capacitive touch sensing is not specified, why am I getting that functionality? Why would this code give me capacitive touch sensing?
Ideally, I would disable the touch sensing somehow, or have the pins simply behave normally, like any other Arduino based device that doesn't have touch sense. But what I have guessed, (shown in code) doesn't work. If there is a more explicit way to specify that IO pins should act as normal pins, without capacitive touch sensing, I would surely like to know.

Please edit your question to include part numbers and links to part descriptions.  Also a good idea to include a  Minimal, Complete, and Verifiable example of code, to show what libraries you are using to read the sensors

How do you do the capacitive sensing? Libraries? Code? This information is still missing.

Im not doing it, in code, the hardware is doing it automaticly. I havent figured out how to disable it. I hoped that by not having it in code, that the functionality wouldn't be active, but it would seem to be the opposite

You wrote: “Im not doing it, in code, the hardware is doing it automaticly”. Wrong. This board is based on the ATmega32u4, which does not natively support touch sensing. I can detect touch with the appropriate code/library, but it cannot do it in a hardware-only way.

Then how do i get functionality of capacitive touch,  if my code doesn't use it. Why isnt it just disabled? I'm here for answers, guys, basing my questions on observations. If i knew already, I wouldn't be asking.

digitalRead(pin) is the wrong way to read capacitive touch inputs.
In the file from the example you linked in your answer, the reading is made by calling CircuitPlayground.readCap(pin, num_samples) and then the returning value is compared to a threshold.
const uint16_t TOUCH_THRESHOLD = 300;

...

if (CircuitPlayground.readCap(Fire) >= TOUCH_THRESHOLD) {
   Keyboard.write(KEY_SPACE);
   Serial.println('F');
}
...

You can change the sensitivity by changing TOUCH_THRESHOLD. You could also add and fiddle with the second argument to change the number of samples.

Its not the best method for finding a solution, perhaps, but I was tooling around in the Adafruit_CircuitPalyground repo, and found a macro for the Capacitive touch sensitivity.
The macro is:
#define CAP_THRESHOLD 300 // Threshold for a capacitive touch (higher = less sensitive).

Located here:
https://github.com/adafruit/Adafruit_CircuitPlayground/search?utf8=%E2%9C%93&q=CAP_THRESHOLD&type=
I'm reading more, and trying to find the libraries for capacitive touch. There may be a much better solution, but for now defining CAP_THRESHOLD works well enough.


text:
How to use Atmega1284AU with Arduino IDE
Is there any support to this chip in Arduino IDE, like bootloaders and boards definitions.. i want to use this chip with 3.3V and 8Mhz crystal speed..
I have seen Nick Gammon bootloaders supports this chip for bootloaders, but not with 8Mhz.? and how to add this chip to Arduino IDE.
anybody help..
thanks you

Please check out MightyCore library by MCUdude.
https://github.com/MCUdude/MightyCore
I have used it and can verify it works pretty well with ATmega1284.


text:
I can't upload sketches to my Arduino 101
When connected to USB green Power LED on but doesn't upload sketch(that says press master reset therefore i've pressed several time but timeout). And main thing is device doesn't show in device manager.(I'm working on windows10).

Have I "bricked" it?
What steps can I take to work out what is wrong?
What can I do to fix it?

I've search in many sites but doesn't give me detail about hardware repairing guide for arduino 101.
I've checked working usb cable and another laptop but not work.I think hardware problem.Once arduino getting hot near usb.

Simply replace it because it has a 1 year warranty outside the US.

It's considered rude to post things in all caps online. I have fixed this for you but please don't do it again. Please add some more details to your answer to make it more helpful: What kind of process was required for the replacement? How did you contact customer service How prompt was their response? Did you have to return the Arduino 101 to get your replacement? If so, were return shipping charges paid by Arduino and was the return address in your country? What sort of restrictions are there for people in the US who need a replacement?

It's hard to tell, but you can try a lot of options:

Use another USB port
Use another USB cable
Reinstall the Arduino IDE
Remove the device in the device manager and try reinstalling the Arduino IDE again
Try another Arduino (to see if the USB/install is ok)
Try on a different computer/laptop

I've also checked all this but i think it's hardware problem.

If you checked all of the above as Michel Keijzers mentioned then it might be a hardware problem. Actually, your usb cable might not fitting correctly to the usb port.


text:
Problem with reading series of bytes over serial port
I'm writing a program to read bytes from serial channel, copy those into an array and then do some verification on those copied numbers.
I'm able to read and copy bytes into an array of bytes.
However, I'm facing an issue with the verification of those bytes.
Here's the code I've written:
#include <SoftwareSerial.h>

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

void loop()
{
    char charRead = 0x00u;
    byte byteArray[10];
    int i=0 , j=0;

    //Clear the array contents
    for(j = 0; j < 10u; j++)
    {
       byteArray[j] = 0x00u;
    }

    //Wait for data on serial channel
    while(Serial.available() > 0)
    {
       //Copy bytes received into array
       charRead      = Serial.read();
       byteArray[i] = (byte)charRead;
       i++;
    }

    //Just for the sake, print the array contents
    for(j = 0; j < i; j++)
    {
       Serial.print(byteArray[j],HEX);
    }

    //Check for first two bytes
    if( (byteArray[0] == 0x31) && (byteArray[1] == 0x32) )
    {
        Serial.println("Verified.");
    }
}

To test this program, I entered "12345" (without quotes) on the serial monitor which gave me an output as "3132333435" since I'm printing the contents of the array in HEX format.
What I'm not being able to understand is even if this output shows that the first two bytes in the array are 0x31 & 0x32 respectively, why not the verification logic of those two bytes is getting executed? If it would, then the string 'Verified' would get printed on the output.
Am I doing something wrong here with Serial.read() or some typecasting?
I'm running this on an Arduino Uno

You are continuously resetting i to 0, thus always writing into the first cell of your array.

You are probably reading one character per loop() run and your array has never more than one characters in it, so your comparison for two elements always fails.

So, as result of Edgar Bonet's good remark, change
int i=0 , j=0;

to
int j = 0;

and define
int i = 0;

Outside the loop (as a global variable).
Also it is quite dangerous to define the length of the array as 10, while not checking for writing over the boundary of the array. What if you receive more bytes? The application might crash or give unpredictable behavior.

The problem is not the size of the array. 10 bytes may be just fine for the intended application. The problem is not checking for overflow.

@EdgarBonet That was also what I meant, so I rephrased the line. Thank you for the notification.

I made some more mistakes too - declaring the array local inside loop() and also clearing it every time the loop runs. Thanks all.


text:
DigitalWrite Cannot Power HC-06 Bluetooth
To save power consumption, I tried to connect the HC-06 bluetooth module to a digital pin of my Arduino Nano. (HC-06 +5V <=> pin 11, HC-06 gnd <=> gnd) In that way, I can toggle the bluetooth when I am not using it. However, when I tried to pinMode(11, OUTPUT) and digitalWrite(11, HIGH), the led on HC-06 does not turn on which means it is not powered. I have tried to connect the HC-06 +5V to the 5V output of arduino and the HC-06 can turn on sucessfully. I have also tried to use a multimeter and the digital pin outputs a voltage of 5V. As the digital pins of Arduino can give 40mA while the HC-06 draws 30mA - 40mA, it should have enough power. I have also tried to use other digital pins as well but still the HC-06 cannot be powered.
What have I done wrong?

Is it average or maximum current consumption? And also 40mA for output pin is listed in section "Absolute Maximum Ratings" and there is also mentioned: "Exposure to absolute maximum rating conditions for extended periods may affect device reliability."

A digital IO pin is only capable of powering an LED or an incredibly low powered device. It is not suitable for powering meaty RF modules.
Instead you need to control the power to your module using a P-channel MOSFET as a High-Side switch.
For instance, assuming a 5V module with built in 3.3V LDO:

simulate this circuit – Schematic created using CircuitLab
Note that /RFEN is active low - set the pin OUTPUT and LOW to turn the module on. M1 should have a threshold of no lower than -4V, better -2V or higher.
Also be sure to set RX and TX to be INPUT when you power down the module or back-powering through the TX/RX pins may occur.
R2/R3 is a simple logic level shifter for the 3.3V logic signal the RX pin expects.

The RX line at least often has a pullup, which should probably be disabled.  And the TX to the module is better driven low than left high.

it should have enough power.

Probably not. Debugging is about challenging all assumptions, especially implicit ones.
Put a high side switch there and it should be ok.


text:
Send signal to vibrate a Restaurant buzzer via web based app to a PC
I'm new to Arduino, I want to create a restaurant buzzer using Arduino and it should turn on/off via web based interface. It will be locally connected only.
Is it possible to send a signal with the mac address of the master transmitter pc to vibrate the buzzer?
What are the materials should I need? Suggestions or any tips is greatly appreciated.

For anything that required TPC/IP, a better option is  nodeMCU (ESP8266). And for simply turning on a buzzer, MQTT is way easier that anything involving a web server. You can send the mac address, the ip address or whatever ID you choose .

You need a webserver, a defined interface for the client to connect to and a buzzer you can make some noise with.
Because you want to do it over WIFI, an Arduino is probably not the best choice.  As 'Look Alterno' says you might be better with an ESP8266 based device, because that has inbuilt WIFI.  I would suggest a Wemos D1, its an ESP8266 12 with a power supply and 2.54 pitch connectors, which means its easy to use with things.

Now you can program an ESP8266 using LUA, but I really wouldn't try that. Also if you do that you won't get any help on this forum.  Use the Arduino IDE and program it in the same language as an Arduino (You will need to download support for the ESP via the Board Manager in the IDE).  There is an example called "Advanced Web Server", done by Majenko on here, that will suit your needs.  You just need to change the root handler to activate the buzzer for n seconds and then return HTTP code 200.
Then your client just needs to connect to the root page of the webserver and the buzzer will sound.  You don't say how many clients will use this, but this will allow 5 simultaneous clients, if you need more that can be achieved easily.
You can then expand this to identify which client sounded the buzzer.
As to keeping it local, use the firewall on your router.

I strongly don't recommend LUA. It's a very beautiful language that I wish I can use, but in a bigger and more powerfull machine. I ran a Webserver under LUA, but crashed all the time. ESP8266 can run a light Webserver under C, but not even think about sending a 100KB javascript file thru it.

Also, ESP8266 have an upper limit of 5 TCP/IP connections at the same time. While sending a buzz is short and light, you will not able to manage a worst case scenario.

I want ESP8266 to connect my web site locally, not to connect in ESP8266. So my PC will act as the webserver and if ES8266 reads something to the code that will send signal to buzz.

OK.  I didn't get that from the question.  Strangely the solution is the same :)  The easiest way of connecting from your PC to the ESP is to use WIFI and run a webserver on the ESP that the PC talks to.  This gets around the 5 connection limit.  You could go to the effort of writing a serial client for your PC that sent the messages when the webserver got a request, but that's not going to be easy.  You are also going to have to write serial code for the ESP to parse the messages.  Its a lot of effort.  Does using WIFI from PC to ESP fit in with your plan?


text:
Can't print on LCD
I'm a newbie here. And sorry for my bad English first of all.
Right now I'm working on VLC (Visible Light Communication). I have working code, in which output is displayed on the Serial Monitor. But now I want to print this output on an LCD.
I made necessary changes like including the LCD library and instead of Serial.print I used lcd.print. But nothing is displayed on the LCD.
Here is the modified code including LCD:
static int TRESHOLD = 500;
static unsigned int standardDelay = 13500000; //1350 is limit
// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 7,6,5,4);

void setup() {
  Serial.begin(9600); // 9600 bits per second
  pinMode(3,OUTPUT); //digital PWM 3 on output
  int sensorValue = 0;
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // initialize the serial communications:
}

void loop() {
  WriteChar('h');
  WriteChar('e');
  WriteChar('l');
  WriteChar('l');
  WriteChar('o');
  WriteChar('w');
  WriteChar('o');
  WriteChar('r');
  WriteChar('l');
  WriteChar('d');
}

void WriteChar(char str){
  switch (str - '0'){
    case 49:
      //code for a is 011 0001
      LightFlash(false, true, true, false, false, false, true);
      break;
    case 50:
      //code for b is 011 0010
      LightFlash(false, true, true, false, false, true, false);
      break;
    case 51:
      //code for c is 011 0011
      LightFlash(false, true, true, false, false, true, true);
      break;
    case 52:
      //code for d is 011 0100
      LightFlash(false, true, true, false, true, false, false);
      break;
    case 53:
      //code for e is 011 0101
      LightFlash(false, true, true, false, true, false, true);
      break;
    case 54:
      //code for f is 011 0110
      LightFlash(false, true, true, false, true, true, false);
      break;
    case 55:
      //code for g is 011 0111
      LightFlash(false, true, true, false, true, true, true);
      break;
    case 56:
      //code for h is 011 1000
      LightFlash(false, true, true, true, false, false, false);
      break;
    case 57:
      //code for i is 011 1001
      LightFlash(false, true, true, true, false, false, true);
      break;
    case 58:
      //code for j is 011 1010
      LightFlash(false, true, true, true, false, true, false);
      break;
    case 59:
      //code for k is 011 1011
      LightFlash(false, true, true, true, false, true, true);
      break;
    case 60:
      //code for l is 011 1100
      LightFlash(false, true, true, true, true, false, false);
      break;
    case 61:
      //code for m is 011 1101
      LightFlash(false, true, true, true, true, false, true);
      break;
    case 62:
      //code for n is 011 1110
      LightFlash(false, true, true, true, true, true, false);
      break;
    case 63:
      //code for o is 011 1111
      LightFlash(false, true, true, true, true, true, true);
      break;
    case 64:
      //code for p is 100 0000
      LightFlash(true, false, false, false, false, false, false);
      break;
    case 65:
      //code for q is 100 0001
      LightFlash(true, false, false, false, false, false, true);
      break;
    case 66:
      //code for r is 100 0010
      LightFlash(true, false, false, false, false, true, false);
      break;
    case 67:
      //code for s is 100 0011
      LightFlash(true, false, false, false, false, true, true);
      break;
    case 68:
      //code for t is 100 0100
      LightFlash(true, false, false, false, true, false, false);
      break;
    case 69:
      //code for u is 100 0101
      LightFlash(true, false, false, false, true, false, true);
      break;
    case 70:
      //code for v is 100 0110
      LightFlash(true, false, false, false, true, true, false);
      break;
    case 71:
      //code for w is 100 0111
      LightFlash(true, false, false, false, true, true, true);
      break;
    case 72:
      //code for x is 100 1000
      LightFlash(true, false, false, true, false, false, false);
      break;
    case 73:
      //code for y is 100 1001
      LightFlash(true, false, false, true, false, false, true);
      break;
    case 74:
      //code for z is 100 1010
      LightFlash(true, false, false, true, false, true, false);
      break;
    default:
      lcd.print(str - '0');
      lcd.print("CAME IN DEFAULT IN WRITECHAR");
      break;
  }
}

void LightFlash(boolean a, boolean b, boolean c, boolean d, boolean e, boolean f, boolean g){

  digitalWrite(3,LOW);
  if (a == true){
    digitalWrite(3,HIGH);
  }
  delayMicroseconds(standardDelay/2);
  boolean sensorValue1 = (analogRead(A0)>TRESHOLD);
  delayMicroseconds(standardDelay/2);

  digitalWrite(3,LOW);
  if (b == true){
    digitalWrite(3,HIGH);
  }
  delayMicroseconds(standardDelay/2);
  boolean sensorValue2 = (analogRead(A0)>TRESHOLD);
  delayMicroseconds(standardDelay/2);

  digitalWrite(3,LOW);
  if (c == true){
    digitalWrite(3,HIGH);
  }
  delayMicroseconds(standardDelay/2);
  boolean sensorValue3 = (analogRead(A0)>TRESHOLD);
  delayMicroseconds(standardDelay/2);

  digitalWrite(3,LOW);
  if (d == true){
    digitalWrite(3,HIGH);
  }
  delayMicroseconds(standardDelay/2);
  boolean sensorValue4 = (analogRead(A0)>TRESHOLD);
  delayMicroseconds(standardDelay/2);

  digitalWrite(3,LOW);
  if (e == true){
    digitalWrite(3,HIGH);
  }
  delayMicroseconds(standardDelay/2);
  boolean sensorValue5 = (analogRead(A0)>TRESHOLD);
  delayMicroseconds(standardDelay/2);

  digitalWrite(3,LOW);
  if (f == true){
    digitalWrite(3,HIGH);
  }
  delayMicroseconds(standardDelay/2);
  boolean sensorValue6 = (analogRead(A0)>TRESHOLD);
  delayMicroseconds(standardDelay/2);

  digitalWrite(3,LOW);
  if (g == true){
    digitalWrite(3,HIGH);
  }
  delayMicroseconds(standardDelay/2);
  boolean sensorValue7 = (analogRead(A0)>TRESHOLD);
  delayMicroseconds(standardDelay/2);
  delayMicroseconds(3*standardDelay); //1 second passed

  long result = 0;
  result = 1000000*sensorValue1 + 100000*sensorValue2 + 10000*sensorValue3
  + 1000*sensorValue4 + 100*sensorValue5 + 10*sensorValue6 + 1*sensorValue7;
  //lcd.print(result);
  PrintChar(result);
}

void PrintChar(long binary){

  switch (binary){

    case 110001:
      //code for a is 011 0001
      lcd.write("a");
      break;
    case 110010:
      //code for b is 011 0010
      lcd.print("b");
      break;
    case 110011:
      //code for c is 011 0011
      lcd.print("c");
      break;
    case 110100:
      //code for d is 011 0100
      lcd.print("d");
      break;
    case 110101:
      //code for e is 011 0101
      lcd.print("e");
      break;
    case 110110:
      //code for f is 011 0110
      lcd.print("f");
      break;
    case 110111:
      //code for g is 011 0111
      lcd.print("g");
      break;
    case 111000:
      //code for h is 011 1000
      lcd.print("h");
      break;
    case 111001:
      //code for i is 011 1001
      lcd.print("i");
      break;
    case 111010:
      //code for j is 011 1010
      lcd.print("j");
      break;
    case 111011:
      //code for k is 011 1011
      lcd.print("k");
      break;
    case 111100:
      //code for l is 011 1100
      lcd.print("l");
      break;
    case 111101:
      //code for m is 011 1101
      lcd.print("m");
      break;
    case 111110:
      //code for n is 011 1110
      lcd.print("n");
      break;
    case 111111:
      //code for o is 011 1111
      lcd.print("o");
      break;
    case 1000000:
      //code for p is 100 0000
      lcd.print("p");
      break;
    case 1000001:
      //code for q is 100 0001
      lcd.print("q");
      break;
    case 1000010:
      //code for r is 100 0010
      lcd.print("r");
      break;
    case 1000011:
      //code for s is 100 0011
      lcd.print("s");
      break;
    case 1000100:
      //code for t is 100 0100
      lcd.print("t");
      break;
    case 1000101:
      //code for u is 100 0101
      lcd.print("u");
      break;
    case 1000110:
      //code for v is 100 0110
      lcd.print("v");
      break;
    case 1000111:
      //code for w is 100 0111
      lcd.print("w");
      break;
    case 1001000:
      //code for x is 100 1000
      lcd.print("x");
      break;
    case 1001001:
      //code for y is 100 1001
      lcd.print("y");
      break;
    case 1001010:
      //code for z is 100 1010
      lcd.print("z");
      break;
    case 11000:
      lcd.print("dit gebeurt vaak");
      break;
    case 1011001:
      lcd.print("dit ook");
      break;
    case 100001:
      lcd.print("tenslotte dit nog");
      break;
    case 1011000:
      lcd.print("en dit is de laatste denk ik");
      break;
    default:
      lcd.print(binary);
      lcd.print("CAME IN DEFAULT ON PRINTCHAR");
      break;
  }
}

I want to print this output on LCD. But I'm not able to do that. Please help me out.
Circuits:
(1) VLC Circuit

(2) LCD Circuit

I combined both circuits above and made a final circuit.
The VLC circuit is set up in which DATA is transmitted from SIMPLE LED and Capture on PHOTODIODE. And using LCD Circuit I want to display data on LCD.

I don't see any code related to the LCD.

@MichelKeijzers Becuase I remove it and upload original code. Already I mention that thing. Just check it out above the code. Ok...

Not enough information. Post your LCD code and schematics.

@LookAlterno Ok, let me.

Connecting a LCD display to an Arduino is not easy because of all those wires and the contrast and the cheap displays need enough voltage (above 4.5 V). I had some trouble with it myself. The second time it was a piece of cake. Forget your project for a moment and make a sketch that only uses the LCD. Start here: https://www.arduino.cc/en/Reference/LiquidCrystal

@Jot Thank you for your advice. I also try out so much code of LCD. Connection setup is all right. But not able to find out what's wrong happen with my code. I uploaded the latest code with. Please check out.

I did. Please make an other small test sketch, just for the display. Your sketch has conflicting things for characters, binary and values. Some improvements can make it easier. But first try to get something on the display. The wires are connected to other pins than in your sketch.

@Jot How? Because I think the whole sketch is necessary. I can't able to make some small sketch.

Of course you can. Make another sketch, a small test sketch that writes "hello" to the lcd display. If that is working, then you know that the display is wired okay and the contrast is okay.

@Jot Oh, you are to say that make simple LCD code which displays "Hello" word. I already do that. And working fine.

I think you ascii conversion is wrong. Ascii code for "h" is 110 1000, and you are using 011 1000.

Finally, got the problem. My code is working fine. I have a problem with my LCD connection.
I write
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);

Instead of
LiquidCrystal lcd(12, 11, 4, 5, 6, 7);

There is so many problems with your code. It can be so much short.
Take WriteChar. Why mess with binary value for chars? Use char directly, just here:
void setup() {
  Serial.begin(9600);
  WriteChar('h');
  WriteChar('e');
}

void loop() {
}

void WriteChar(char c) {
  boolean b7 = c & B1000000;
  boolean b6 = c & B0100000;
  boolean b5 = c & B0010000;
  boolean b4 = c & B0001000;
  boolean b3 = c & B0000100;
  boolean b2 = c & B0000010;
  boolean b1 = c & B0000001;

  Serial.println(c);
  LightFlash(b7, b6, b5, b4, b3, b2, b1);

}

void LightFlash(boolean b7, boolean b6, boolean b5, boolean b4, boolean b3, boolean b2, boolean b1) {
  Serial.print(b7 ? "1" : "0");
  Serial.print(b6 ? "1" : "0");
  Serial.print(b5 ? "1" : "0");
  Serial.print(b4 ? "1" : "0");
  Serial.print(b3 ? "1" : "0");
  Serial.print(b2 ? "1" : "0");
  Serial.println(b1 ? "1" : "0");
}

There is more simply ways to write that (using arrays and loops) but this is easier to understand. And better, pass the char directly to LightBlash.
Don't use a string when you just pass a char to a function.


text:
Differences between nodemcu and arduino processer
I have an arduino Uno and nodemcu development board.
I have an OV7076 camera and used with arduino UNO. It worked flawlessly with it and the code used is provided in the [Instructables tutorial][2] named as FromComputerNerd.ino.
Now i want to use it with Nodemcu. Whereas Nodemcu have a single Analog input but OV7076 uses two analog inputs [shown in][2]. So to get it I am trying to use Multiplexer. I can change the code so that it would adjust for analog pins.
But will the code be compatible with Nodemcu. Since it was written for arduino uno.If not, What changes can be done to make it compatible?
http://www.instructables.com/id/OV7670-Without-FIFO-Very-Simple-Framecapture-With-/

OV7076 doesn't use any analog signals. They are all digital.

the hardware can work. the sketch will need stripped of all it's AVR-specific refs like hard-coded ports.

Camera doesn't send data via Analog to Arduino.
A5 and A4 are I2C bus beside Analog.
NodeMCU has Software I2C protocol bus too, You can use D1 (GPIO 5) as CLK, and D2 (GPIO 4) as SDA.
see : https://github.com/esp8266/Arduino/blob/master/doc/libraries.rst#i2c-wire-library

I am suggesting you to buy NodeMCU because it is having inbuilt WIFI, you can connect NodeMcu to internet without much effort compare to connecting UNO to internet, and the best thing is NodeMCU is arduino compatible you can do all possible stuff that can be done with UNO. We can also program NodeMCU in 'C' language using Arduino IDE directly
Hardware comparison
NodeMCU

128KB RAM
4MBytes ROM(flash)
micro USB port
Small Board Size

Arduino UNO

2kB RAM
32 KB ROM
USB type B connector
Bigger in size than NodeMCU

Both are having nearly same prices.


text:
Code to obtain PWM output
I tried code to obtain 100KHZ PWM output with a 41.66% duty cycle by reading an analog value from A0, which is compared with a reference 5V value for obtaining PWM value.
Can someone help me with the code? Any help is very much appreciated.
Here is my code.
int Pwmpin=9;//Pwm Output Pin
int Fchange= A0;//Frequency change through Potentiometer

void setup() {
  pinMode(Pwmpin, OUTPUT);//Pwm pin as Output
  Serial.begin(9600);
  TCCR1A=_BV(COM1A1)|_BV(COM1B1);//Non-inverted Mode
  TCCR1B=_BV(WGM13)|_BV(CS11);//Prescalar 8
}

void loop(){
  float freq=0;
  float count=10000,countt=0,Pinput=0;
  while(1){
    ICR1=count;//variable Frequency
    countt=16*count;
    freq= int(16000000/countt);
    OCR1A=int(count/2);
    Serial.print("Pwm Freq =");
    Serial.println(freq);
    count=10000;
    Pinput=analogRead(A0);//Read input value
    Serial.print("adc value is:");
    Serial.println(Pinput);
    Pinput=(Pinput/0.0113);
    Serial.print("pwm value is:");
    Serial.println(Pinput);
    count=count+Pinput;
    if(count>=100000) {
      count=10000;
    }
    delay(1000);
  }
}

And the question is?

It is difficult to help when we do not how the ADC value should relate to the PWM output.  However, keep in mind that ADC conversions are normally noisy and likely should employ techniques to reduce the noise.  Also, you might want to look at the micro processor's specifications for the specific processor on your specific Arduino (there are many different types).  The PWM values you stated may not be obtainable due to the granularity of the processor's PWM hardware.

You could get 41.6̅% duty cycle with a 12 MHz Arduino (do these even exist?). The closest you can get with a 16 MHz Arduino is 41.875%.

You appear to be trying to model an analog PWM generator circuit with an MCU - this is probably a bad idea, and would need a higher performance ADC at least.  If it all possible, simply using the internal timer to generate PWM digitally would be best.

Read the datasheet.
Figure out which pen mode works for you and which prescaler and top you need.
Set timer1 to that mode.

After that all you need is to load the duty cycle register with the desired value.
For your application leave the top value alone.
Your code is far from that.


text:
Arduino Gesture Sensor error:No such file or directory
I cloned https://github.com/sparkfun/APDS-9960_RGB_and_Gesture_Sensor
and copied the libraries into the Arduino libraries folder. I then launched Arduino and selected the example. I opened the file GestureTest and when I started upload I received this error:

GestureTest.ino:49:31: fatal error: SparkFun_APDS9960.h: No such file or directory
compilation terminated.

I checked the SparkFun_APDS9960.h and I found it in the Gesture_Sensor/Libraries/src folder.
Is there a solution to resolve this error?

SparkFun made a poor choice for the folder structure of that repository. Likely this has caused you to incorrectly install the library. Please follow these instructions:

Download the latest release from https://github.com/sparkfun/APDS-9960_RGB_and_Gesture_Sensor/releases. Currently it is https://github.com/sparkfun/APDS-9960_RGB_and_Gesture_Sensor/archive/V_H1.0_L1.4.2.zip.
Unzip the downloaded file.
Rename the folder APDS-9960_RGB_and_Gesture_Sensor-V_H1.0_L1.4.2/Libraries/Arduino to SparkFun_APDS9960. This is not absolutely necessary but "Arduino" is not a very descriptive name for a library folder and the Arduino IDE works best when the library folder name matches the primary header file name so this is best practices.
Copy the SparkFun_APDS9960 folder to {sketchbook folder}/libraries. You can find the location of the sketchbook folder at File > Preferences > Sketchbook location.
Restart the Arduino IDE if it's running (not necessary with recent versions of the Arduino IDE).

Note that the folder structure of this library requires Arduino 1.6.x or newer.
UPDATE: I submitted a pull request to put the library in an appropriately named folder. This won't change the instructions above until the next release but it does remove the need to rename the folder if you are cloning the repository or downloading from the tip of the repository rather than a release.


text:
Do all serial ports on an Arduino MEGA 2560 have the potential to "brick" attached items when being flashed?
I was browsing through the hookup guide for SparkFun's OBD-II UART breakout and found something particularly worrying written half way down in a quite casually presented way:

Keep in mind when you upload this to your board, you will want to disconnect the OBD-II board RX line from the Arduino TX-0, to prevent issues during code upload, such as bricking the OBD-II board.

For my money I think bricking your device should come with a more stark warning than one stuffed part way down a guide starting with "keep in mind" and continuing with "issues". Nonetheless it caught my attention as I tend to build sealed boxes that aren't sprawled in front of a keyboard ready to be rewired any time a re-flash might happen.
Is the real risk here the fact that all of the flashed data would stream past the RX pin of the UART board and potentially accidentally send a 'self-destruct' signal? (Also I'm not sure a system is really up to scratch if you can accidentally tell it to kill itself.)
Surely the programming port is not the one being borrowed by the UART hookup? On a MEGA 2560, using a different serial port, is this still a risk or is that only on boards with one serial port?

fwiw, when updating ESP8266s, even via OTA, i'll often see the GPIO's "go nuts". On my light dimmers, that means the light is flashing and dimming rapidly and randomly. if it were more complex than a dimmer, it could be a very bad thing...

In the Sparkfun example the Arduino Uno is used. The Uno has only one hardware serial port, and that is used to upload a sketch and for the serial monitor. Pin 0 (RX) and pin 1 (TX) can be overriden for something else. However, then you must know what you are doing, and connect and disconnect modules as required.
The Arduino Leonardo and (Pro) Micro use a USB CDC implementation and have a unused hardware serial port at pin 0 and 1.
The Arduino Mega 2560 uses the hardware serial port at pin 0 and 1 to upload a sketch, just as the Uno. However, the three other hardware serial ports are not used, and you are free to use them.
If you use an unused hardware serial port for the OBD-II, there is no risk at all. You can use that port and nothing else messes with that port.
If you use a serial port that is also used to upload a sketch, or a software implementation of a serial port, you probably are going to make a mistake some day, and there is a risk to send the wrong data to the wrong hardware.
[ADDED]
I see that the example code in the SparkfunHookup Guide uses the Arduino Uno and SoftwareSerial on pin 2 and 3. That is independent of the hardware serial port. The SoftwareSerial is something that should be used as a last resort, since it almost completely takes over the Arduino board. It's good to have SoftwareSerial, but try to avoid it.
If you do want to use an Arduino Uno, perhaps the AltSoftSerial can be used. The AltSoftSerial works okay for 9600 baud as long as no other code uses too much time in interrupts and no one else uses TIMER1.