texts:
I've succeeded to get an Arduino to work with a pressure sensor.

What I want to do is

when I put pressure on the sensor, after 5 minutes the led lights on.
it starts over again if there's no pressure on the sensor.

Here's the program:

// FSR is verbonden met analoog 0
int fsrAnalogePin = 0;
// De LED is verbonden met pin 11 (pmw pin)
int LEDpin = 11;
// De analoge waarde van de fsr spanningdeler
int fsrWaarde;
// De helderheid van de led tussen 0 en 255
int LEDhelderheid;

void setup() {
    // start de serial monitor
    Serial.begin(9600);
    pinMode(LEDpin, OUTPUT);
}

void loop() {
    fsrWaarde = analogRead(fsrAnalogePin);
    // print ‘Analoge waarde’
    Serial.print(“Analoge waarde = “);
    // print de fsrwaarde op de monitor
    Serial.println(fsrWaarde);

    // maak van getallen tussen 0 en 1023 getallen tussen 0 en 255
    LEDhelderheid = map(fsrWaarde, 0, 50, 0, 255);
    analogWrite(LEDpin, LEDhelderheid);
    delay(100);
}

I've got this for the pressure sensor... now I need to combine it with 5 minutes and the led lights on when it's reached that 5 min of pressure.

i managed to do this but it aint enough...

unsigned long currentTime;
unsigned long startTime;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  currentTime = millis();
  startTime = currentTime;
}

    void loop() {
  currentTime = millis();
  // put your main code here, to run repeatedly:
  Serial.println(currentTime);
  delay(1000);

  if(currentTime-startTime > 6000) {
Serial.println("1 minuut voorbij");
startTime = currentTime;
  }
}


texts: ESP8266 NONos SDK with Arduino ide or VSCode PlatformIO

texts:
I have few questions about esp8266 programming. I am trying to make a iot application with esp8266. I have to run esp on two modes and create tcp server and http client. I did this application with arduino codes. But i want to fall deeper for esp. ( like bare metal sth.). I did some research on internet and i found nonos sdk for esp's. I tried some app on it.
For example: I didnt use WiFi.begin function and tried use nonos sdk functions. This way is true? or will this way help me to learn nonos SDK? I have checked api refference is prepared by espressif and i am trying  this functions.
My C knowledge is not too hard, so i dont enter in depth for this situation. Actually i want to begin nonos sdk with this little steps but i concerned is this true way?

My aim is improve my C skills as well as learning SDK.

Is there any suggestions about this situation, please can u share with me?
and is there any proper tutorials about esp8266 NONos SDK can sahre me?


texts: Error while inputting EEPROM.read() and EEPROM.write()

texts:
I am trying to store data in ATmega328 (Arduino Uno) using the following code using tinkercad:
#include <EEPROM.h>

void setup() {
  int addr, data=1;
  Serial.begin(9600);
  for (addr=0; addr<1023; addr++) {
    EEPROM.write(addr, data);
  }
  for (addr=0; addr<1023 ; addr++) {
    Serial.print(EEPROM.read(addr), DEC);
  }
}

When I simulate the code in the tinkercad, then i get the following error:
In function `main':
43: undefined reference to `loop'
 error: ld returned 1 exit status

Please help me where is the error in my code. I am not able to understand the error source.


texts: Arduino Sketch: NodeMCU compilation error

texts:
Every time I try to compile a program written in Arduino IDE 1.8.5 for NodeMCU (LoLIN version v3), I get the following error:

Arduino: 1.8.5 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 115200, 4M (3M SPIFFS)"

C:\Users\sumeetpatil\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-ar: unable to rename 'C:\Users\SUMEET~1\AppData\Local\Temp\arduino_build_831529/arduino.ar'; reason: File exists

exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

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

I have tried reinstalling several times, but I just can't get ahead of this step.


texts:
I just bought an LCD. I connected everything as explained in this sheet.

This is the code I am using:

#define RST 3
#define CE 2
#define DC 4
#define DIN 6
#define CLK 5

void LcdWriteCmd(byte cmd) {
  digitalWrite(DC, HIGH); //DC pin is low for commands
  digitalWrite(CE, HIGH);
  shiftOut(DIN, CLK, MSBFIRST, cmd); //transmit serial data
  digitalWrite(CE, LOW);
}

void setup() {
  pinMode(RST, OUTPUT);
  pinMode(CE, OUTPUT);
  pinMode(DC, OUTPUT);
  pinMode(DIN, OUTPUT);
  pinMode(CLK, OUTPUT);
  digitalWrite(RST, LOW);
  digitalWrite(RST, HIGH);
  LcdWriteCmd(0xAE); // LCD set display enabled
  LcdWriteCmd(0x21); // LCD set power COntrol
  LcdWriteCmd(0x14); // LCD bias mode 1:40
  LcdWriteCmd(0xA2); // LCD basic commands
  LcdWriteCmd(0xA9); // LCD all segments on
}

void loop() {
}

The commands I used are in the command table of this sheet. (page 12)
It is supposed to turn all pixels on now. However nothing happens. All pixels are staying off.

Can you see a problem?


texts: Why do preformed breadboard jumper wire sets miss so many useful lengths?

texts:
When I'm setting up a small breadboard (400 point) with a Nano, I often find myself having to run wires that are between 1" and 2" or point distances between 10 and 20 spaces on the breadboard. I have a few different sets of preformed breadboard jumper wire that you can find online and in stores and they all seem to follow the same lengths and color standards, but for whatever reason, they don't have lengths that I find useful for Arduino work. Why is that?  Historical reasons?  Am I doing something wrong? I've made this diagram using Tinkercad to show what I mean. In it, I show the various lengths of jumper wire that are often provided.

I realize that I can use other types of jumper wires or make my own, but the main reason for buying the preformed ones are that they are fast, compact and hug the breadboard. Also, the 2" length ones aren't even the right size to connect the power rails on both sides so why not make them 1.8" length instead of 2.0" length? I have seen other people do the same thing of using a 2.0" length wire and bending it slightly to connect the power rails.

I've searched online for other people asking this same question and didn't find anyone else complaining so I'm wondering if I've been using them wrong all this time. :/


texts:
I want to start a relay, have it run for 3 seconds, stop for 10 seconds, repeat.

I can't use delay, because I have a motor driver starting / stopping every 100 milis.

So I put together this code, but it does not work. Any help appreciated.

There's a 500ms delay to stop too much debugging info.

Also for some reason, tenSecondsBool switches to true as soon as you run the code.

unsigned long threeSeconds=3000; // the time we need to wait
unsigned long threeSecondsMillis=0; // millis() returns an unsigned long.
unsigned long fourSeconds=7000; // the time we need to wait
unsigned long fourSecondsMillis=0; // millis() returns an unsigned long.

unsigned long previousMillis=0; // millis() returns an unsigned long.
bool ledState = false; // state variable for the LED
bool led2State = false; // state variable for the LED
unsigned long tenSecondMilis=0; // millis() returns an unsigned long.
unsigned long tenSeconds=10000; // the time we need to wait

unsigned long paliGasiMilis=0; // millis() returns an unsigned long.
unsigned long paliGasi=1000; // the time we need to wait

unsigned long ventMilis=0; // millis() returns an unsigned long.
unsigned long ventInt=100; // the time we need to wait

bool threeSecondBool = false;
bool tenSecondBool = false;

int Fin1 = D7;

#define enA D1
#define in1 D2
#define in2 D3
#define button 4

int rotDirection = 0;
int pressed = false;

void setup() {
  Serial.begin(9600); // send and receive at 9600 baud
  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(button, INPUT);
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  pinMode(Fin1, OUTPUT);
  digitalWrite(Fin1, HIGH);
  threeSecondBool = false;
  tenSecondBool = false;
}

void loop() {

 unsigned long currentMillis = millis(); // grab current time

 if ((unsigned long)(currentMillis - tenSecondMilis) >= tenSeconds) {
    Serial.print("---------------\n");
    Serial.print("10 second end\n");
    Serial.print("---------------\n");
    tenSecondBool = true;
    tenSecondMilis = millis();
}

Serial.print("10 second bool = ");
Serial.print(tenSecondBool);
Serial.print("\n");
Serial.print("3 second bool = ");
Serial.print(threeSecondBool);
Serial.print("\n");

 if (tenSecondBool) {
  if ((unsigned long)(currentMillis - threeSecondsMillis) >= threeSeconds) {
   Serial.print("---------------\n");
   Serial.print("3 second end\n");
   Serial.print("---------------\n");
   threeSecondBool = true;
   threeSecondsMillis = millis();
  }
 }

if (!tenSecondBool && threeSecondBool){
  Serial.print("Both triggered!\n");
  digitalWrite(Fin1, HIGH);
}

if (!tenSecondBool && !threeSecondBool){
  Serial.print("Both triggered!\n");
  digitalWrite(Fin1, HIGH);
}

if (tenSecondBool && threeSecondBool){
  threeSecondBool = false;
  tenSecondBool = false;
  digitalWrite(Fin1, LOW);
}

delay(500);

  if ((unsigned long)(currentMillis - ventMilis) >= ventInt) {
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
    ventMilis = millis();
  } else {
    digitalWrite(in1, LOW);
    digitalWrite(in2, HIGH);
  }

}


texts: Turn on one by one the LEDs of a Neopixel rgb LEDs strip for each detection at the same distance from an Ultrasonic Distance Sensor (HC-SR04)

texts:
For this project I seek to create a counter of water glasses we drank throughout the day.
I use for this an Arduino UNO card, a Piezo buzzer and a Neopixel rgb LEDs strip (5 LEDs for this test).

Aside from the last 2 LEDs that only light up to indicate to the user that his presence is considered by the product, I would like that when the HC-SR04 first detects our glass of water between 0 and 5cm (cheers!), the first LED lights up and stays on. When the first LED is on and the HC-SR04 detects a second time our water glass is between 0 and 5cm, then the second LED lights up and stays on as well. And so on.
For each glass detected between 0 and 5cm, a slight sound sounds through the piezo buzzer.

By using the Adafruit Neopixel library (download here), I manage to make everything work as I see fit. However, I still have trouble programming if the LED n is on then the n+1 LED lights up at the next detection between 0 and 5cm, without all the LEDs lighting at the same time in a single detection.

I recently tried to use a boolean to identify when the LED n is true (ON/HIGH), but unsuccessfully. I leave you my code as is by thanking you for any help you can bring me.

See my layout and my code below:

#include <Adafruit_NeoPixel.h>

const int trigPin = 9;
const int echoPin = 10;
const int buzzer = 11;

#define dinPin 4
#define numLEDs 5

Adafruit_NeoPixel strip = Adafruit_NeoPixel(numLEDs, dinPin, NEO_GRB + NEO_KHZ800);

long duration;
int distance;

int blue;
int green;
int off;

boolean lightLED = false;

void setup() {
  strip.begin();
  strip.setBrightness(80);
  strip.show();

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(buzzer, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);

  distance = duration * 0.034 / 2;

  uint32_t blue = strip.Color(0, 100, 255);
  uint32_t green = strip.Color(0, 255, 20);
  uint32_t off = strip.Color(0, 0, 0);

  ///////////////////////////////////////////////////////////
  // LED 1 + Buzzer
  ///////////////////////////////////////////////////////////

  if (distance <= 5) {

    if (! lightLED) {
      strip.setPixelColor(0, blue);
      strip.show();
      delay(0);
    }

    else {
      lightLED = false;
    }

    digitalWrite(buzzer, HIGH);
    tone(buzzer, 400, 100);
    delay(75);
    tone(buzzer, 600, 100);
    delay(75);
    tone(buzzer, 800, 100);
    delay(75);
    noTone(buzzer);

  }

  else {
    digitalWrite(buzzer, LOW);
  }

  ///////////////////////////////////////////////////////////
  // LED 2
  ///////////////////////////////////////////////////////////

  if (lightLED && distance <= 5) {

    lightLED = true;

    if (! lightLED) {
      strip.setPixelColor(1, blue);
      strip.show();
      delay(0);
    }
  }

  ///////////////////////////////////////////////////////////
  // DETECT USER PRESENCE
  ///////////////////////////////////////////////////////////

  if (distance >= 6 && distance <= 20) {
    strip.setPixelColor(3, green);
    strip.setPixelColor(4, green);
    strip.show();
    delay(0);
  }

  else {
    strip.setPixelColor(3, off);
    strip.setPixelColor(4, off);
    strip.show();
    delay(0);
  }

  // Voir la distance dans le moniteur
  Serial.print("Distance: ");
  Serial.println(distance);
}

Sorry for the code that is a bit rough, I am a beginner but I hope not to have lost you in my explanations (I lose myself in my code…).

Thanks,

Thibaut


texts: FreeRTOS: Object not created properly from within task

texts:
I am encountering a very strange error using freeRTOS on an Arduino Mega2560:

In the setup block I can create an instance of my class:

MyClass* myClass = new MyClass(/*char*/ a, /*char*/ b, new Vector(42));
// new Vector(42) creates a new vector and pushes 42 in as first item

Using a print() method in this class, I get a legitimate output on the console, showing me all the chars and values in the vector.

Using the exact same line inside a task, causes the object not to be created properly. It seems like the fields are empty or there is something entirely wrong (like strange memory errors) with the instance. Printing it again results in an empty line (program doesn't crash) while printing a globally created instance gives the correct result.

Is there any trap in freeRTOS concerning the creation of new instances of an object inside a task? Below is the code for the task creation, increasing the task stack size doesn't help. For debug reasons this the only task running at the moment.

xTaskCreate(displayTask,
    "DisplayTask",
    configMINIMAL_STACK_SIZE + 300,
    NULL,
    tskIDLE_PRIORITY + 1,
    NULL);


texts:
I have a working fan control with the correct wiring that works with arduino.

I would like to change the arduino with a Wemos D1 mini board.

When I hook everything up. The fans are not activated.

The fan is driven by a 12v charger. And the irf540n cicruit powers that. They just share a common ground and the pwm pin D5

Is there something I need to know about the difference in both of them?

Below is the code, I've changed D5 in the code to 14.

Still nothing seems to work.

    #define fan D5

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("start");
  pinMode(fan, OUTPUT);

  digitalWrite(fan, LOW);
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(1000);
  digitalWrite(fan, HIGH);

  delay(1000);
  digitalWrite(fan, LOW);
}


texts:
My Arduino IDE is not getting started. It just crashes before opening up. I don't know what the problem is. It was working well enough before without any issues.

This is what I see after running the arduino_debug.exe in the command line

Note: I added a library (DHT) to work with my humidity and temperature sensor and since after then, this issue comes up. I tried to reinstall it like more than 7 times, but the issue still persists.

Please help me with it. Thanks.


texts: Infared: some controllers send code into infinite loop

texts:
I have a piece of code that captures input from infrared and spits it out to the serial port.
When I use it with a simple controller that comes with a typical kit, it receives the infrared code just fine for each button I depress.
But when I try and capture information from my air conditioning remote (the one I need to clone), I receive the first hexcode and then the output gets thrown into an infinite loop with that 1 hexcode, and will not break out.
#include <IRremote.h>

const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  Serial.begin(115200);
  irrecv.enableIRIn();
  irrecv.blink13(true);
}

void loop(){
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume();
  }
}

What is causing the infinite loop from "some" controllers and how do I prevent it?
Update:
In changelog they say they renamed RAW_BUF to RAW_BUFFER_LENGTH. I find RAW_BUFFER_LENGTH in IRremoteInt.h and not IRremote.h
I'm not calling on IRremoteInt.h
I did try and reset the buffer from 101 to 201 in IRremoteInt.h, recompiled, uploaded, same issue.


texts: How to assign two or more variables incoming from app

texts:
I'm really new to Arduino and have some doubts about how Arduino reads data. Lets suppose I have 3 variables a,b,c. I need these variables in my Arduino to make whatever. Since all variables are read using Serial.read() how can I distinguish between them in my Arduino?

Example:

Variable a: 2
Variable b: 3
Variable c: 4

Arduino example code:

void loop() {
int a = Serial.read();
int b = Serial.read();
int c = Serial.read();

if(a == '0'){
digitalWrite(yellowLed, HIGH);
}

if(b == '0'){
digitalWrite(blueLed, HIGH);
}

if(c == '0'){
digitalWrite(redLed, HIGH);
}

In every loop, my Arduino does serial.read() 3 times, if I only send value b from my app, since int a = Serial.read() executes first, will my b value be assigned to a? If yes, how can I avoid that problem and force the correct assignment? Aditionally, in every loop, if Serial.read() doesnt read anything, will my values be changed to null or zero?


texts: Arduino uno + usb host shield: SPI test failing

texts:
I purchased a usb host shield that looks like a clone of the circuits@home shield (IE not a sparkfun shield) and am having the following error when I try to run board_qc from the usb host shield 2.0 library:
Circuits At Home 2011
USB Host Shield Quality Control Routine
Reading REVISION register... Die revision 01
SPI long test. Transfers 1MB of data. Each dot is 64K
Test failed. Value written: 01 read: 00
Unrecoverable error - test halted!!
0x55 pattern is transmitted via SPI
Press RESET to restart test

I don't quite understand the error and how it physically relates to the board (IE what component is bad if any). I checked all the soldering and that the capacitors are receiving power, I'm at a loss.


texts:
I am attempting to make an Arduino counter using a 4 digit 7 segment display. The problem I am encountering is the display flickers. I am using an Arduino Uno and 5641AS digit display (so common cathode). Here is my program:
#include "SevSeg.h"
SevSeg sevseg;

int buttonPress{}; // Variable used in Serial monitor, simulates button press to increment counter
void setup(){
  byte numDigits = 4;
  byte digitPins[] = {10, 11, 12, 13};
  byte segmentPins[] = {9, 2, 3, 5, 6, 8, 7, 4};

  bool resistorsOnSegments = true;

  bool updateWithDelays = false;
  byte hardwareConfig = COMMON_CATHODE;
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
  sevseg.setBrightness(90);
  Serial.begin(9600);
  sevseg.setNumber(0);
  sevseg.refreshDisplay();
}
void loop(){
  static int number = 0;

  if (Serial.available() > 0) { // Serial monitor input for buttonPress
    buttonPress = Serial.read();
  }
    Serial.println("The value of buttonPress is:  ");
    Serial.println(buttonPress);
    if (buttonPress == 10){ // Increment counter if buttonPress Serial monitor input = 10
    number += 15;
    buttonPress = 0;
    sevseg.setNumber(number); // Display the number on 4 digit 7 segment display
    }

    sevseg.refreshDisplay(); // Refresh display
}

I suspect this issue has to do with sevseg.refreshDisplay(), I have tried moving it in the program with no avail. My wiring is correct, as the program displays the correct digits. Thank you!


texts:
I have a situation where I need to select between two signals, lets say 1A or 2B and route it to output 3C. I need to do this six times (2A or 2B to output 2C, 3A or 3B to output 3C, etc.).

These all need to switch based on one output from my chip.

What sort of component do I need for this? I think it's something like a 2:1 spdt multiplexer, but something doesn't seem quite right.

I've been looking at a bunch of data sheets and I cannot seem to find a chip which switches many 2:1 switches based on ONE input. Does such a thing exists? Or am I just way of the mark here? Not sure.

Any help appreciated.

Thanks.


texts:
I am trying to make a group of LED dim with PWM to a MOSFET. The code seems to work for this, but the trouble is that the IR receiver will only receive the signal to turn on the lights and then IR receivers onboard LED goes to a permanent dim state (which is suppose to be off completely).  It then refuses to take input until a Arduino reset is preformed.  I purchased another IR receiver and placed it in the same configuration and it work exactly as intended I could brighten the LEDS and I saw the PWM stretch on my oscilloscope with every click of my remote.  The trouble is that the receiver quickly quit working at this point I think there is a problem with my circuit.  I am attaching the circuit diagram in hopes that someone can help.

Thanks,
Billa

#include <IRremote.h>

int led = 9;
int led2 = 10;
int brightness = 0;    // how bright the LED is
const int RECV_PIN = 7; //IR Receiver Pin
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  // declare pin 9 to be an output:
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
  Serial.begin(9600);
  irrecv.enableIRIn();

}

void loop() {

  analogWrite(led, brightness);
  analogWrite(led2, brightness);

  if(irrecv.decode(&results)) //this checks to see if a code has been received
{
    if(results.value == 0xFF906F) //if the button press equals the hex value 0xC284
    {
        Serial.println("Triggered U");
        brightness = brightness + 5;
    }

    if(results.value == 0xFFE01F) //if the button press equals the hex value 0xC284
    {
        Serial.println("Triggered D");
        brightness = brightness + 5;
    }

    irrecv.resume(); //receive the next value
}

  delay(100);
}


texts: Can you help me combining these sensor sketches as one in Arduino

texts:
I want to combine these three sketches into one.

RAIN SENSOR:

int rainPin = A0;
int greenLED = 6;
int redLED = 7;
// you can adjust the threshold value
int thresholdValue = 500;

void setup(){
  pinMode(rainPin, INPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);
  Serial.begin(9600);
}

void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(rainPin);
  Serial.print(sensorValue);

  if(sensorValue < thresholdValue){
    Serial.println(" - It's wet");
    digitalWrite(greenLED, LOW);
    digitalWrite(redLED, HIGH);
  }
  else {
    Serial.println(" - It's dry");
    digitalWrite(greenLED, HIGH);
    digitalWrite(redLED, LOW);
  }
  delay(500);
}

LIGHT SENSOR:

int ldrPin = A0;
int greenLED = 6;
int redLED = 7;
// you can adjust the threshold value
int thresholdValue = 500;

void setup(){
  pinMode(ldrPin, INPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);
  Serial.begin(9600);
}

void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(ldrPin);
  Serial.print(sensorValue);

  if(sensorValue < thresholdValue){
    Serial.println(" - light");
    digitalWrite(greenLED, LOW);
    digitalWrite(redLED, HIGH);
  }
  else {
    Serial.println(" - dark");
    digitalWrite(greenLED, HIGH);
    digitalWrite(redLED, LOW);
  }
  delay(500);
}

SMOKE SENSOR:

int smokeD0 = A5;
int greenLed = 11;
int redLed = 12;
// Your threshold value
int sensorThres = 300;

void setup() {
  pinMode(smokeD0, INPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(redLed, OUTPUT);
  digitalWrite(greenLed, LOW);
  digitalWrite(redLed, LOW);
  Serial.begin(9600);
}

void loop() {
  int analogSensor = analogRead(smokeD0);
  Serial.println(analogSensor);

  // Checks if it has reached the threshold value
  if (analogSensor < sensorThres)
  {
    Serial.println(" - Smoke");
    digitalWrite(redLed, LOW);
    digitalWrite(greenLed, HIGH);
  }
  else
  {
    Serial.println(" - No Smoke");
    digitalWrite(redLed, HIGH);
    digitalWrite(greenLed, LOW);
  }
  delay(100);
}

I want to combine those codes as one with only two outputs:

the greenLED and;
the redLED.


texts: make Arduino tell when the Python program stops reading from the Serial (crash, etc)

texts:
Here's the Arduino code:

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

  pinMode(7, INPUT_PULLUP);
}

void loop() {
    int val = digitalRead(7);
    if (val == HIGH) {
        Serial.print("1");
    } else {
        Serial.print("0");
    }
    Serial.println("");  // new line

}

Python code:

import time
import serial

# setup Arduino USB communication
try:
    arduinoSerialData = serial.Serial('com3', 9600)

except: # not connected/damaged
    pass

while True:
    if arduinoSerialData.inWaiting() > 0:
        datastr = arduinoSerialData.readline()
        print datastr
        time.sleep(1)

WHat I want to add is, if Python program exits, or crashes, let the Arduino know somehow. More specifically turn on a LED in pin 8.


texts: LCD prints weird characters when I place the print statement in setup after pinMode statements

texts:
#include "LiquidCrystal.h"

const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7)

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  pinMode(22, INPUT_PULLUP); // Reed switch - Row1
  pinMode(24, INPUT_PULLUP); // Reed switch - Row2
  pinMode(26, INPUT_PULLUP); // Reed switch - Row3
  pinMode(28, INPUT_PULLUP); // Reed switch - Row4
  pinMode(32, OUTPUT);
  digitalWrite(32, HIGH);
  lcd.setCursor(0, 0);
  lcd.print("hello");
}

When I run the above code I get weird characters in my LCD. I removed all the connections to the pins` defined in pinMode and left only the lcd connections but kept the pinMode and digitalWrite statements in the code, but am still getting weird characters. But when I remove the pinMode and digitalWrite statements from my code the lcd works fine. Can anyone help me out.

Edit:
Another weird thing happened, I removed all the pinMode and digitalWrite statements do my setup() had only Serial.begin() and lcd.begin() and I only had the lcd connections. Now I put this code to print into an function called lcdprintMove() and there were other functions too which were performing other tasks when I ran it as such I got weird characters in the LCD but when I removed all of the other functions,the lcd printed fine. From this I was able to conclude that this problem can't be because of the supply but has to be something else. But I still can't figure it out.

Problem Solved

Today I commented all the digitalWrite statements and uploaded the program and it worked! So,  I am going to connect the lcd onto a separate arduino and communicate serially. Someone suggested the solution of putting a cap to ground and buff the power of 5 v pin can you explain this in more detail.

Circuit diagram   Note: Rs is connected to pin 7 and E to 6


texts: Print with round towards zero instead of round to nearest

texts:
When printing with one decimal place, Arduino's Serial.println() rounds numbers like 123.89 to “123.9”. Is there any way to change the rounding mode? For some reasons I want the value to be rounded towards zero (i.e., truncated) to one decimal place, like 123.89 → “123.8”.

here is the code

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

}

void loop()
{
float A = analogRead(A0);
A = (A/1023)*5.0;
Serial.print("A = ");
Serial.println(A,3);
float B = A*10;
Serial.print("A * 10 = ");
Serial.println(B,1);
delay(1000);
}

the output is

A = 2.473
A * 10 = 24.7
A = 2.488
A * 10 = 24.9
A = 2.517
A * 10 = 25.2
A = 2.527
A * 10 = 25.3
A = 2.507
A * 10 = 25.1

instead I want the output to be like this

A = 2.473
A * 10 = 24.7
A = 2.488
A * 10 = 24.8
A = 2.517
A * 10 = 25.1
A = 2.527
A * 10 = 25.2
A = 2.507
A * 10 = 25.0

is it possible ?


texts:
I've got an ESP8266 that takes instructions from a web page and sets a series of NeoPixels to flash in different sequences.

I noticed that when the Wi-Fi got data and parsed it, my LEDs would "stutter" as the processor ignored them for a moment while processing the incoming instructions.

So I added a 2nd ESP8266. This one just handles the LEDs. So the 1st ESP gets the Wi-Fi data and parses it. It then sends an interrupt to the 2nd ESP which breaks out of the LED display loop, checks the interrupt pin for HIGH or LOW and sets the LEDS based on HIGH/LOW.

However, I would like to send more data from the Wi-Fi ESP to the LED driving ESP. e.g. Colour data, transition speed, rotation direction etc. All of these settings I can send to the ESP from a web page.

I thought I2C (the wire library) would help but all comments seem to say that the ESP8266 cannot act as a slave so I can't send to it.

So it appears I'm left with Serial comms (the interrupt is over by the time comm start because I realize Serial does not work in an interrupt).

So my questions are:

Am I right that I2C will not work?
If I am wrong does anyone have a working end to end example?
If I am right is there an approved way to do ESP to ESP serial comms?


texts: Programmatically Upload Arduino Sketch From Android App

texts:
I am attempting to build an Android app from which I can can upload a .hex file to my Arduino(Leonardo). I am aware of a few apps in the Google Play store that are capable of this functionality but I can't seem to find any actionable resources on how to go about doing this. I am aware that the desktop Arduino IDE uses AVRDude to perform the upload but I don't believe AVRDude is available on Android so I'm at a complete loss here. Does anyone know how I would go about accomplishing this?

After some more searching I now know that the Leonardo(ATMega32u4) uses the AVR109 Protocol to flash new programs onto the hardware but I'm still at a complete loss as to what that process is and how I'd reproduce it in Java.


texts: How to power Arduino and shields with 4 rechargeable AA batteries?

texts:
To start, I am a software guy, and I really want to ensure I not going to destroy any components. I previously looked at power through a USB power bank, but the issue with these is that they turn themselves off with low current pull.

My question is: I have a number of Arduino shields and would like to power them with 4 rechargeable AA batteries, and therefore would like some advice on what to use without frying any electronics.

The rechargeable batteries I have are these 1.2V AA (NiMH). Going on their rated value they should supply 4.8V. Testing the 4 batteries in serial gives me 5.3V overall, or around 1.325V per battery at full charge.

So if the batteries provide more than 5V, I cannot safely plug them into the 5V pin on the Arduino. But if the batteries could potentially provide around 4.8V to 5.5V plugging them into VIN means that the voltage regulator will take too much power, reducing the overall voltage to be too low for all of the shields (Which require 5V). What should I do in this situation?

This is a list of the current equipment that will require power:

Arduino Mega 2560
SIM900 GPRS/GSM Shield
Sparkfun GPS Logger Shield
Sparkfun Wifi Shield - ESP8266

The shields will be stacked on top of each other.


texts:
I am trying to control an actuator carrying a carriage made from stepper motor. My problem is that after the carriage reach certain height, I want it to delay for several minutes and change direction to move the other way around.

Any suggestion on what sensor to use? I tried to use EndStop switch like the one in 3D printer but I haven't found any luck as it simply cuts the electronic connections once the carriage hits it.


texts: Arduino serial communication synchronisation

texts:
i am trying to send data via Labview to my arduino board using serial communication.My problem is that the arduino reads only the first byte of sent data then when i change it ,it doesn't react.
For example when i start the communication i send '0' to arduino.I sees it.but while it is running i send '1' but it doesn't behave accordingly to it.
I noticed also that the board 'sees' sometime the new value after a random period of time.

void setup()
{
    Serial.begin(9600);
    pinMode(13, OUTPUT);
}

char data = 'F';

void loop()
{
    data = Serial.read();
    delay(50);

    if (data == '0')
    {
        digitalWrite(13, HIGH);
        delay(1000);
        digitalWrite(13, LOW);
        delay(1000);
    }
    if (data == '1')
    {
        digitalWrite(13, HIGH);
        delay(4000);
        digitalWrite(13, LOW);
        delay(4000);
    }

    data = '4';
}


texts: Why does an Arduino Uno have 2 microcontrollers

texts:
I was looking at this schematic:

And I noticed that there are 2 microcontrollers (an Atmega328p and a ATmega16U2).  I was wondering why there need to be 2 microcontrollers.  Do they do different things that only 1 of them can do and the other can't ?


texts: Temperature Controlled fan using arduino project regarding - LCD not displaying anything

texts:
I have connected the circuit as per the diagram below and I have got the LCD to display boxes and nothing else. What could be wrong here? Please help!

Circuit diagram below -

Code as follows -

#include<DHT11.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
#define dht11pin 12
dht11 DHT11;
#define pwm 9
byte degree[8] =
{
  0b00011,
  0b00011,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};
void setup()
{
  lcd.begin(16, 2);
  lcd.createChar(1, degree);
  lcd.clear();
  lcd.print("   Fan Speed  ");
  lcd.setCursor(0, 1);
  lcd.print("  Controlling ");
  delay(2000);
  analogWrite(pwm, 255);
  lcd.clear();
  lcd.print("Our Project ");
  delay(2000);
}

void loop()
{
  DHT11.read(dht11pin);
  int temp = DHT11.temperature;
  lcd.setCursor(0, 0);
  lcd.print("Temperature:");
  lcd.print(temp);
  lcd.write(1);
  lcd.print("C");
  lcd.setCursor(0, 1);
  if (temp < 26 )
  {
    analogWrite(9, 0);
    lcd.print("Fan OFF  ");
    delay(100);
  }
  else if (temp == 26)
  {
    analogWrite(pwm, 51);
    lcd.print("Fan Speed: 20%   ");
    delay(100);
  }
  else if (temp == 27)
  {
    analogWrite(pwm, 102);
    lcd.print("Fan Speed: 40%   ");
    delay(100);
  }
  else if (temp == 28)
  {
    analogWrite(pwm, 153);
    lcd.print("Fan Speed: 60%   ");
    delay(100);
  }
  else if (temp == 29)
  {
    analogWrite(pwm, 204);
    lcd.print("Fan Speed: 80%    ");
    delay(100);
  }
  else if (temp > 29)
  {
    analogWrite(pwm, 255);
    lcd.print("Fan Speed: 100%   ");
    delay(100);
  }
  delay(3000);
}

I used the default LiquidCrystal.h library for this project. Is that wrong?


texts:
I'm stuck in my project, I try to read an absolute encoders angular position with my Arduino.
I used and cabled a differential line receiver and driver between Arduino and the encoder, like explained in the 2 following links:

Figure 2.1 here
Input circuitry of subsequent electronics

Here are the specifications of the encoder that I try to read.

Here is my Arduino code :

const int CLOCK_PIN = 5;
const int DATA_PIN = 6;
const int BIT_COUNT = 25;

void setup() {
  //setup our pins
  pinMode(DATA_PIN, INPUT);
  pinMode(CLOCK_PIN, OUTPUT);

  //give some default values
  digitalWrite(CLOCK_PIN, HIGH);

  Serial.begin(115200);
}

void loop() {
  float reading = readPosition();

  if (reading >= -0.5) {
      //Serial.print("Reading: ");
      //Serial.println(reading,2);
  }

  delay(200);
}

//read the current angular position
float readPosition() {
  unsigned long sample1 = shiftIn(DATA_PIN, CLOCK_PIN, BIT_COUNT);
  unsigned long sample2 = graytobin(sample1, BIT_COUNT);
  delayMicroseconds(25);  // Clock mus be high for 20 microseconds before a new sample can be taken

  Serial.print("grey: ");
  Serial.println(sample1, BIN);
  Serial.print("binary: ");
  Serial.println(sample2, BIN);
  Serial.print("decimal: ");
  Serial.println(sample2 & 0x0FFF);
  Serial.print("\n");

  return ((sample2 & 0x0FFF) * 360UL) / 4096.0;
}

// gray to binary
int graytobin(int grayVal, int nbits ) {
  int binVal = 0;
  bitWrite(binVal, nbits - 1, bitRead(grayVal, nbits - 1)); // MSB stays the same
  for (int b = nbits - 1; b > 0; b-- ) {
    // XOR bits
    if (bitRead(binVal, b) == bitRead(grayVal, b - 1)) { // binary bit and gray bit-1 the same
      bitWrite(binVal, b - 1, 0);
    }
    else {
      bitWrite(binVal, b - 1, 1);
    }
  }
  return binVal;
}

//read in a byte of data from the digital input of the board.
unsigned long shiftIn(const int data_pin, const int clock_pin, const int bit_count) {
  unsigned long data = 0;

  for (int i=0; i<BIT_COUNT; i++) {
    data <<= 1;
    digitalWrite(clock_pin,LOW);
    delayMicroseconds(1);
    digitalWrite(clock_pin,HIGH);
    delayMicroseconds(1);

    data |= digitalRead(data_pin);

  }

  return data;
}

I'm still able to receive information with my Arduino from the encoder but they are totally random. Here is an example of the output I get (I didn't move the encoder during this exercition):

grey: 1001111101110100011111001
binary: 11111111111111111011000010101110
decimal: 174

grey: 111110110010001111100111
binary: 11110101000101
decimal: 3397

grey: 0
binary: 0
decimal: 0

grey: 0
binary: 0
decimal: 0

grey: 0
binary: 0
decimal: 0

grey: 0
binary: 0
decimal: 0

grey: 1111111111111111111111111
binary: 11111111111111111010101010101010
decimal: 2730

grey: 1011001110011011100010001
binary: 10010111100001
decimal: 1505

grey: 1100111011011100100011111
binary: 11111111111111111101000111101010
decimal: 490

grey: 1101110110111001000111111
binary: 101110000101010
decimal: 3114

grey: 0
binary: 0
decimal: 0

grey: 0
binary: 0
decimal: 0

grey: 0
binary: 0
decimal: 0

grey: 0
binary: 0
decimal: 0

grey: 111111
binary: 101010
decimal: 42

grey: 111011011100100011100111
binary: 11111111111111111000111101000101
decimal: 3909

grey: 1100111001101110010001111
binary: 11111111111111111001011100001010
decimal: 1802

grey: 1100111011011100100011111
binary: 11111111111111111101000111101010
decimal: 490

grey: 0
binary: 0
decimal: 0

grey: 0
binary: 0
decimal: 0

grey: 0
binary: 0
decimal: 0

grey: 0
binary: 0
decimal: 0

I don't know how to diagnose the problem, and how to find it.


texts:
I am tracking down the memory usage of an Arduino-like project I am working on (not a real Arduino, but has same microcontroller and it uses the Arduino build environment, version 1.6.8). I have some modules that I am using and placed them in the Libraries directory in my sketch directory:

Encoder
LiquidCrystal
OneWire
TGPages
TGPro

Now, when I compile a minimal sketch...

#include <Arduino.h>

void setup()
{
}

void loop()
{
}

...the compiled size is 450 bytes Flash and 9 bytes RAM. So far, so good.

Now here's the weird part: when I include a single header file from anywhere in the Libaries folder, the compiled size increases dramatically.

#include <Arduino.h>
#include "pins.h"

void setup()
{
}

void loop()
{
}

"pins.h" is located in the TGPro directory and only contains #defines, not even code or other includes.

....
Using library TGPro in folder: C:\Users\User\Project\TG\libraries\TGPro (legacy)
Using library OneWire in folder: C:\Users\User\Project\TG\libraries\OneWire (legacy)
Using library Encoder in folder: C:\Users\User\Project\TG\libraries\Encoder (legacy)
Using library LiquidCrystal in folder: C:\Users\User\Project\TG\libraries\LiquidCrystal (legacy)
Using library EEPROM at version 2.0 in folder: C:\Users\User\Project\TG\hardware\arduino\avr\libraries\EEPROM
Using library Wire at version 1.0 in folder: C:\Users\User\Project\TG\hardware\arduino\avr\libraries\Wire

Sketch uses 2,266 bytes (7%) of program storage space. Maximum is 32,256 bytes.
Global variables use 230 bytes (11%) of dynamic memory, leaving 1,818 bytes for local variables. Maximum is 2,048 bytes.

And I'm like: WTF? I'm not even referencing any of the files, still they get pulled in, wasting space. There are a few global, static variables in there which explain the used space and referenced code.

So, my questions:

Is het normal for Arduino to pull in all files in the Sketch\Libraries directory, regardless if they are referenced or not? It doesn't seem to do this with the 'core' libraries.
How can you prevent this? Suppose I have a large collection of modules that I use in various projects, but not all modules are used all the time. It would be a waste to include code that is never actually used.
How can I find out more about the code that is compiled in; I know the linker will leave out unreferenced code, but I want to make sure this is due to the statically defined variables.


texts:
Is there a sensor I could use which would let me know which direction an object is heading/facing? i.e. I have a servo that can rotate 0 to 180 degrees, and I have another sensor on a block. When I turn the block 45 degrees, I want the servo to also turn 45 degrees - I thought I could do this with a compass, but the varying magnetic fields make it impossible. Gyro/acc maybe? Except I don't know how to use that to solve this problem.

So in other words we need to know the block was rotated 45 degrees using a sensor on the block, which tells the servo to rotate 45 degrees.


texts: Why isn't my Arduino Nano Every recognized as a Nano Every and why won't it upload sketch?

texts:
I have a genuine Arduino Nano Every board that isn't showing up quite right.  I actually have 2 hooked up to the computer on different ports and one of them, when I click on 'Port' shows as:
COM12 (Arduino Nano Every)

But the other one just shows up as:
COM18

The COM18 device used to have (Arduino Nano Every), but doesn't anymore.  The other problem I have is that when I try to upload a sketch to the device, it compiles and gets to uploading and then has a bunch of errors:
avrdude: jtagmkII_getsync(): sign-on command: status -1
avrdude: jtagmkII_getsync(): sign-on command: status -1
avrdude: jtagmkII_getsync(): sign-on command: status -1
An error occurred while uploading the sketch

I've tried changing the selection on "Registers emulation:" between ATMEGO328 and None (ATMEGA4809) but I get the same errors whenever I try to upload a sketch.  Is my Every bricked?  Or is there some way to revive it?
I'm not sure why this happened.  I was able to upload sketches before, and have barely even used this device.
Does somebody have any ideas on how to get this working again, or should I just throw it away and get another one?


texts:
This is my code. I am tring to make a connection to my wifi through esp8266.

#define DST_IP "192.168.1.5" // my IP
#include <SoftwareSerial.h>

SoftwareSerial mySerial(0, 1);

void setup()
{
  Serial.begin(115200);
  mySerial.begin(115200);
  while (! Serial); // Wait until Serial is ready - Leonardo
  Serial.println("AT+RST");
  delay(4000);
  Serial.println("AT+CWJAP=\"Ahmed\",\"12341234Aass\"");
  delay(4000);
  if (Serial.find("OK") )
  {
    Serial.println("1");
  }
  else
  {
    Serial.println("0");
  }
}

void loop()
{

}

This is the result of my code.


texts: Is there any limitation with Arduino Nano serial communication distance?

texts:
I am trying to build Project which communicate multiple Arduino Nanos. I wanted to understand if Arudino Nano is capable of doing that, while doing research I came across post where it says communication with nano can be done up to 2-3 meter, where as my goal is up to 30 meter.

Project - I am trying intercom system, I have 4 Ring button at main gate, when user press any one of those 4 the Arduino will understand it and send to one of the 4 Arduino sitting at other place. Each Arduino will read that message if its for them they will perform activity if not they will skip it.

My problem is I am in selection mode and want know if Arduino Nano can handle that, communication is not that complex. It will be just sending 2/3 value max during communication. As I saw post of distance limitation, I just want get inputs from community. If you have any similar examples of serial communication between multiple Arduino Nano please let me know, I found several but it might save my time if I find something more similar.


texts: How to convert four uint16_t to double float IEEE754?

texts: I am working in a Modbus project where I have to read modbus Holding and Input registers using ESP8266, I am using ModbusMaster232 library. I returns a response buffer array of uint16_t. I need to convert the uint16_t to double precision float. A quick test in ESP8266 shows double datatype in ESP8266 stores 8 bytes.Does anybody know how to convert four uint16_t to double in Arduino. If so please share your knowledge.


texts:
I have made a custom board based on the Arduino Due but have some problems with the Serial communication with the 16u2 chip.

i have usb connection with the 16u2 chip and was able to load the arduino-due usb serial hex over the usb port. the usb now shows up as arduino com port. now when i try to load a sketch it says No device found on COM12. the SAM chip is erased but it can't load the new sketch.

now when i load a sketch with a simple serial print at 115200 over the native port. the SAM chip is programmed correctly. when i open the serial monitor i receive data but it is garbage! the garbage is always different. the sketch is at 115200 and the monitor also at 115200.

this would explain why it can't upload a sketch with the 16u2.

the same sketch on a original arduino due works fine.

the transmit an receive led are blinking.

What would cause this garbage in the connection where do i start looking?


texts: error 404 in HTTP GET request with Arduino Uno and ESP8266 using AT commands

texts:
when I try to send http get request I get error 404

AT+CIPMTX=1

OK
AT+CIPSTART=4,"TCP","alirezaabrhshami.ir",80
4,CONNECT
OK
AT⸮⸮R5U9⸮⸮b⸮⸮j
OK
>
Recv 47 qytes
SEND OK
+IPD,4,223;HTTP/1.1 404 Not Found
Cache-Contsol: public, max-age=0:a1n CeK⸮

this is my code:

#include <SoftwareSerial.h>

const byte rxPin = 2;
const byte txPin = 3;
SoftwareSerial ESP8266 (rxPin, txPin);

unsigned long lastTimeMillis = 0;

void setup() {
  Serial.begin(9600);
  ESP8266.begin(115200);
  delay(2000);
}

void printResponse() {
  while (ESP8266.available()) {
    Serial.println(ESP8266.readStringUntil('\n'));
  }
}

void loop() {

  if (millis() - lastTimeMillis > 30000) {
    lastTimeMillis = millis();

    ESP8266.println("AT+CIPMUX=1");
delay(1000);
printResponse();

ESP8266.println("AT+CIPSTART=4,\"TCP\",\"alirezaabrishami.ir\",80");
delay(1000);
printResponse();

String cmd = "GET /greencare/login.php?product_id=123456 ";
ESP8266.println("AT+CIPSEND=4," + String(cmd.length() + 4));
delay(1000);

ESP8266.println(cmd);
delay(1000);
ESP8266.println("");
  }

  if (ESP8266.available()) {
    Serial.write(ESP8266.read());
  }

}


texts: Serial structure data transfer between an Arduino and a Linux PC

texts:
I use the Arduino compatible chipKIT WF32 board. I want to transfer structure data between my board and a Linux PC. Can I do it like the following?

struct data d;
char *tx = (char*)d;
Serial.print(tx);

Even if the above code works, the data type size in Arduino and on Linux will vary. Is there a way to serialize the data, like Protocol Buffers on Arduino?


texts: Arduino randomly freezes during runtime?

texts:
I'm currently trying to create a traffic simulation project on Arduino, where it can change lights, open a gate, and turn on street lamps based on light. If anybody could help me diagnose why my arduino is behaving this way, that'd be extremely appreciated. Here is my code, if it helps you understand.

//Libraries Used
#include<Servo.h>

//Variable Declaration
int red1 = 10;
int yellow1 = 9;
int green1 = 8;
int red2 = 13;
int yellow2 = 12;
int green2 = 11;
int debug = 3;
int PIR = 5;

int button1 = 2;
int buttonState = 0;

int light = 0;

unsigned long previousTime = 0;
unsigned long currentTime = 0;
int currentState = 0;

int currentPIR = 0;
int pirState = LOW;

Servo servo;

void setup()
{
  pinMode(red1, OUTPUT);
  pinMode(yellow1, OUTPUT);
  pinMode(green1, OUTPUT);
  pinMode(red2, OUTPUT);
  pinMode(yellow2, OUTPUT);
  pinMode(green2, OUTPUT);
  pinMode(debug, OUTPUT);

  pinMode(PIR, INPUT);

  pinMode(button1, INPUT);

  servo.attach(4);
  servo.write(90);
}

void loop()
{

  currentPIR = digitalRead(PIR);
  if(currentPIR == 1){
    servo.write(180);
  }else{
    servo.write(90);
  }

  buttonState = digitalRead(2);
  light = analogRead(A0);

  if(light > 100){
    digitalWrite(debug, HIGH);
  }else{
    digitalWrite(debug, LOW);
  }

  if(buttonState == HIGH){
    if(currentState == 3){
      digitalWrite(debug, HIGH);
      currentState++;
    }
  }
  //Using millis() instead of delay(), so program doesn't pause completely.
  currentTime = millis();
  changeLights();
}

void changeLights(){
  if(currentState == 0){
    //Red, Green
    digitalWrite(red2, LOW);
    digitalWrite(red1, HIGH);
    digitalWrite(green2, HIGH);
    asyncDelay(4000);
  }
  else if(currentState == 1){
    //Red, Yellow
    digitalWrite(green2, LOW);
    digitalWrite(yellow2, HIGH);
    asyncDelay(2000);
  }
  else if(currentState == 2){
    //Red, Red
    digitalWrite(yellow2, LOW);
    digitalWrite(red2, HIGH);
    asyncDelay(750);
  }
  else if(currentState == 3){
    //Green, Red
    digitalWrite(red1, LOW);
    digitalWrite(green1, HIGH);
    asyncDelay(4000);
  }
  else if(currentState == 4){
    //Yellow, Red
    digitalWrite(green1, LOW);
    digitalWrite(yellow1, HIGH);
    asyncDelay(2000);
  }
  else if(currentState == 5){
    //Red, Red
    digitalWrite(yellow1, LOW);
    digitalWrite(red2, HIGH);
    asyncDelay(750);
  }
}

void asyncDelay(int delayTime){
  if(currentTime - previousTime == delayTime){
    currentState++;
    previousTime = currentTime;
    if(currentState == 6){
      currentState = 0;
    }
  }
}


texts: Do AVR delay functions (_delay_us() and _delay_ms()) use timers?

texts:
I'm trying to determine if the AVR delay functions _delay_us() and _delay_ms() use timers in such a way that I can't use those timers for other functionality in my code. If so, what timer does it use?

For reference I'm using an Arduino Uno with ATmega328, but I imagine if it's an AVR function it must work similarly on other devices.


texts: ESP8266 HTTPS post body request with WifiClientSecure

texts:
Is there a way to post HTTPS body request in Arduino esp8266.
I am able to HTTPS parameter request with WifiClientSecure library,but is not safe compared to Request Body send in POST.


texts: How can I clear the memory of my Arduino in this case?

texts:
I have made a code using involving HID control. But it seems that I messed up, but I can't upload a new sketch(nor edit the wrong code), because my Arduino is constantly doing things like Ctrl+Alt+Delete, Alt+F4... etc.
It seems that the only way is erasing the code in the memory, but how can I do so?


texts: NodeMCU successfully uploaded sketch but it does not work from Arduino IDE

texts: NodeMCU successfully compiled and uploaded a simple blink sketch on board, no errors at all, but the LED stays on constantly and does not blink. Also I have checked the power is enough. I have checked this with all pins but the red LED only stays on and doesn't blink. I have no idea what could have gone wrong. And how to fix this?


texts: Using Arduino Uno as USB to serial converter

texts:
Can I use my Arduino Uno as a USB to serial converter to program my Raspberry pi 0 over serial communication?

My idea: Computer connects to Arduino via USB > Arduino connects with Raspberry pi 0 via GPIO pins.

How do I go about this?


texts: Possible impedance problem when moving to new power supply

texts:
I'm working on building an LED matrix and I'm using an LED strip to create it. I've worked through a simple wiring setup using my bench top power supply and got a strip test working.
Now that I have the actual fabrication done I want to move the power from my bench top supply to a regular wall adapter supply.
The problem I'm running into is that when I provide power from the wall supply the led strip no longer gets the data from the signal pin.While troubleshooting I connected my multimeter to the signal pin and all of a sudden the strip's first LED got the signals and started lighting up.
I'm assuming I'm running into an impedance issue, but I'm not sure why or how to solve it other than trying different resistor values on the signal pin to overcome the issue.
Here's a rough diagram. there's not a lot to it:

I couldn't find info on the forward voltage of the strip or a datasheet for it, so I turned all of the LEDs white and looked at the current draw on my bench top supply:

So the whole matrix is pulling 1.5 amps.
The trinket M0's GPIO voltage is 3.3v, so if I'm thinking about this right to figure out the resistor I need I would use ohms law:
r = V/I

So in my case:
r = 3.3/1.5 = 2.2ohm

Is that right? While I know some I still feel like a novice and I'm working alone and teaching myself, so I'm not sure if I'm thinking of everything correctly.
I also shot a video showing what's happening if that helps: https://vimeo.com/496062949
UPDATE
And actually to simplify things further, I just tried moving the trinket over to the external power supply as well and I get the same issue.
So even with this diagram:

Update
A closer look at the all-on-the-wall-adapter circuit:


texts:
I've following code:

char a[5] = "bang";
char b[5] = "";
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
  if (a != b){
  for(int i=0; i<4; i++){
      b[i] = a[i];
    }
    Serial.print("b: ");
    Serial.println(b);
    Serial.println("Not Equal");
    delay(1000);
  }
  else{
    delay(1000);
  }

}

Why the output is:

b: bang
Not Equal
b: bang
Not Equal
b: bang
Not Equal

Shouldn't a and b equal after first loop?


texts: Arduino and AVR Serial Communication over USB

texts:
I have a Arduino Uno Rev3 and I would like to use a AVR development toolchain to write a program that performs serial communication over USB.

Doing this using the Arduino IDE is fairly simple:

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

void loop() {
   int i;
   while(1) {
      Serial.write("hello\n");
      delay(5000);
   }
}

Then from Linux, I can simply read from /dev/ttyACM0 and every 5 seconds I get "hello\n".

I found a blog post titled Simple Serial Communications With AVR libc that explains how to perform serial communication using an AVR development toolchain. The simplified version of the above Arduino sketch is below.

#ifndef F_CPU
#define F_CPU 8000000UL
#endif

#ifndef BAUD
#define BAUD 9600
#endif

#include <stdio.h>
#include <avr/io.h>
#include <util/delay.h>
#include <util/setbaud.h>

void uart_init() {
    // Upper and lower bytes of the calculated prescaler value for baud.
    UBRR0H = UBRRH_VALUE;
    UBRR0L = UBRRL_VALUE;

    // Configure data frame size to 8-bits.
    UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);

    // Configure to enable transmitter.
    UCSR0B = _BV(TXEN0);
}

void uart_putchar(char c) {
    // Wait until the register to write to is free.
    loop_until_bit_is_set(UCSR0A, UDRE0);

    // Write the byte to the register.
    UDR0 = c;
}

void uart_putstr(char *data) {
    // Loop until end of string writing char by char.
    while(*data){
      uart_putchar(*data++);
    }
}

int main() {
    uart_init();

    while(1) {
        uart_putstr("hello\n");
        _delay_ms(5000);
    }

    return 0;
}

The problem is, this doesn't actually work. I can build and flash the ATmega328p but reads to /dev/ttyACM0 block forever. I suspect what is happening is that the serial communication is occurring on some pins and not over USB, but I am not sure.

Anyone have any idea on how I can emulate Serial.write using an AVR development toolchain and have the output be written over USB?


texts: Can I use TCS34725 Color Sensor with Lilypad?

texts:
I have been trying to get TCS34725 color sensor working with LilyPad Arduino USB - ATmega32U4 Board but with no success. I am wondering if it possible? I have been using the following Sketch to try and get a reading but nothing appears in the monitor:

#include <Wire.h>
#include "Adafruit_TCS34725.h"

/* Example code for the Adafruit TCS34725 breakout library */

/* Connect SCL    to analog 5
   Connect SDA    to analog 4
   Connect VDD    to 3.3V DC
   Connect GROUND to common ground */

/* Initialise with default values (int time = 2.4ms, gain = 1x) */
// Adafruit_TCS34725 tcs = Adafruit_TCS34725();

/* Initialise with specific int time and gain values */
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);

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

  if (tcs.begin()) {
    Serial.println("Found sensor");
  } else {
    Serial.println("No TCS34725 found ... check your connections");
    while (1);
  }

  // Now we're ready to get readings!
}

void loop(void) {
  uint16_t r, g, b, c, colorTemp, lux;

  tcs.getRawData(&r, &g, &b, &c);
  // colorTemp = tcs.calculateColorTemperature(r, g, b);
  colorTemp = tcs.calculateColorTemperature_dn40(r, g, b, c);
  lux = tcs.calculateLux(r, g, b);

  Serial.print("Color Temp: "); Serial.print(colorTemp, DEC); Serial.print(" K - ");
  Serial.print("Lux: "); Serial.print(lux, DEC); Serial.print(" - ");
  Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
  Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
  Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
  Serial.print("C: "); Serial.print(c, DEC); Serial.print(" ");
  Serial.println(" ");
}


texts: Arduino thermometer and humidity display with 7 segment LED display

texts:
I want to use an Arduino Uno, a seven segment LED display (four digits) and the SevSeg library, to see temperature and humidity (alternatively).

First of all I try this code:

  #define COMMON_ANODE 1
  #define COMMON_CATODE 0
  #include "DHT.h"
  #define DHTPIN A5     // pin analogico che legge i dati
  #define DHTTYPE DHT22   // DHT 22  (AM2302)
  #include "SevSeg.h"

  // Crea un'istanza dell'oggetto
  SevSeg sevseg;
  DHT dht(DHTPIN, DHTTYPE);
  unsigned long timer; // the timer
  unsigned long INTERVAL = 5000; // the repeat interval (30 seconds)

  int segA = 6;   // Undicesimo PIN del display 7Segment x 4
  int segB = 2;   // Settimo PIN del display 7Segment x 4
  int segC = 10;  // Quarto PIN del display 7Segment x 4
  int segD = 12;  // Secondo PIN del display 7Segment x 4
  int segE = 13;  // Primo PIN del display 7Segment x 4
  int segF = 5;   // Decimo PIN del display 7Segment x 4
  int segG = 9;   // Quinto PIN del display 7Segment x 4
  int segDP = 11; // Terzo PIN del display 7Segment x 4

  int digit1 = 7; // Dodicesimo PIN - PWM che Accende il primo digit
  int digit2 = 4; // Nono PIN - PWM che Accende il secondo digit
  int digit3 = 3; // Ottavo PIN - PWM che Accende il terzo digit
  int digit4 = 8; // Sesto PIN - PWM che Accende il quarto digit

  void setup()
  {
    dht.begin();
    int numberOfDigits = 4; //Numero di cifre del display

    // Inizializzo i PIN
    sevseg.Begin(COMMON_CATODE,digit1,digit2,digit3,digit4,segA,segB,segC,segD,segE,segF,segG,segDP);
    // Imposto la luminosità (valore da 0 a 100)
    sevseg.Brightness(90);
    timer = millis(); // start timer
  }

  void loop()
  {
    if ((millis()-timer) > INTERVAL) {
      // Reset the timer and get/display the current temperature
      timer += INTERVAL;
      // Leggo dal sensore la temperatura
      float t = dht.readTemperature();
      float h = dht.readHumidity();
      //La converto in un numero intero a 4 cifre
      int a=t*100;
      sevseg.NewNum(a,2);
    }
        sevseg.PrintOutput();
  }

And it works very well!

But I cant see temperature (first) AND humidity (after) and again temperature (first) AND humidity (after)...

I have tried many ways but... nothing!! Can you help me?


texts: Major difference between DTR signal and RTS signal?

texts:
I actually had a doubt about what is the difference between the RTS signal and DTR signal ?
I already know this that the DTR signal is used to auto reset when we use Arduino and similar MCUs. Can anyone say what is the major difference between these signals and what is their active state ?


texts: Can't manually connect HC-05 master to slave

texts:
Using this as a tutorial, I've tried to connect the master Bluetooth module from my Nano to the slave module in my Mega. After following the steps in the tutorial, when I enter the command to my serial monitor:

AT+BIND=98d3,31,30690

I receive:

ERROR:(7)

After looking up the error, I only get results for ERROR:(0)

Does anyone know what the error means or how to fix it?


texts:
I have an Arduino Uno project which is recording student attendance using fingerprint sensor. So when sensor found a match, the serial monitor will be printing out Student ID and current time like this:

    DateTime now;
    void setup()
      {
          ...
      }

    void loop()
      {
          .....
          //found a match
          Serial.print("Found ID #");
          Serial.println(finger.fingerID);
          Serial.print("Time->");
          Serial.print(now.hour(), DEC);
          Serial.print(':');
          Serial.print(now.minute(), DEC);
          Serial.print(':');
          Serial.print(now.second(), DEC);
      }

Sample result will be:

Found ID#1
Time-> 18:11:54

I would like to store the time into a variable and print it out instead of printing hour, minute, second separately. How can I do that???

I have tried to do like this as below but im getting error, I would like to store it as a string. How can I do that?

string time = now.hour() + ':' + now.minute() + ':' + now.second();


texts: I/O expander with i2c interface vs Multiplexer

texts:
I am wondering where are the difference in between using something like:
CD4067, which selects which pins to read/write from by "selecting" an address with 4 pins by writing to it. Versus the MCP23017 which uses the i2c interface.

I am trying to learn and build a simple application with lots of digital inputs and outputs, and need something that is fast at switching the pins and reading/writing to it.


texts: How to use Atmega1284AU with Arduino IDE

texts:
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


texts:
I wan't to build a diversity controller similar to this one.

  A diversity controller is basically a circuit which detects the strongest RSSI Signal of multiple receivers and provides the data signal of that (the strongest) receiver.

As a receiver I use boscam RX5808 receivers.

This receiver can be switchen between 8 channals through a 3 bit output interface. The CH1-3 outputs are active high 5V which got to be pulled to ground.

Is it possible to put these receiver-outputs on an arduino digital inputs, to either put them on ground or not?

How exactly do I implement this in software?


texts: Control 2 ESC with a potentiometer with arduino

texts:
I have 2 ESC (electronic speed controller) which control these brushless motors: Hobbyking Donkey ST3511 Brushless Motor

I would like to make them work with a poentiometer, under arduino.

I have a program but it only works with one engine. Here is the program :

#include <Servo.h>//Using servo library to control ESC

Servo esc;
Servo esc2;
//Creating a servo class with name as esc

void setup()

{

esc.attach(9); //Specify the esc signal pin,Here as D8

esc.writeMicroseconds(1000); //initialize the signal to 1000

Serial.begin(9600);

esc2.attach(9); //Specify the esc signal pin,Here as D8

esc2.writeMicroseconds(1000); //initialize the signal to 1000

Serial.begin(9600);

}

void loop()

{

int val; //Creating a variable val

val= analogRead(A0); //Read input from analog pin a0 and store in val

val= map(val, 0, 1023,1000,2000); //mapping val to minimum and maximum(Change if needed)

esc.writeMicroseconds(val); //using val as the signal to esc
esc2.writeMicroseconds(val);
}

I did not find help on the internet, thank you in advance.


texts: Arduino loop over a function is always displaying 0 as final values

texts:
I trying to loop over a function in arduino to get values for 2000 times, and then divide it by 2000 to get an average offset:

int16_t x_offset = 0;
int16_t y_offset = 0;
int16_t z_offset = 0;

And inside setup():

for(int i=0; i<2000;i++)
  {
    GetXYZ(x_offset, y_offset, z_offset);
    x_offset += x_offset;
    y_offset += y_offset;
    z_offset += z_offset;
    Serial.println(x_offset);
    delay(3);
  }
  x_offset /= 2000;
  y_offset /= 2000;
  z_offset /= 2000;
  Serial.println(x_offset);Serial.println("...");Serial.println(y_offset);Serial.println("...");
Serial.println(z_offset);Serial.println("...");

Here is the GetXYZ() function:

void GetXYZ( int16_t &x, int16_t &y, int16_t &z) {
  // Get the gyro values
  Wire.beginTransmission(MPU);
  Wire.write(0x43);     // first register of gyro values
  Wire.endTransmission(false);

  Wire.requestFrom(MPU,6);
  x = Wire.read() << 8 | Wire.read();
  y = Wire.read() << 8 | Wire.read();
  z = Wire.read() << 8 | Wire.read();
}

The values printed in the serial of x_offset, y_offset and z_offset are always 0.


texts:
I'm making a game of snake on the adafruit Neopixel shield and have run in to a problem. How do you fill out an array (in this case a 5*8 array) with values once the class has been called.
This is my code so far

H file

#include <Arduino.h>
#include <Adafruit_NeoMatrix.h>
#include <streaming.h>

class Snake : public Adafruit_NeoMatrix
{
    public:
    Snake();
    void drawSnake();

    private:
    int snakeBoard[5][8];
};

CPP file

#include "Snake.h"

Snake::Snake() : Adafruit_NeoMatrix(8, 5, D6,
  NEO_MATRIX_TOP        + NEO_MATRIX_LEFT +
  NEO_MATRIX_ROWS       + NEO_MATRIX_PROGRESSIVE,
  NEO_GRB               + NEO_KHZ800)
{
  begin(); // start the matrix
  show();

  int snakeBoard[5][8] = {{1,1,0,0,0,0,0,0},
                        {0,0,1,0,0,0,0,0},
                        {0,0,1,0,1,1,-1,0},
                        {0,0,1,1,1,0,0,0},
                        {0,0,0,0,0,0,0,0}};
}

void Snake::drawSnake()
{
  for(int y = 0; y < 5; y ++)
  {
    for(int x = 0; x < 8; x ++)
    {
      Serial << "X: " << x << " Y: " << y << " Value" << snakeBoard[x][y] << endl;
      delay(100);
    }
  }
  drawPixel(5,5,Color(0,0,255));
  show();
}

When I run the program random garbage is printed in the serial monitor.


texts: How do I use a 5v/120v relay that is not mounted on a board

texts:
I bought an arduino kit, and it came with, amongst other things, a 5v relay to control 120-220v.

The relay is only that, there is only the 5 pin relay, and it's not on a board on which one can screw in the leads

I was wondering how I can use it..  i.e. how do I mount it somehow (especially since the leads are metric and most perf board is standard (or vice-versa)).

I don't mind soldering the 5v control leads from the arduino, but I'm not so sure about soldering or connecting 110v straight on the relay.  i'm worried about long term longevity.

I have soldered longer leads just to be able to fit it on a board for tests, but those are tiny, and aren't safe for higher voltage/current.

Any suggestions?
Thanks, Seb.


texts: Is there any version of arduino that can do something like serial interruption?

texts:
I am using an Arduino to control servo MX18A by serial, and trying to use computer to communicate with the Arduino by another serial to send commands to Arduino and change the servo control mode. Once the computer send a message to Aruduino, I hope it could response in time because may be there is something emergency like the servo being out of control ,under which circumstance I have to change the control strategy in time.

However, it seems like Arduinos like UNO, MEGA does not have serial interruption, so once the message from computer comes, it could not response in time.

I know that judging serial.available() in every loop is one solution, but in my different servo control strategy there are many time delays, for loops and while loops, which means that I have to put serial.available() in every time delay or for loops, making the code hard to write and maintain.


texts: Run 5V LED Matrix and LED Strip on one Arduino

texts:
I am fairly new to the Arduino community but have electronics and programming experience. I was able to connect and run a 5V RGB 8x32 LED matrix on my Arduino displaying some running text.
Now I would like to add a separate 5V LED strip that is controlled separately. For example I want to blink or light up either in red or in blue depending on an external switch.

How can I run a NeoPixel Matrix and a NeoPixel LED strip together off one Arduino controller?


texts: Problems with controlling LED with soil moisture sensor

texts:
I'm a beginner at Arduino.

I have a soil moisture sensor and I mapped the lowest and highest moisture value to a value in between 0 and 100.

What I was trying to do was if the value was less than 50, then the LED should turn on. But even when the value was less than 50 (e.g 25) the LED doesn't turn on.

The moisture detection or the value mapping works perfectly fine.

Does the issue lie on my code or my LED wiring?

Code:

int mostMoist = 180;
int leastMoist = 600;
int percent;
int raw;
const int threshold = 50;

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  raw = analogRead(A0);
  percent = map(raw,leastMoist,mostMoist,0,100);

  if (percent < 0){
    percent = 0;
  }

  if (percent < threshold){
    digitalWrite(LED_BUILTIN,HIGH);
  } else {
    digitalWrite(LED_BUILTIN,LOW);
  }

  Serial.println(percent);
  delay(2);
}


texts: VS1003 MP3 module performance(?) problem

texts:
I'm trying to play sound on Arduino Uno with a VS1003 module, using schematics and most of the code from this project and I have almost succeeded, but I've got (I think) a performance problem and I don't know what could be wrong. Midi files and low bitrate WAV files are played perfectly (so I think the code and wiring is OK) but when I play MP3 file I hear the song but the sound is slowed down (interrupted) with lots of little breaks (per second). I think it's not getting the data fast enough, but the original project is the same and it works! What can be wrong? Could it be the SD card reader module or SD card?

I have to note that the original wiring from that project was not working in my case because of SD initialization error. It started to work after I've replaced the 2.2K and 3.3K resistors for SPI lines with 100K and 200K. (I didn't have to replace those on the DCS, CS and RST lines of the VS1003 module). Also I don't have the LCD and buttons so my main loop() is just empty. I use the Serial for debugging (but not during the playback).

Edit:

I have tested the SD card performance and the result is 107kbps - no wonder the 192kbps mp3 is sliced! So it is clearly the SD card performance problem. Does anyone know why it could be so slow? Can the wiring or voltage affect the speed? I'm using LC STUDIO card reader and TOSHIBA SD-M512 card (512MB). Just tested the card in PC and it's fast, so it's either the reader or wiring.

Any ideas?


texts: GSM library getIPaddress returns local network address 10.X.X.X

texts:
I have a Mega board and a GSM shield. I'm using Arduino's example "TestWebServer". The serial monitor shows that the GSM is connected, and returns a IP.

However, the IP is always 10.X.X.X. Isn't that a internal network IP address? How should I get the SIM cards IP? Thanks!


texts: Question about controlling servos with PWM while being able to accurately read the current from a sensor

texts: Hi I am hoping to design a custom board ATMEGA32u4 with practically a Arduino leonardo bootloader. I plan to control up to 12 servos while being able to read back the current sensor voltage of an INA169 current sensor on voltage changes. The  voltage reading will be read back into a digital pin through an ADC controlled by a  multiplexer. The question is am I able to manage all the current sensing on all 12 servos properly with this setup? or should I use a faster controller that act as a master to do the data collection from the current sensor while the ATMEGA32u4 focus on controlling the servos? I plan to store this data too, so is this the right way of doing things?


texts: Is there a way to go to the start of the void loop() function kind of like a "continue" keyword in c in loops?

texts:
I am new to Arduino programming and am trying to make an obstacle avoiding car with an ultrasonic sensor and a differential driver model. While learning how to code it, I learned that you can exit the void loop() function with an exit(0) to terminate the program analogous to break keyword in C language.
Is there anything similar that I can use to mimic the "continue" keyword, say if I don't want to run the code after a particular line in the void loop() function.


texts: Why is the same program taking up more space in atmel studio?

texts:
When I compile the same program with atmel studio, the result is:
            Program Memory Usage     :    1326 bytes   16,2 % Full
            Data Memory Usage         :    0 bytes   0,0 % Full

When I compile the same program with arduino ide, the result is:
Sketch uses 100 bytes (1%) of program storage space. Maximum is 8192 bytes.
Global variables use 0 bytes (0%) of dynamic memory, leaving 512 bytes for local variables. Maximum is 512 bytes.

1326 bytes in atmel studio,100 bytes in arduino ide.Why ???
Atmel studio should have been better.My Atmel studio settings are set by default..Can you help if I have a change I need to make?
uint16_t adc_read() ----->//this function eats too much bytes in atmel studio.
{

ADCSRA|=(1<<ADSC);    //start conversion
 while(!(ADCSRA & (1<<ADIF)));

  uint16_t adc_data=(ADC);//
  return(adc_data);
}


texts: Receiving and sending on the Arduino Duemilanove with an MAX3232 chip

texts:
I have a max3232 hooked up to the RX and TX pins of the Arduino Due.  I'm trying to write a simple program to relay messages received from USB and output as RS232 through the chip.  Here is my code:

char readbyte;

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

void loop(){

  while (Serial.available() > 0 ) {
    readbyte = Serial.read();
    Serial.print(readbyte);
  }
}

This program works when I don't have the MAX2323 hooked up (e.g. I send "123" and get "123" echoed back), but when I hook up the MAX2323, the Arduino isn't sending back.  I've written another test program that sends random data and it seems to work fine.  I'm at a lost at what is wrong with my simple program, can anyone help?

Here is the schematic:


texts: Arduino motor control using digital pins

texts:
I am new to these Arduino things, and I am currently using an Uno board for my projects.

I don't know how to control the DC motor with the help of digital pins via L293D. But I cannot use the PWM pins of Arduino, since I have already used them for controlling servos and other things, which need higher accuracy.

I tried using the SoftPWM library to control motor, but it is conflicting with other things like ultrasonic sensor. I don't know what the problem is.

Could someone suggest me a solution?


texts:
I want to read voltage level by my Arduino board please help in this regard. I am using this syntax.

volts = analogRead(A3);    // read the input pin
Serial.println(volts)


texts: Does natural outdoors wind affect the readings of an ultrasonic sensor significantly?

texts:
I am thinking of using an ultrasonic sensor outdoors, and am wondering if the presence of wind (say up to 20km/h) would significantly impact the accuracy of the readings, or would this not be a large concern?
Thanks.


texts:
I am using Arduino Uno and Blue tooth HC-06, I am trying to use this in order to switch a LED through mt phone but I cannot create communication  between the Bluetooth and the Arduino, I am using software version 1.8.13 and I manage to pair to the Bluetooth through my phone, this is my code:
    char data = 0;                //Variable for storing received data
    void setup()
    {
    Serial.begin(9600);         //Sets the data rate in bits per second (baud) for serial data transmission
    pinMode(13, OUTPUT);        //Sets digital pin 13 as output pin
    }
    void loop()
    {
    if(Serial.available() > 0)  // Send data only when you receive data:
    {
    data = Serial.read();      //Read the incoming data and store it into variable data
    Serial.print(data);        //Print Value inside data in Serial monitor
    Serial.print("\n");        //New line
    if(data == '1')            //Checks whether value of data is equal to 1
    digitalWrite(8, HIGH);  //If value is 1 then LED turns ON
    else if(data == '0')       //Checks whether value of data is equal to 0
    digitalWrite(8, LOW);   //If value is 0 then LED turns OFF
    }

}

and this is the image of the wiring:

I don't have any problem with the computer the software or the Arduino different codes I can run very easily the only problem is with the Bluetooth device
Thanks a lot


texts:
Suppose we have a computer mouse , now when we connect it to a computer then  computer understands it is a mouse which is been connected to it. Same thing happens for keyboard and many other devices. As per my understanding, the mouse has a microcontroller and a TTL serial converter which is programmed a certain way that enable computer's default mouse driver to understand the instructions coming from the connected device.

Let me to talk about one of my projects where I build a device driver for my own device. Like arduino send serial instructions to a port say COM3 and the driver which is a java program reads those instructions and performs accordingly.

As we all know that the arduino library provides support for Mouse and keyboard which works fine. Mouse operations are performed without a custom driver.

Now what I want is when arduino connects to a computer it gets detected as a Joystick or as a pendrive or something like that.

I go through different header files of mouse and keyboard which are present in arduino library but those are very complex and without proper documentation hard to understand.

Can you tell me where I could find study materiel regarding the existing library? Arduino website provides documentations only on different methods not on how it works.

Or if I think of building my own library then how I should start?

One more thing where I can find the information regarding the protocols that a conventional device like mouse, keyboard, pendrive, CD-ROM follows during communication (like the code or the algorithm that is burn into the microcontroller of the device) ?

I know it is a out of the box question but still if you help me, I will be grateful to you.


texts: How to use a DC buck converter to regulate Uno R3 input voltage?

texts:
I have had a rough time trying to understand why this isn't working correctly. Quick background: I set up a system to pop open car doors using touch sensors. I heard that powering the Arduino Uno R3 straight off the car battery is not a good idea, so I bought a buck converter. I wired it up and calibrated the output on the converter for 5V. When I hooked it up to the Arduino (via the barrel jack), I experienced some odd effects. The output pins and the 5v power pins were only getting 3.5V.  I had to adjust the buck converter up to about over 7V in order to get 5v on the Uno.

Then the sensors started acting oddly. Auto triggering and alternately not working. Anyone know what I am doing wrong?

Converter I bought:  https://www.amazon.com/gp/product/B0159W0UL2/ref=oh_aui_detailpage_o07_s00?ie=UTF8&psc=1


texts:
I hope I'm in the right place to ask, I couldn't find anything so I ask here, please tell me if I missed some relative topic.

I was following this tutorial : https://learn.adafruit.com/force-sensitive-resistor-fsr/using-an-fsr#in-depth-code-for-analog-fsr-measurements
and the only difference is that I have a potentiometer instead of a 900K resistor. I put it to 14350 Ohms because it fits the tutorial just above the last one, on top of the same page.
So here is the thing : I want to know the force in Newtons but the values I end up with are clearly wrong. A medium touch on the FSR is already > 3 Newtons, and it changes a lot when I turn the potentiometer to a higher resistance (and changing the value of that pota in the code too) : same force applied, different value of that force on the screen.

I know nothing about elecs so I would also like to know more about this part :

// Use the two FSR guide graphs to approximate the force
if (fsrConductance <= 1000) {
  fsrForce = fsrConductance / 80;
  Serial.print("Force in Newtons: ");
  Serial.println(fsrForce);
} else {
  fsrForce = fsrConductance - 1000;
  fsrForce /= 30;
  Serial.print("Force in Newtons: ");
  Serial.println(fsrForce);
}

Where does the /80 and -1000 then /30 come from ? Why is it a different operation and not just only different values ?
I'm using the same FSR but with 3.3V. I have the same graph as this one : https://learn.adafruit.com/force-sensitive-resistor-fsr/overview#how-to-measure-force-slash-pressure-with-an-fsr

I would really appreciate clear and simple explanations. Thank you by advance !


texts:
Hello Internet Arduino enthusiasts!

I'm totally new to Arduino and as my first project, I'd like to make a controller connected to computer A (the master) and computers B and C as 'slaves'.

The master would simply send commands as USB mouse and USB keyboard inputs to slave computers through an Arduino controller. Think of it as a hardware KVM switch (without the V(ideo)).

Now, I'm planning to work on that during the Christmas vacations, so I need to order the parts now to receive them in time.

I was thinking I could use these parts:

Arduino Due (because it has the capability to send keyboard and mouse input)
2 SparkFun FTDI Basic Breakout - 5V, one for the mouse, one for the keyboard (per target computer) (https://www.sparkfun.com/products/9716) (because I can convert it to a 3.3v, what the Due is using)

Please consider:

The price is not really an issue for now.
I'm not worried to much about the programming.
I'll figure out how to make it work once I have the time and the items.
I know someone who has a starter kit from SparkFun, and there is an electronic store closeby, so I'm not worried about the wires.

Will I be able to make what I'd like with those basic parts, or am I missing something?

Thanks!


texts: Sanity check with potential project. IoT with a dishwasher

texts:
So sanity check for a potential project.

We have an old dishwasher at work, a GE QuietPower 3, and being a technology company, we want to connect it to our chat room to notify that the cycle is done, so someone can unload it.

The first iteration of the project we were just going to cover the "finished" indicator light with a photoresistor, so when it lights up, the microcontroller will know it is done.

However, that is not very nice looking, the second approach, after quickly looking at the technical maintenance manual. Is to literally solder the ground and + of the "finished" indicator light to a digital or analog pin, and the ground pin on the micro controller, so the results are more precise.

I suspect the LED is probably less than 12V, (will confirm with a multimeter). I will step it down to 5V.

Then it is just a matter of checking if the pin is high or not on the microcontroller, is this simple enough to solve the problem, or am I overlooking something obvious?


texts:
I found this great code to pick a random number from a "hat" without repeat:

/* RandomHat
  Paul Badger 2007 - updated for Teensy compile 2017
  choose one from a hat of n consecutive choices each time through loop
  Choose each number exactly once before reseting and choosing again
*/

#define randomHatStartNum 0  // starting number in hat
#define randomHatEndNum 25    // ending number in hat - end has to be larger than start
#define numberInHat (randomHatEndNum - randomHatStartNum) + 1

void setup()
{
  Serial.begin(9600);
  Serial.println("start ");
}

void loop()
{ // randomHat test
  for (int i = 1; i <= numberInHat; i++) {
    int x = randomHat();
    Serial.print(x);
    Serial.print(", ");
    delay(50);
  }
  Serial.println(" ");
}

int randomHat() {
  int thePick;    //this is the return variable with the random number from the pool
  int theIndex;
  static int currentNumInHat = 0;
  static int randArray[numberInHat];

  if  (currentNumInHat == 0) {                  // hat is emply - all have been choosen - fill up array again
    for (int i = 0 ; i < numberInHat; i++) {    // Put 1 TO numberInHat in array - starting at address 0.
      if (randomHatStartNum < randomHatEndNum) {
        randArray[i] = randomHatStartNum + i;
      }
    }
    currentNumInHat = abs(randomHatEndNum - randomHatStartNum) + 1;   // reset current Number in Hat
    Serial.print(" hat is empty ");
    // if something should happen when the hat is empty do it here
  }

  theIndex = random(currentNumInHat);                  //choose a random index from number in hat
  thePick = randArray[theIndex];
  randArray[theIndex] =  randArray[currentNumInHat - 1]; // copy the last element in the array into the the empty slot
  //                                                     // as the the draw is random this works fine, and is faster
  //                                                     // the previous version. - from a reader suggestion on this page
  currentNumInHat--;    // decrement number in hat
  return thePick;
}

I would like to use a custom array to choose from like so:

char *things[]={
"Thing 1",
"Thing 2",
"Thing 3",
"Thing 4",
"Thing 5",
"Thing 6",
};

Which is quite possible as I use the numbers from to first piece of code to select items from my custom array.

So I have two questions about this:

The first being the code first returns "hat is empty" before the numbers.

start
  hat is empty 11, 24, 17, .......
  hat is empty 4, 19, 23, .......

Is there a way to reverse this?

And secondly, I would like define the randomHatEndNum automatic by the lenght of my custom array, but I have trouble implementing that code. What is the right way to approach this?


texts: Arduino Nano and 0.96 i2c oled screen not working

texts:
When I try to scan the i2c address it stays stuck on "i2c Address Scanner" which is the first line of the code.
My screen is connected with VCC-5V, GND-GND, SCL- 4.7K resistor->A5, SDA- 4.7K resistor->A4.
Nothing displays on screen, and I even tried without the resistors. I also tried with some 10K resistors and same result.

Here in the picture you can see how I connected the screen to the nano. SDA-A4, SCL-A5, VCC-5V, GND-GND.


texts:
I was wondering if the following type of wire adapter existed. Because I have some small JST pins and I need to connect them to some JST XH pins. (Preferably on amazon):

JST to JST XH adapter


texts:
Today I got Arduino Leonardo to replace my Uno. I've tried running one of sketches I use on the Uno, but with no luck. When I start the upload, RX LED on the Leonardo flashes few times, and after several seconds, L LED pulsates and I get this message:

avrdude: ser_open(): can't open device "\\.\COM9": The system cannot find the file specified.

avrdude: ser_send(): write error: sorry no info avail

I've checked in Device Manager, where it says that Arduino Leonardo is on COM3, and COM3 is also set in Arduino IDE.

However, when I change COM port to 9 in Device Manager and also in Arduino IDE and then try to upload the sketch, things start to roll out like above, but this time IDE freezes for 5-10 mins on "Uploading..." part, and finally unfreezes with this message:

Found programmer: Id = "B¨J"; type =
    Software Version =
avrdude: error: buffered memory access not supported. Maybe it isn't
a butterfly/AVR109 but a AVR910 device?

Several more infos:

- OS: Win7 64-bit
- Arduino IDE: 1.0.5-r2
- Other serial devices: Only Bluetooth that I've manually assigned to COM200, to avoid possible conflicts.


texts: Issue sharing MISO with multiple RC522 RFID Readers

texts:
so for about the last 8.5 hours (almost non-stop) I have been trying to figure out one issue and I have exhausted every search I could possibly think of.

I'm building a puzzle that requires 5 RFID readers on the 1 Arduino, but for the sake of testing i've only been using 2.

Both readers work independantly, I can read out the UIDs of the little cards, which is all I need to do, but as soon as I make them share the MISO line, it simply stops printing anything out. I have no idea why.

Both readers have a common external 3.3v power supply and ground, they share all other lines but have an individual Slave Select. For testing I put both of their MISO cables into a breadboard which then leads into the Arduino on PIN 12, but it will only print out the UID when only ONE cable is plugged into the breadboard.

So is there something special I need to do to make this work? Is there a reason why the readers sharing a MISO line would break it? Even if i don't initialise one of them, just for the fact that it's plugged in still breaks it. I have tried setting one to HIGH and one to LOW, both to LOW, both to HIGH, nothing changes it.

Also, something else kind of confusing to me, it's meant to be active LOW to activate the SS, but when only 1 is plugged into the MISO line, it doesn't seem to matter which state it's in, it always prints...

I did a little bit of testing on my sketch just a moment ago and realised that when both are plugged into the MISO, the sketch will not progress past this line (which is also the first line in the loop)

if ( ! mfrc522_2.PICC_IsNewCardPresent())
        return;

I know everything else is working because it works when there is nothing else plugged into the MISO line, but I need it to work when all the others are plugged in too.

Please please please, if you have any idea, let me know.

I'm using the MFRC522 Library

EDIT:

This is basically the setup i'm using:

I'm not using any voltage translators or shifters, everything is 5v from the arduino except for the power to the readers which is coming from an external 3.3v supply like mentions previously.

I'm pretty certain that this is the datasheet for the RC522 i'm using, though i'm not sure if it's V1 or V2, but given the differences between them I don't think it matters:

http://www.nxp.com/documents/data_sheet/MFRC522.pdf

I don't know if they are able to share MISO lines like someone below said, I just assumed I could?


texts: Placing decoupling capacitors when building an Arduino PCB with Atmega328-PU

texts:
I have previously asked this question:

Custom build of arduino on a pcb

And thanks to the answer by Majenco I have learned that my circuit works a lot better when adding a capacitor. For example I am using the NRF24L01 and it is much more stable when using a capacitor. I am placing the capacitor for now next to the power supply like this:

Right now I am running this on a breadboard. The Atmega328 chip is very cheap compared to the arduino uno board; therefore, I will like to continue building my projects based on the atmega328P-PU chip.

Anyways before printing the PCB based on the Atmega328P-PU chip, where should I place the capacitors in order to reduce the most noise? The capacitors are very cheap and making one good design will enable me for all my future designs to be based from this one.

From researching on the internet I see a lot of different examples. Everyone uses different capacitance sizes. For example I have found this:

I got that from this link: https://www.autodesk.com/products/eagle/blog/what-are-decoupling-capacitors/

On other places they say to place the capacitance closest to the pins such as from this video. If that is true should I just place one capacitor on pins 7 and 8. Lastly the other capacitor on pins 20 and 22?

I do not mind soldering extra pins knowing my circuit will have the best performance.


texts: Cannot include .h files back one directory

texts:
I am working on a project with multiple arduinos. I want my folder structure to be as follows:

/
  libs/
    someSharedFile.h
  arduino1/
    arduino1.ino
  arduino2/
    arduino2.ino

When I include someSharedFile.h in one of my .ino files like this #include "../libs/someSharedFile.h", I get this error No such file or directory.

However, when I move libs/ to arduino1 and include the shared file like this #include "libs/someSharedFile.h" everything works fine.

I am using IDE 1.6.7 on windows 10.


texts: is it possible to code microservo automatically stop when the speed of rotation getting slower?

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


texts: How to program and arduino UNO via NodeMCU ESP8266?

texts:
I don't have my USB type A cable to program my UNO, I would like to program it via a NodeMCU ESP8266.
Maybe with the TX and Rx pins, I've seen people program certain versions of ESP with a UNO board.
How do I do this and is it possible?


texts: Send serial commands through IDE while RX pin is in use

texts:
This is really a two part question. I have an ESP8266 hooked up to USB. I have connected my LED strip (WS2812B LEDs) to the RX port, so I can control them individually and so on. I realised WiFi is a bit slow and will eventually crash the ESP8266 if I send enough requests, which is why I want to give serial a go.

If I open up the serial monitor, how do I send something to it, such as a color or 100 colors in one command? I'd assume Serial.read() inside a Serial.write() would display whatever I type in, but it doesn't do that. I can Serial.write() inside a loop, and it will display that.
Is something like this even possible? I'm looking for a way to send a lot of information (could be 100 colors (1 per LED)) as fast as possible. Speed is the key here.

Software serial is an option as well, as long as it's faster than WiFi.


texts: How to split a string received via a GSM module (message)

texts:
I am doing a motorcycle security system. In this system, I will receive a message from GSM in the form {password:operation (like start,stop,alarm):time}.
Example:(9990:start:30)

now i need to split  each term seperately (a=9990,b=start,c=30).help me to solve


texts: IR Remote code not activating ON/OFF states

texts:
The code below is for turning RGB lights on/off. The connections are as indicated in pin numbers. I found the resulting value of the buttons of the remote but when I used them in code it is not showing ON/OFF.

I assume there may be some practical errors. How to avoid such errors?

#include <IRremote.h>

int RECV_PIN = 3;
int red = 13;
int blue = 12;
int green = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  pinMode(red, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(green, OUTPUT);
}

void loop() {
  if (irrecv.decode(&results)) {
    long int getting = results.value;
    Serial.println(getting);
  }
  switch (results.value) {
    case 16582903:
      digitalWrite(red, HIGH);
      digitalWrite(blue, LOW);
      digitalWrite(green, LOW);
      break;
    case 16615543:
      digitalWrite(red, LOW);
      digitalWrite(blue, HIGH);
      digitalWrite(green, LOW);
      break;
    case 16599223:
      digitalWrite(red, LOW);
      digitalWrite(blue, LOW);
      digitalWrite(green, HIGH);
      break;
    default:
      Serial.println("Enter ;");
  }
  irrecv.resume(); // Receive the next value
  delay(100);
}


texts: Memory allocation on Arduino Due never returns NULL

texts:
I'm working on a project that uses quite a bit of RAM to store and analyze data that is sent from the PC. The program heavily relies on malloc/free, which normally works just fine. However, if the data set gets to big - which I can't tell beforehand - the Arduino just dies. Some analysis found that it has to do with memory management. Running a simple sketch which just does
void loop() {
  int SIZE_TO_TEST = (1024 * 10);
  int* mem = (int*)malloc(SIZE_TO_TEST);
  if (mem == nullptr)
  {
    // This never happens
    Serial.print("Allocation failed\r\n");
    return;
  }
  Serial.print("Allocation succeeded\r\n");
  Serial.print((int)mem, HEX); // this always prints 0x200712E0, regardless of the size
  Serial.println();
  for (int i = 0; i < SIZE_TO_TEST / 4; i++)
  {
    mem[i] = i;
  }

  for (int i = 0; i < SIZE_TO_TEST / 4; i++)
  {
    if (mem[i] != i)
    {
      // You better get a new board if this happens
      Serial.print("HARDWARE ERROR: Memory broken\r\n");
    }
  }
  free(mem);
}

works fine and repeatedly prints "Allocation succeeded". When I start increasing the SIZE_TO_TEST, the CPU crashes when the value is over the effective memory size of 96k. The weird thing is, that even when the value is 1000k (far beyond what the uP actually has), the pointer returned by malloc() is still the same memory address, not NULL, as one would expect. The crash also does not occur if the allocated memory is not used (if the two for loops are commented out), so I suspect the actual crash occurs because the program tries to write to memory that is not actually there.
How do I find out that the memory is exhausted? Why does malloc() never return NULL?
(Note: I know about the problems of memory fragmentation with small micro controllers, but I can work around that issue)