texts:
simulate this circuit – Schematic created using CircuitLab

In above schematic;

what value should R1 have? is it even needed?
do we need that pull down resistor(R2)? if yes, 10K is enough or we need higher value like 100K resistor there?

IRLZ44N DATASHEET


texts: ADXL345 hangs the microcontroller as vibrations increase

texts:
I am using ADXL345 accelerometer with Adafruit_ADXL345 library for vibration measurement.

I am reading acceleration at X, Y, Z-axis of a sensor placed on a vibrating platform.And serially sending it to PC at a baud rate of 115200.

When vibration is low sensor shows vibrations but as i increase the vibrations serial transmission seems to be halted. As shown in figure:(x-axis=Samples y-axis=Samples )

I thought it may be due to loose connections so I soldered its terminals but it behaved the same way at higher vibrations.
 Here is the code that I’m using.

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
/* Assign a unique ID to this sensor at the same time */

Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12);
int i=0;
struct measure
{
    int timestamp;
    float x;  // ACC in x direction
    float y;  //ACC in y direction
    float z;  //ACC in z direction
};
sensors_event_t event;
struct measure measurements;

int timestamp = 0;

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

  Serial.println("Accelerometer Test"); Serial.println("");

  /* Initialise the sensor */
  if(!accel.begin())
  {
    /* There was a problem detecting the ADXL345 ... check your connections */
    Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
    while(1);
  }
  accel.setDataRate(ADXL345_DATARATE_3200_HZ);
  accel.setRange(ADXL345_RANGE_16_G);
     pinMode(LED_BUILTIN, OUTPUT);
  delay(2000);
}

void loop(){

 accel.getEvent(&event);
   measurements.timestamp = timestamp++;
   measurements.x  = event.acceleration.x;
   measurements.y  = event.acceleration.y;
   measurements.z  = event.acceleration.z;

if(measurements.timestamp%2==0)
  digitalWrite(LED_BUILTIN, HIGH);
  else
    digitalWrite(LED_BUILTIN, LOW);

  /* Sending the array with data through serial*/

  Serial.print(measurements.timestamp);
 Serial.print(",");
 Serial.print(measurements.x+0.06);
 Serial.print(",");
 Serial.print(measurements.y+0.7);
 Serial.print(",");
 Serial.println(measurements.z-10.10);
}

Where does problem lie? How to resolve this issue?

Circuit Connections:


texts: Having problems compiling this code for NRF24l01 on stm8s103f3p6

texts:
It said it has mutiple libraries were found for "nRF24L01.h"
but i check the Ardurino libraries I can only found one.
And it work fine if I compile it to Arduino uno.

//Include Libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

//create an RF24 object
RF24 radio(8,9 );  // CE, CSN

//address through which two modules communicate.
const byte address[6] = "00001";

void setup() {
  // put your setup code here, to run once:

  while (!Serial);
    Serial.begin(9600);

  radio.begin();

  //set the address
  radio.openReadingPipe(0, address);

  //Set module as receiver
  radio.startListening();
}

void loop() {
  // put your main code here, to run repeatedly:

  if (radio.available())
  {
    char text[32] = {0};
    radio.read(&text, sizeof(text));

    Serial.println(text);

  }

}

Here is the error message

Arduino: 1.8.10 (Windows 8.1), Board: "STM8S103F3 Breakout Board"

Multiple libraries were found for "nRF24L01.h"
bash.exe: warning: could not find /tmp, please create!
 Used:
C:\Users\UserName\Documents\Arduino\libraries\RF24
C:\Users\UserName\AppData\Local\Arduino15\packages\sduino\tools\sdcc\build.10738/bin/sdcc sketch\receiver.ino.cpp

nul re12 -c -Ddouble=float -DUSE_STDINT -D__PROG_TYPES_COMPAT__ -E -MC -mstm8 -DSTM8S103 -DF_CPU=16000000L
-DARDUINO=10810 -DARDUINO_STM8S_BLUE -DARDUINO_ARCH_STM8
-IC:\Users\UserName\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.4.0\cores\sduino
-IC:\Users\UserName\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.4.0\variants\standard
-IC:\Users\UserName\Documents\Arduino\libraries\RF24
-IC:\Users\UserName\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.4.0/STM8S_StdPeriph_Driver/inc
-IC:\Users\UserName\AppData\Local\Arduino15\packages\sduino\tools\sdcc\build.10738/include
Mark re12:C:\Users\UserName\AppData\Local\Arduino15\packages\sduino\tools\sdcc\build.10738/bin/sdcc -c -Ddouble=float -DUSE_STDINT -D__PROG_TYPES_COMPAT__ -E -MC -mstm8 -DSTM8S103 -DF_CPU=16000000L -DARDUINO=10810 -DARDUINO_STM8S_BLUE -DARDUINO_ARCH_STM8 -IC:\Users\UserName\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.4.0\cores\sduino -IC:\Users\UserName\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.4.0\variants\standard -IC:\Users\UserName\Documents\Arduino\libraries\RF24 -IC:\Users\UserName\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.4.0/STM8S_StdPeriph_Driver/inc -IC:\Users\UserName\AppData\Local\Arduino15\packages\sduino\tools\sdcc\build.10738/include sketch\receiver.ino.cpp -o nul
cpp gefunden
In file included from C:/Users/UserName/Documents/Arduino/libraries/RF24/RF24.h:18,
                 from C:\Users\UserName\Desktop\mad\receiver\receiver.ino:4:

C:/Users/UserName/Documents/Arduino/libraries/RF24/RF24_config.h:143:30:
fatal error: avr/pgmspace.h: No such file or directory

compilation terminated.

exit status 1
Error compiling for board STM8S103F3 Breakout Board.

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


texts: how to interrupt the loop function and restart it?

texts:
I have a project with some NeoPixels and other LEDs and an Arduino UNO.
Once switched on, the defaultLEDAnimation with colors and blinking, etc. starts.

I want to trigger some other animations, so I connected two buttons to the Arduino. Whenever you press button1, the Arduino should stop everything it is doing and run animation1. The same goes for button2. if you press it, the Arduino should run animation2. All animations are quite complex and run for several seconds and even minutes.

Now for the challenge: How do I use the two buttons to immediately stop every animation happening and display the appropriate animation?

The tried using interrupts and connected the two buttons to pin 2 and 3.
However, when I press the buttons, the animation starts after several seconds delay. Is there any way to restart the loop function immediately after the interrupt has been made? Or is there another way to trigger my animations with those two buttons?

The code looks something like this:

#define button1 2
#define button2 3

volatile bool shouldPerformButton1Action = false;
volatile bool shouldPerformButton2Action = false;

void setup() {
    attachInterrupt(digitalPinToInterrupt(button1), button1Pressed, RISING);
    attachInterrupt(digitalPinToInterrupt(button2), button2Pressed, RISING);
}

void loop() {
    if (shouldPerformButton1Action) {
        doAnimation1();
        shouldPerformButton1Action = false;
    } else if (shouldPerformButton2Action) {
        doAnimation2();
        shouldPerformButton2Action = false;
    } else {
        runDefaultAnimation();
    }
}

void button1Pressed() {
    shouldPerformButton1Action = true;
}

void button2Pressed() {
    shouldPerformbutton2Action = true;
}

void doAnimation1() {
    for(int i=0; i<10; i++){
        neoPixelStrip.setPixelColor(neoPixelArray[i], neoPixelStrip.Color(255, 0, 0, 255));
        neoPixelStrip.show();
        delay(100);
    }
    delay(1000);
    for(int i=0; i<10; i++){
        neoPixelStrip.setPixelColor(neoPixelArray[i], neoPixelStrip.Color(0, 0, 0, 0));
        neoPixelStrip.show();
        delay(100);
    }
}

The function doAnimation1 is just an example. It will be much more complex.


texts:
I notice problems with my output pins when I use this method of setting their pinMode:

int allOutputPins[] = {3, 4, 9, 10, 5, A3, 11, 12, 7, 8, A1, A2};

for(int a = 0; a < sizeof(allOutputPins); a++){
   pinMode(allOutputPins[a], OUTPUT);
  }//end for

Am I doing something wrong?


texts: What are the differences between the Arduino Micro and Pro Micro?


texts:
I have a dev board for my attiny85.
when connecting it to the computer I get "unknown USB device(device descriptor request failed)"
although I have the needed drivers, so I thought of trying using my nodemcu.
Tried connecting the SPI (to the nodemcu hmiso;hmosi;hcslk;hcs)and upload using "arduino as ISP" and compitable settings(https://www.hackster.io/arjun/programming-attiny85-with-arduino-uno-afb829).
pressing "burn bootloadre" using this way gives me errors:
"avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x03
......
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x03
Error while burning bootloader."
***EDIT:
After changing a line(#define USE_OLD_STYLE_WIRING) in ArduinoISP (from example)
the error code changed a bit and it shows up much faster:
"Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "ATtiny25/45/85, ATtiny85, Internal 8 MHz"
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x04
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x30
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x61
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x67
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xc1
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xc4
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xc5
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xa1
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xcc
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xe2
Error while burning bootloader."
Any help on how to use nodemcu to program attiny85 will be great
thanks


texts: ESP8266 Timing question / Do something in 2 seconds even

texts:
I am able to synch my ESP8266 running on Arduino core with the time.nist.gov-Server but how can I achieve to trigger i.e. a digital pin in 2 seconds even? What I mean is that following:

The MC recieves the signal for trigger by the user on 09:25:18:312
It waits until it is exactly 09:25:19:000
It triggers the digital out on +2 seconds, on 09:25:21:000

Thanks!!

Edit: Corrected Times.


texts: Why does current flow along a wire instead of a resistor right next to it?

texts:
I am having trouble understanding exactly what is going on in a circuit where when a button is pressed an LED goes on. Also, I have the Arduino UNO.

The schematic can be seen at:

2:36 of this video: Arduino Tutorials: Control a LED with a Button.

So, the part that I don’t understand is, how come when the button is clicked and the current can pass through, the current doesn’t go through the pull down resistor and instead goes along the input wire?

I’m a beginner but do understand concepts like voltage, amps, resistors, Ohm’s law, etc. So answers don’t have to be super simple, but simple enough that I can understand them. Thanks!


texts: Can i used code written in BASIC (.hex File) to write an Arduino sketch?

texts:
Poormans Soldering Station

GCBasic Code

Hi,

i have followed these plans to create a soldering station but changed the atmeaga chip for an Arduino Mini Pro.

http://poormanelectronics.blogspot.com/p/pm-soldering-station.html - Full Plans which i followed

http://poormanelectronics.blogspot.com/2015/08/5-firmware.html - GCBasic Firmware

As your can see the code is written in BASIC which i cant transfer to Arduino.

Is there any way i can use this code to write an Arduino Sketch ?


texts: Burn normal bootloader onto Atmega328P configured to use internal 8MHz clock

texts: I have an Atmega328P that I have previously burned with a bootloader configured to use the 8MHz internal clock as described here. I would like to now burn the normal Duemilanove bootloader configured to use an external 16MHz clock onto the chip. However, when I try following the normal procedure, it says "Invalid device signature". I can still upload programs to the chip and they will run, but I would like it to use the 16MHz external clock. How do I do this?


texts: ESP8266 - Garbled output when using serial Swap

texts:
I want to use two serial ports

Serial1 - for debugging - No RX needed

Serial - to read from a different device

I receive garbled output instead of valid characters

Here is code for NodeMCU

#define LED D0

void setup() {
  // put your setup code here, to run once:
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
  Serial.flush();
  Serial.swap();
  Serial1.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(Serial.available()>0)
  {
//    digitalWrite(LED, HIGH);
//    delay(500);
//    digitalWrite(LED, LOW);
//    delay(500);
//    digitalWrite(LED, HIGH);
//    delay(500);
//    digitalWrite(LED, LOW);
//    delay(500);
    Serial1.print(Serial.read());
  }
}

and here is the code for Arduino mega which is emulating a send and receive

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial1.begin(9600);    //Transmit
  Serial2.begin(9600);    //Recieve
}

void loop() {
  // put your main code here, to run repeatedly:
  if(Serial.available()>0)
    Serial1.print(Serial.read());

  if(Serial2.available()>0)
    Serial.print(Serial2.read());
}

When I Send an Charater(Single) I receive something like this
for "s" - 5257525753515257534952575256
for "d" - 5257525652565257534952575256

Kindly help


texts: ATtiny44 millis() not working with 16 MHz external clock

texts:
I'm using ATtiny44 with Arduino IDE according to this tutorial: http://highlowtech.org/?p=1695

I have a problem with millis(). When I use an internal 1 MHz clock it works correctly but when I use external 16 MHz clock it takes millis() much more time than one second to be divisible by 1000.

I tested it with LCD and Hello World sketch, modified to correspond ATtiny's pins. Do millis() actually work with Tiny's?

Why does it work properly with 1MHz and not with 16 MHz which is the same as used in Arduino platform.


texts: How to Create a water screen with solenoid valve in arduino

texts:
I want to make a water screen. I will create character with solenoid valve. Sometimes sequential valve will pass to water, sometimes not pass.

And I will create some shape or character.

But I don't know how can I create this character with Arduino.

Do you have any good idea ? Can you help me ?


texts: Programming ATMEGA328p via AVR Pocket Programmer

texts:
I have a ATMEGA328p on a breadboard with the following connections to the 2x3 ICSP connector and its connected to AVR Pocket Programmer.

While running AVRDUDE utility, i get the following error,

avrdude -c usbtiny -p m328p

The controller is powered by the AVR and i have made certain about the pinout. Anyone run into the above error?

Adding more verbose output from the terminal.


texts:
I just watched this excellent video tutorial that shows a simple Arduino program that toggles an LED via a pushbutton. Very cool!

In the video, the author is using a breadboard for prototyping his circuit. What's the next "step up" from this? In other words, say I get my breadboard circuit working perfectly, is it now time to create a PCB? If my understanding of circuitry is correct, this is not a trivial process. I would need a CAD program to design my circuit, and it would likely be very expensive to get the design actually fabricated. At least too expensive for simple hobby purposes. Is there a middle ground between breadboard and PCB?


texts: How does ESP8266 work as web server with Arduino?

texts:
I am trying to learn internet of things with smart home. I will connect an ESP8266 and an Arduino with the IBM Bluemix server to control a circuit from a public IP.

I want to start with the local network for now. I have gone through a couple of links which seem like a great start http://allaboutee.com/2014/12/30/esp8266-and-arduino-webserver/

They explain how it works, and have source code but no circuit diagram. How should I connect the ESP8266 with Arduino for this example ?

#include <SoftwareSerial.h>

const byte rxPin = 2; // Wire this to Tx Pin of ESP8266
const byte txPin = 3; // Wire this to Rx Pin of ESP8266

// We'll use a software serial interface to connect to ESP8266
SoftwareSerial esp8266(rxPin,txPin);

void setup() {
  Serial.begin(9600);
  esp8266.begin(9600);
  delay(1000);
}

void loop() {
  Serial.println("Sending an AT commands");
  esp8266.println("AT");
  delay(30);
  while(esp8266.available()) {
    String data = esp8266.readStringUntil('\n');
    Serial.println("Got response from esp8266: " + data);
  }
}


texts:
I am planning an uno based tachometer for my truck, which doesn't have a tachometer. With nothing in place for me to get a reliable signal, I started looking at other sources to read the rpm from the engine.

It seems to me that an engine should affect the power every time a cylinder fires --the power should spike in some way. So in theory I should be able to hook up to the 12v cigar lighter, count the spikes, and calculate the rpm. It would only need to be accurate within 500 rpm or so.

This is a two part question.

How would I hook up the arduino to the 12v system? As in, what should I do to protect the io of the arduino?
How would I gather the test data to see if this is possible? Is there a way to hook the arduino up to the truck via the 12v and my computer via usb and send data back that I can record or monitor?


texts: How to fix bricked esp8266 after run AT+IPR=9600

texts:
I was seeing tips to change baudrate to 9600, which i saw on this forum with use AT+IPR command. Unfortunately it's brick my esp8266, the indicator blue led always on. After i search google not only me got this problem, and yeah it's caused by AT+IPR. Now how to fix this problem?
Im unable to send AT command anymore


texts: Switched from 3ft to 10ft connection wires. My setup doesnt run correctly now. Timing issues?

texts:
Running a DC motor(6.5A max input), motor driver (MD10C 7Amp peak output), and Arduino Mega. I am stabilizing an object with an accelerometer as my sensor. I switched to longer wires so I can have my board next to me and the stabilized object far away. Now I believe there are timing issues because of this. How would I fix this? How would i test to see how long it takes to travel through my wires?
I can add my code if that helps.


texts: read first line from sd card and save the position for again reading from sd card

texts: I am reading sd card .txt file, I want to read the first line then how to save the position of the pointer for the next line read?


texts: Trying to print text on LCD display from Arduino trinket

texts:
I'm trying to simply program an Arduino trinket to display some text on an LCD display.

I'm basically trying to follow this, except connect it to a Trinket rather than an Arduino Uno. The background color of the LCD display is changing as expected from the loop function in my Arduino code, but it's just displaying some o's and arrow's for text on the LCD display.

I'm new to Arduino's (and EE in general), but am a computer programmer.

What am I doing wrong that the sample code in the above link doesn't print text on my LCD display?


texts: Hello I am working on getting a pwm signal with arduino nano, I am new to Arduino and i need it for a project

texts:
I want it so that

When I apply 1v to analog input i get a pwm signal of 50% duty cycle.
When I apply 2v to analog input i get a pwm signal of 80% duty cycle.
Can someone tell me the code on how to do it.


texts:
Its a well known fact, that you can debug your arduino board with the help of an Atmel Ice. However, you might know the Controllino which is an arduino compatible device.

It has an ATmega2560 on it.

Do you have an idea how to debug a controllino? I neither see any ICSP port nor did I found anything useful around this topic.

Any help is greatly appreciated!


texts:
I'm using Matlab to communicate with a custom AD7746 board through an Arduino UNO. The data sheet mentions that
"In continuous conversion mode, the address pointers’ autoincrementer should be used for reading a conversion result.
That means, the three data bytes should be read using one
multibyte read transaction rather than three separate single byte
transactions"
I'm not sure how I can go about implementing this using MATLAB's Arduino support package.
Would anyone have an Idea about this?


texts: Run Arduino on USB and at the same time BreadBoard on higher voltage?

texts:
I am trying to design a bicycle LED lighting system, and for that I bought an Arduino yesterday (so very beginner with Arduino).

My final system will operate at 6V, so I plan to put everything on a breadbord and tune everything (blinking times, resistor values, etc.) and for that I want to keep my Arduino plugged to USB during development.

So my question is:

How should I connect USB-powered Arduino to a higher-voltage-powered breadbord (between 6 and 12V) safely?


texts:
I want to controll some ambient lights in my living room.

Therefore, I got some 433mhz outlets which can be turned on or off with an remote, a 433mhz transmitter and receiver on the arduino.

The arduino receives the remotes signals and knows which lamp has which state and will turn any lamp off at specific times.

Now I want to turn on the lights automatically when I close the shutter, but I have no idea how I could do this.

A light sensor behind the window won't do the job. I don't want to turn on the lights when it get's dark, but when the shuhtter get's closed.

Edit:
What came to my mind first was an light sensor inside the window, facing outside, and a IR LED. I'd attach some tinfoil to the inside of the shutter to return the IR light, which the sensor will notice. But maybe the're are some simpler solutions? Also, the tinfoil would fall off quickly...


texts:
I am using an Arduino UNO and I am trying to vary the brightness by steps by 0.5 volts till it gets to a max of 5.0 V using buttonA and decrease the brightness of the LED by 0.5 volts with buttonB. The Problem I have is that when I push buttonA the LED steps it's voltage by 0.5V all the way to 5.0V and with buttonB its steps down to 0. I would like to have the LED step each time I press the button not all at once. Here is my code that I have so far can someone help me with telling the Arduino to Step each time a button is pressed. CODE IS DIFFERENT from another post I did

HERE is my code:

int ledPin = 9; // must be a PWM digital pin
int buttonApin = A2; //buttonA to analog 2
int buttonBpin = A1; // buttonB to analog 1
int maxBright = 255; // between 0 and 255
int ms = 1500;    // delay in milliseconds
int buttonPushCounterA = 0; //counter for the number of button presses
int buttonStateA = 0; // current state of the button
int lastButtonStateA = 0; // previous state of the button
int buttonPushCounterB = 0; //counter for the number of button presses
int buttonStateB = 0; // current state of the button
int lastButtonStateB = 0; // previous state of the button

void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(buttonApin, INPUT_PULLUP);
  pinMode(buttonBpin, INPUT_PULLUP);
}

void loop()
{
  if (digitalRead(buttonApin) == LOW) //if buttonA is pushed
   {
      buttonStateA = digitalRead(buttonApin);

     if (buttonStateA != lastButtonStateA)
     {
        if(buttonStateA == LOW)
     {
        buttonPushCounterA++;
     }
    }

// fade from min to max in increments of 25.5 points: basically (0.5 volts)
for (float n = 0; n <= maxBright; n +=25.5)
{
 // sets the value (range from 0 to 255):
 analogWrite(ledPin,n);
 delay(ms);
}
  }

  if (digitalRead(buttonBpin) == LOW) //if buttonB is pushed
  {
     buttonStateB = digitalRead(buttonBpin);

       if (buttonStateB != lastButtonStateB)
         {
            if(buttonStateB == LOW)
              {
                buttonPushCounterB--;
              }
         }

     // fade from max to min in increments of 25.5 points: basically (0.5 volts)
     for (float n = maxBright; n >= 0; n -= 25.5)
    {
     // sets the value (range from 0 to 255):
     analogWrite(ledPin, n);
     delay(ms);
    }
  }

  lastButtonStateA = buttonStateA;
  lastButtonStateB = buttonStateB;
 }


texts: which kind of data are store If i terminate the call in sim800?

texts:
I'm working in SIM800 for DTMF based project.
I want to know which kind of data are stored in the buffer during termination of call in SIM800.
How to find if call was disconnected in SIM800?
Also please suggest some AT-COMMAND tester software and DTMF codes for my reference.


texts:
I'm new to Arduino and today I have a problem with this code:

int led_1 = 10;
int led_2 = 11;
int led_3 = 12;
int button = 3;
int time = 0;
byte val = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(led_1, OUTPUT);
  pinMode(led_2, OUTPUT);
  pinMode(led_3, OUTPUT);
  pinMode(button, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  val = digitalRead(button);

  if (val == HIGH){
    time = millis();
    while (digitalRead(button) == HIGH) {
      if (millis() - time < 1000) {digitalWrite(led_1, HIGH);}
      else if (millis() -time > 1000 && millis()-time <2000) {digitalWrite(led_2, HIGH);}
      else if (millis()-time >2000) {digitalWrite(led_3, HIGH);}
    }
  } else {
    time =0;
    digitalWrite(led_1, LOW);
    digitalWrite(led_2, LOW);
    digitalWrite(led_3, LOW);
    }
}

The code should work like this: If I press the button less than one second, led_1 will turn on. If I press it between one and two seconds, led_2 will turn on; and if I press the button more than 2 seconds, led_3 will turn on. If I don't press a button, the LEDs remain off. The time variable is used to take the time when I start to press the button and then the control millis()- time should give how long I press the button.

It works for a while, then after a random time (I think) if I push the button, only the led_3 turns on. Why?


texts: ESP 8266 HTTP Client Data is not changing correctly

texts:
I'm Trying to control a pin "D1" from HTTP API everything was working fine but when i'm going to change the data from server it's done on the server but on device it's takes so long time almost 20 minutes i also checked the Serial Monitor the data is not updating please help me.

My Device: Node MCU V3,

Here is my code:

/**
   BasicHTTPClient.ino

    Created on: 24.05.2015

*/

#include <Arduino.h>

#include <Arduino_JSON.h>

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#include <ESP8266HTTPClient.h>

#include <WiFiClient.h>

ESP8266WiFiMulti WiFiMulti;

void setup() {

  Serial.begin(115200);
  // Serial.setDebugOutput(true);

  Serial.println();
  Serial.println();
  Serial.println();

  pinMode(D1, OUTPUT);

  for (uint8_t t = 4; t > 0; t--) {
    Serial.printf("[SETUP] WAIT %d...\n", t);
    Serial.flush();
    delay(1000);
  }

  WiFi.mode(WIFI_STA);
  WiFiMulti.addAP("Maruf Hasan", "marufhasan");

}

void loop() {
  // wait for WiFi connection
  if ((WiFiMulti.run() == WL_CONNECTED)) {

    WiFiClient client;

    HTTPClient http;

    Serial.print("[HTTP] begin...\n");
    if (http.begin(client, "http://marufhasan.net/api/test.txt")) {  // HTTP

      Serial.print("[HTTP] GET...\n");
      // start connection and send HTTP header
      int httpCode = http.GET();

      // httpCode will be negative on error
      if (httpCode > 0) {
        // HTTP header has been send and Server response header has been handled
        Serial.printf("[HTTP] GET... code: %d\n", httpCode);

        // file found at server
        if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
          String response = http.getString();
          //Converting response object;
          Serial.println(response);
          JSONVar myObject = JSON.parse(response);

          if (JSON.typeof(myObject) == "undefined") {
            Serial.println("Parsing input failed!");
          }else{
            if (myObject.hasOwnProperty("status")) {
              String status = (const char*) myObject["status"];

              if(status=="on"){
                    Serial.println("ON");
                    digitalWrite(D1, HIGH);
              }else{
                    Serial.println("OFF");
                    digitalWrite(D1, LOW);
              }

            }
          }
        }
      } else {
        Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
      }

      http.end();
    } else {
      Serial.printf("[HTTP} Unable to connect\n");
    }
  }

  delay(5000);
}


texts:
this is my first post here. Before I ask you my problem, I'm sorry if I'm wrong to write but my English is bad.

So, my problem is this: I'm developing a "client-server" system with serial communication between my computer and the NodeMCU. The PC will send a message (an integer) to the Node which makes certain things based on the number. At the end of the work the Node will send an ACK to the server (an integer).
I programmed the NodeMCU using the Arduino tool and in the first preliminary tests everything worked: the Node received and answered correctly. Then I wrote a script in Python to automate the thing and that's where the problems start. Communication takes place correctly but the messages that the Node sends to the PC are dirty. At the beginning of the buffer there are some illegible bits while at the end of the buffer there is the correct message. I did the same test with the Arduino Uno and this works perfectly.

Can you give me a reason for this problem and in case a solution?
Thanks in advance!

NodeMCU:

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

void loop( )
    {
        if( Serial )
            {
                Serial.write( (int)12 );
            }
    }

Python:

#!/usr/bin/python
import serial

port = '/dev/cu.wchusbserial1420'

ard = serial.Serial(port,9600,timeout=5)

x = ard.read(1)
x = int( x )

print x

(I am attaching some screenshots)


texts: Is there a particular function in the library TinyGPS or TinyGPS Plus which outputs the raw NMEA sentences? I couldn't find anything about it on the website guide of the library.


texts: Negative voltage output Or Controling negative voltage

texts:
I've got an RGB led strip I'm trying to control. It's a 12v, 4 pin strip.
Pin layout seems rather odd to me as 1 pin takes 12v of power and 3 pins (that go to ground) control the colors. In other words, the LED colors are controlled by limiting outgoing voltage.

White- +12v
Green- Green in negative voltage
Red - Red in negative voltage
Blue - Blue in negative voltage

I've already made a similar setup that uses n-channel MOSFETS (or at least I think that's what they are) between the colored cables and the ground and Arduino power the MOSFET gates as necessary.

So my question is: is it possible to hook these LEDs up directly to arduino and control the negative voltage without aditional electronics?

As a slightly off topic question: Is there a specific name for elements that are controlled with negative voltages.

By the way, I'm using Arduino nano, although I don't think it is relevant at this point and I've got Mega and Uno aswell if needed.


texts: Unable to upload the data on thingspeak using uno and esp8266

texts:
I am able to connect to thingspeak but now able to upload the data. here are my set of commands:

AT+CIPMUX=0
OK

AT+CIPSTART="TCP","184.106.153.149", 80
OK
Linked

AT+CIPSTATUS
STATUS:3
+CIPSTATUS:0,"TCP","184.106.153.149",80,0
OK

AT+CIPSEND=45
> GET /update?api_key=DXDPC4MLXMXFB5TT&field1=60

busy s...

SEND OK

OK

and after some time unlink

I am giving these commands using arudino serial monitor.
Please help, I have searched a many blogs, youtube videos.


texts:
I am considering using an Arduino as a controller for a water treatment system and would love to hear your opinions. All it has to do is open/close a water gate (by starting/stopping a motor) at predefined times. It would have to...

Be able to connect to a phone using a usb cable. The phone would act as a UI to change settings and water flush times on the Arduino (via a custom app)
Log data which would be easily retrievable
Ideally, be able to connect to a cell network and send/receive packets. I believe there is a shield for this
Consume MINIMAL POWER. All it has to do is flush once every few days, log data, and possibly receive data from shield/usb. It would be running off of a solar panel and battery. In winter it could run out of power.

And thats pretty much it! Can this project be done with an Arduino? I would greatly appreciate any advice and recommendations!


texts: I need to measure mass air flow in a tube (and get Arduino to read it). Someone suggested me to use a mass air flow sensor (MAF). The problem is that the tube diameter of these devices is way too large for my project. My tubing have a diameter of approximately 5 mm. Is there any other way measuring mass air flow in these conditions or any small MAF sensor that I could use?


texts:
I would like to make a small project, which would allow me to recognize if the grass has grow enough to lawn. I don't know too much the ecosystem of available sensors for such problem. And I have a lot of grass and some irregular areas to clean once in a while.

Is that something I can do with an arduino and some sensors, or should I need to use more processing power and cameras/AI?

TIA!


texts: Non-Linear readings on Analog Pin A0 vs. other Pins A1

texts:
I discovered a curios behavior of my Nano v3. The analog Pin A0 seems to measure data in a non-linear way while the other pins seem to work normal.

Please have a look at the screenshot. This is the normal ReadAnalogVoltage example with a 50K potentiometer. A1 (red line) raise and falls linear when turning the knob. But the A0 line (blue) does not.

Is there a way to change it back to the normal behavior? Some weeks ago it worked fine on A0 as well. So these results are quite surprising for me. In general it would have been easy using another pin, but I already created a pcb which utilize A0.

Thanks


texts: Arduino Uno - ESP 8266: sending AT commands via Code

texts:
I bought a ESP 8266 & I am able to send AT commands and receive response via serial monitor when I upload a empty sketch. I changed the baud rate from 115200 to 9600 by using AT+CIOBAUD=9600 and am able to run AT commands at 9600 baud rate.

Empty Sketch:

void setup()
{

}
void loop()
{

}

Here is how my circuit looks:

Problem

The problem is when I create a custom sketch to run AT commands it doesn't work. Here is how my sketch looks:

#include <SoftwareSerial.h>
SoftwareSerial esp8266(0,1); //RX,TX

void setup()
{

  Serial.begin(9600);
  esp8266.begin(9600);

  Serial.println("Run AT Command");

   esp8266.print("AT\r\n");

}

void loop(){
   String response = "";
   while(esp8266.available())     {
        char c = esp8266.read();
        response+=c;
        Serial.print(c);
      }

      if(response != ""){
        Serial.println(response);
      }

}

ESP8266 is receiving 3.3V but I have read TX and RX sends 5V, and they also need to be 3.3V. Don't know if thats what is causing it, but I am able to run AT commands on empty sketch, so this is a bit weird.

  UPDATE:

My sketch is:

#include <SoftwareSerial.h>
SoftwareSerial esp8266(2, 3); //RX,TX

void setup()
{

  Serial.begin(9600);
  esp8266.begin(9600);

  esp8266.print("AT\r\n");

}

void loop() {
  String response = "";
  while (esp8266.available())     {
    char c = esp8266.read();
    response += c;
  }

    if (response != "") {
      Serial.println("Response: " + response);
    }

}

Serial Monitor shows this:

Response: A
Response: T

OK
Response:

OUTPUT when I run AT+CIFSR command:

Response: A
Response: T+CIFSR

Response:
+CIFSR:APIP
Response: ,"192.168.4.1
Response: "
+CIFSR:APMA
Response: C,"5e:cf:7f:80
Response: :f7:74"

OK

Question now is: How do I store the string being returned from the esp8266. I thought my response string was suppose to store the "OK" but that did not happen.


texts: 5V 10A 4 channel relay to 2 lights15W light in series in 220V AC supply

texts:
I am trying to setup my first relay module with live environment. I have attached the relay module image below.

Which I am using to control 4 devices in my switch board as follows:

Fan (working fine),
6w celling LED panel (2 connected in series) (Working fine)
15w celling LED panel (2 connected in series) (Sometimes work sometimes don't)
Spotlights 3 lights in series and some LED strips connected to it (Sometimes works sometimes don't.).

I have cut one wire which is connected to main normal mechanical switch WHICH IS NOT A HOT WIRE its just the another wire connected to the button.

But I am not sure why its not working? Do I need to connect neutral to the another end of the relay. As I have only 2 wires connected to the relay for each of the switches. Here is a screenshot of specifications 15watt LED panel which is connected to my house, if this can help to understand better.

If I connect Neutral on the first pin of relay and when I close the relay switch, do the current will go into the neutral wire as well?

If I keep my 3w spotlights ON or more then 3-4 hours and try to close the relay on connected to it. The relay LED light for that connected relay goes OFF but the light don't. Seems like the mechanical relay is not getting enough power to move the mechanical relay off.

I want to know why this is happening? And how can I solve this issue? Attaching a neutral (earth) wire will help to reduce this? But if connect neutral to first (off side of relay) pin, then will get the current?

Any suggestions will be helpful. Also I added 3.3v from NodeMCU to VCC (instead of jumper) pin. But that is also not helpful.


texts:
Is it possible to capture good sound with Aduino? I need to record street / birds / nature sounds.

As I found, maximal sample rate, achievable with built-in ADC is 9kHz, which is to low.

So, I require to use some external hardware. But wave shields I saw are to expensive (comparable by price with Arduino itself), probably, because of excess functions (including not only ADC but also DAC and so on).

Simultaneously, there are ICs, providing ADC functionality and even MP3 encoding functionality for relatively low price. But here a schematic design required.

So, how to find appropriate solution here?


texts:
I know a global JsonObject shouldn't be used, but I have my reasons.

I have a JsonObject* functions and I want him to save the content of a file.
With

functions=new JsonObject(jsonBuffer.as<JsonObject>());

I can access the JsonObject, but not when I leave the method. Can someone help me to understand why?
(Don't give me a solution like: copy into a struct, I need a JsonObject ready to be read in all my code.

Full code:

JsonObject* functions;

void loadFunctions() {
  File file = SPIFFS.open("/functions.json", "r");
  if (!file) {
    Serial.println("Failed to open the file");
  }else{
    size_t size = file.size();
    if (size > 512) {
      Serial.println("File size is too large");
    }else{
      std::unique_ptr<char[]> buf(new char[size]);
      file.readBytes(buf.get(), size);
      DynamicJsonDocument jsonBuffer(256);
      DeserializationError error = deserializeJson(jsonBuffer, buf.get());
      if (error) {
        Serial.println("Failed to parse file ");
      } else {
        functions=new JsonObject(jsonBuffer.as<JsonObject>());
        Serial.println((*functions)["test"].as<String>()); //this doesn't work in another method
      }
    }
  }
}


texts: Does the reset button work when not powered?

texts: I'm working on a project and my dad hit the reset button on my Arduino board, unknowingly. If it wasn't connected to any power source or computer, did it still reset? Do I have to upload my code to the board again? Or does the board need power to be reset?


texts: How can I scan for a HIGH signal on digitalRead during the main loop, while running other things?

texts:
I'm working on a program which listens for certain bytes on serial through an if/then/elseif ladder. I want to also check if a pin (say, A15) has been given a HIGH state, by another Arduino with shared ground. The slave Arduino will turn a digital pin to HIGH and I want the MEGA2560 to check every time it loops if a HIGH is present from the other board. A "While button not pressed do nothing statement won't work, because that won't let the loop go. I tried doing an if statement, using something to the effect of this:

if (digitalRead(A15)==HIGH) {
  //things to do
}

But it seems no matter what I put, be it HIGH, LOW, != HIGH, != LOW, etc. or either input pinmodes, pullup or not, it always thinks the board is transmitting HIGH. In fact, it only doesn't think it's HIGH when it actually is HIGH. I'm pretty stumped on this. If you ask me, digitalRead is really odd with what's HIGH and what's LOW.


texts:
char *p = I2CinBuffer; // array contains "string" "," "string"

but

char *p = I2CinBuffer; // The data to be parsed e.g. 6,100
char *str;       // Temp store for each data chunk
int count = 0;

while ((str = strtok_r(p, ",", &p)) != NULL)    // seperate at each "," delimiter
{
    inParse[count] = str;      // Add chunk to array
    count++;
}

does not enter while loop.

Many thanks but the hard coding of the values "6,100" give correct results as it stands. However, I am now aware that the Arduino code is working in C strings and I2CInBuffer is a C string on which the "strtok" or "strok_r" functions will NOT work. My question now is how to parse the C string I2CinBuffer to obtain 2 values separated by a comma i.e. "6, 100".


texts: What happens to serial output when no-one is listening?

texts:
This question probably needs a better title but I'm having trouble thinking of one! Please feel free to edit or suggest one.

My target system is a pair of Arduino Leonardos linked by XBee radios. One is the coordinator and is expected to communicate with a host PC over the USB connection (virtual serial port). The coordinator parses commands and potentially forwards them on to the endpoint by radio. The endpoint replies to commands and can also generate output spontaneously. Both devices can also send diagnostic output to the USB/Serial port. The endpoint sends "heartbeat" messages every 8 seconds. If the coordinator misses 2 consecutive heartbeats then it'll reinitialize. If the endpoint sends a heartbeat and doesn't get a response within a couple of seconds, then it will also reinitialize.

This all seems to work pretty well, but I've noticed something odd. If I connect to both devices with a terminal emulator and just watch the output, everything is good and the system is stable for at least 14 hours (the longest I've tested it). I can see the heartbeat messages happening and the diagnostic output coming out. However, as soon as I disconnect one of the serial ports, things begin to fail. The XBee comms state machine appears to time out at both sides and goes into an endless re-initialization loop.

I'm struggling to think why this might be, but disconnecting one of the serial ports reliably causes the issue within 10 to 20 seconds (I think the "no heartbeat" timeout is being hit).

It seems like if nothing is listening to the serial port, something is getting jammed up. My understanding is that its OK to read from and write to a port that nothing is connected to, and that data will just fall into the bitbucket. Is this not the case? Why should disconnecting the client from the serial port jam everything up?

UPDATE: I've tested with this modified "blink" sketch:

#include <Arduino.h>

auto& host = Serial;

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  host.begin(115200);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
  host.print("Time ");
  host.println(millis());
}

With something (PuTTY) connected to the USB/serial port, I get a nice even mark-space ratio on the LED. As soon as I disconnect PuTTY, the 'off' period of the LED becomes about twice as long as the 'on' period, i.e. there is upwards of a second delay each time I write to the serial port. Is that normal?


texts:
Hello I have a String that contains the following: "println('hello world')".
I want to be able to remove everything from the String except for the text insie the brackets. Bear in mind that this text will change multiple times as the programme runs. How can I remove everything except for what is in the brackets from the string.

    String line1 = "println('hello world')";

Please help me thx.


texts: Sending data using Bluetooth SPP-C Module without a Breakout-Board

texts:
tl;dr

I can't send data using the raw SPP-C Bluetooth module without a breakout board.
The communication via UART works fine as I am able to issue AT commands and get proper responses.
But when connected over Bluetooth the data passed over UART does not show up on my computer while the other direction works fine.
Has anyone tried that module yet without using a breakout board?

The long story:

I started my project by using a regular HC-05 module on a breakout board. The prototype worked just fine as there are also plenty tutorials available. The drawback using that breakout module is that it works with two voltages, 5V for power and 3V3 for communication. I have also more components in my project that run best at 3V3. That is why it came to my mind to use 3V3 as the only voltage. The raw HC-05 module without breakout board is also powered with 3V3. So everything looked just perfect.

Looking at the specs to the HC-05 I noticed that there is also more on that module like SPI and USB (page 12 bottom). So I got curious and off track.

Anyway. Instead of ordering raw HC-05 modules without breakout board I ordered cheaper SPP-C modules that don't have all this fancy stuff but just UART communication.

Following the description from Martyn Currey I was quicky able to issue AT commands and receive data over bluetooth. But I am not able to send data over Bluetooth.

I am using the same setup as it is shown on page 4 in the Chinese datasheet. (no I can't read that crazy symbols but I can read and understand the images)


texts: Is it possible to put ATtiny85 to sleep while using TinywireS?

texts:
I have an arduino uno as the master I2C device talking to an ATtiny85 as the slave.
What I want to do is have the Attiny85 receive a message from the UNO to tell it to power off which will then trigger a mosfet to turn all the power off to the UNO and then sleep for a period of time.
This all seems to be working fine but every now and then I seem to get a lock up where the UNO just stays on.
Is what I am doing below ok. I am worried about TinyWireS_stop_check() call and if that is going to be messed up by the fact I have delays in the loop and also the fact it goes to sleep.

Thanks

// Code for the ATtiny85
#include <powernap.h>
#include <TinyWireSlave.h>

#define I2C_SLAVE_ADDRESS 0x4 // Address of the slave
#define POWER A3
// The default buffer size, Can't recall the scope of defines right now
#ifndef TWI_RX_BUFFER_SIZE
#define TWI_RX_BUFFER_SIZE ( 16 )
#endif

uint8_t sleepInterval = 1;
bool cycleComplete = false;
bool sleepNow = false;

Napper napper;

enum InterComms
{
    IDLE = 0,
    PWR_OFF = 1,
    CALIBRATION_MODE = 2,
    SLEEP_INTERVAL = 3,
    KEEPALIVE = 4
};

char rxChrData; //Receives the data.
char rxString[12];  //Varbiable for holding one string of data.
int rxIndex = 0; //Used to index rxString.
int i = 99;
bool calibrationMode = true; //Always true when power is turned on

void requestEvent()
{
    TinyWireS.send(calibrationMode);
}

void receiveEvent(uint8_t howMany)
{
    if (TinyWireS.available()) {
        if (howMany < 1)
        {   // Sanity-check
            return;
        }
        if (howMany > TWI_RX_BUFFER_SIZE)
        {   // Also insane number
            return;
        }

        howMany--;
        uint8_t byte = TinyWireS.receive();
        switch (byte)
        {
        case PWR_OFF:
            i = 100;
            sleepNow = true;
            break;
        case CALIBRATION_MODE:
            calibrationMode = true;
            i = 110;
            break;
        case SLEEP_INTERVAL:
            i = 120;
            howMany--;
            sleepInterval = TinyWireS.receive();
            break;
        case KEEPALIVE:
            i = 130;
            measureTimer = millis();
            break;
        default:
            i = IDLE;
            break;
        }
        //Make sure buffer is emppty
        while(howMany--)
            TinyWireS.receive();
    }
}

void setup()
{
    pinMode(POWER, OUTPUT);
    analogWrite(POWER, 255);

    TinyWireS.begin(I2C_SLAVE_ADDRESS); // join i2c network

    TinyWireS.onReceive(receiveEvent); // not using this
    TinyWireS.onRequest(requestEvent);

    napper.setup();

    measureTimer = millis();
    return;
}

void loop()
{
    unsigned long currentMillis = millis();

    TinyWireS_stop_check();

    if (sleepNow)
    {
        sleepNow = false;
        tws_delay(2000);
        cycleComplete = true;
        calibrationMode = false;
        analogWrite(POWER, 0);
        tws_delay(200);
        napper.napminutes(sleepInterval);
        analogWrite(POWER, 255);
        cycleComplete = false;
        //Reset timer
        measureTimer = millis();
    }

    if ((unsigned long)(currentMillis - measureTimer) > (300000) /*&& !cycleComplete*/)
    {
        analogWrite(POWER, 0);
        tws_delay(1000);
        analogWrite(POWER, 255);
        measureTimer = millis();
    }
}


texts: Bad Data : Arduino Mega & NodeMCU Serial Communication

texts:
Currently I am working on an Arduino project. The project required to establish communication between Arduino Mega and NodeMCU ESP8266. Here are some details about the project:

NodeMCU Rx Pin is connected to Arduino Mega Pin 14 (Tx3), while NodeMCU Tx Pin is connected to Arduino Mega Pin 15 (Rx3), Jumper Wires is used to connect NodeMCU and Arduino Mega
Both Arduino Mega and NodeMCU are using baud rate 115200

Code for NodeMCU ESP8266 (Send The Data to Arduino Mega):

void loop(){
       esp.println("0000");

       esp.flush();
}

Code for Arduino Mega (Receive Data) :

 if(Serial3.available()){

  data = Serial3.readStringUntil('\n');

  Serial3.flush();

  Serial.println(data);

}

The result :

The intented and expected result is "0000", however, the result shown in serial monitor is not accurate. Anyone could advise?


texts:
I have an nmake file;

  srcpath = ..\pilot
  cmdline =  "C:\Program Files (x86)\Arduino\arduino.exe"
  cmdflags = --verify  --board arduino:avr:uno --port com4 -v --preserve-temp-files
  prefs = --pref sketchbook.path=$(srcpath) --pref build.path=build
  deps = $(srcpath)\pilot.ino $(srcpath)\commands.h $(srcpath)\publish.h $(srcpath)\motor.h

  pilot.hex :$(deps)
    type $(srcpath)\pilot.ino
    $(cmdline) $(cmdflags) $(prefs) $(srcpath)\pilot.ino

The file types out fine, but Arduino returns an error;

"failed to open sketch ..\pilot\pilot.ino"

I am setting --pref sketchbook.path=$(srcpath), but I have tried with and without (and many variations of both) and get the same error.

This is the command that is currently being invoked, and looks correct to me;

"C:\Program Files (x86)\Arduino\arduino.exe" --verify  --board arduino:avr:uno --port com4 -v --preserve-temp-files --pref sketchbook.path=..\pilot --pref build.path=build ..\pilot\pilot.ino

Any ideas?


texts: I am using I2C to communicate between a collection of ATtiny85s that are acting as controllers for various parts of a system and the "Main Brain" -- a RaspberryPi. Most of the ATtiny85s only have a couple of free pins left (usually Pins 1 and 2 -- the reset and the pin that can't be used for PWM) so I can't use something like a DIP switch to directly set device IDs. I'd rather not hardcode the device IDs when I push code to the tinys but I can't think of a good, simple, and reliable way to do it otherwise. Anyone here have a suggestion?


texts: Arduino Yun Disk Expander low memory but it looks like my memory is fine

texts:
I can't quite understand this when I run arduino yun disk expander sketch with a sd card plugged in I get the the following message. You do not have enough flash memory need 1mb. I ssh into my arduino and I get this
Filesystem                Size      Used Available Use% Mounted on
rootfs                    6.9M    632.0K      6.3M   9% /
/dev/root                 7.5M      7.5M         0 100% /rom
tmpfs                     29.8M    148.0K     29.7M   0% /tmp
tmpfs                     512.0K       0    512.0K   0% /dev
/dev/mtdblock3            6.9M    632.0K      6.3M   9% /overlay
overlayfs:/overlay        6.9M    632.0K      6.3M   9% /
/dev/sda1                29.7G      2.4M     29.7G   0% /mnt/sda1

The only thing that is full is the /dev/root but the reading I have done through the posts here and online say that's fine. Why may this be I am quite confused???


texts: How does input from IR receiver to Arduino UNO board work?

texts:
I have a very simple circuit with an Elegoo IR receiver module connected to an Arduino UNO. The three wires are connected correctly with the data wire (Y) connected to pin 8. The code works fine, as every time I press button on the remote, the Serial Monitor displays the corresponding button description.

However, I do not understand how Arduino's pin 8 knows which IR button has been pushed. My understanding is that pin 8 can read either 5V or 0V, but to know which of 20+ remote buttons has been pushed it would have to read PWM. But pin 8 does not the PWM icon next to it and yet it works fine. Unless the PWM icon applies only to pin output? Or is there another way I have failed to find info about?

Thanks!


texts: Error on UNOr3--> avrdude: ser_open(): can't open device "/dev/ttyUSB0": No such file or directory ioctl("TIOCMGET"): Inappropriate ioctl for device

texts:
When I try to upload my program on the Arduino Uno Chinese clone, It says

 -> avrdude: ser_open(): can't open device "/dev/ttyUSB0": No such file or directory
ioctl("TIOCMGET"): Inappropriate ioctl for device

My Arduino Programmer: ArduinoISP
My Arduino Software version: 1.6.8
My OS: Linux Mint

Can you help me fix this error?


texts:
ım building a rover and ı using Johson 12v Dc motor and VNH2SP30. My code and motor works perfectly but my motor driver works only one way. It cant go to reverse and motor starts buzzing when it tries to go in reverse. Here is the code ım using for testing.

#define BRAKE 0
#define CW    1
#define CCW   2
#define CS_THRESHOLD 15   // Definition of safety current (Check: "1.3 Monster Shield Example").

//MOTOR 1
#define MOTOR_A1_PIN 7
#define MOTOR_B1_PIN 8

#define PWM_MOTOR_1 5

#define CURRENT_SEN_1 A2

#define EN_PIN_1 A0

#define MOTOR_1 0

short usSpeed = 150;  //default motor speed
unsigned short usMotor_Status = BRAKE;

void setup()
{
  pinMode(MOTOR_A1_PIN, OUTPUT);
  pinMode(MOTOR_B1_PIN, OUTPUT);

  pinMode(PWM_MOTOR_1, OUTPUT);

  pinMode(CURRENT_SEN_1, OUTPUT);

  pinMode(EN_PIN_1, OUTPUT);

  Serial.begin(9600);              // Initiates the serial to do the monitoring
  Serial.println("Begin motor control");
  Serial.println(); //Print function list for user selection
  Serial.println("Enter number for control option:");
  Serial.println("1. STOP");
  Serial.println("2. FORWARD");
  Serial.println("3. REVERSE");
  Serial.println("+. INCREASE SPEED");
  Serial.println("-. DECREASE SPEED");
  Serial.println();

}

void loop()
{
  char user_input;

  while(Serial.available())
  {
    user_input = Serial.read(); //Read user input and trigger appropriate function
    digitalWrite(EN_PIN_1, HIGH);

    if (user_input =='1')
    {
       Stop();
    }
    else if(user_input =='2')
    {
      Forward();
    }
    else if(user_input =='3')
    {
      Reverse();
    }
    else if(user_input =='+')
    {
      IncreaseSpeed();
    }
    else if(user_input =='-')
    {
      DecreaseSpeed();
    }
    else
    {
      Serial.println("Invalid option entered.");
    }

  }
}

void Stop()
{
  Serial.println("Stop");
  usMotor_Status = BRAKE;
  motorGo(MOTOR_1, usMotor_Status, 0);
}

void Forward()
{
  Serial.println("Forward");
  usMotor_Status = CW;
  motorGo(MOTOR_1, usMotor_Status, usSpeed);
}

void Reverse()
{
  Serial.println("Reverse");
  usMotor_Status = CCW;
  motorGo(MOTOR_1, usMotor_Status, usSpeed);
}

void IncreaseSpeed()
{
  usSpeed = usSpeed + 10;
  if(usSpeed > 255)
  {
    usSpeed = 255;
  }

  Serial.print("Speed +: ");
  Serial.println(usSpeed);

  motorGo(MOTOR_1, usMotor_Status, usSpeed);
}

void DecreaseSpeed()
{
  usSpeed = usSpeed - 10;
  if(usSpeed < 0)
  {
    usSpeed = 0;
  }

  Serial.print("Speed -: ");
  Serial.println(usSpeed);

  motorGo(MOTOR_1, usMotor_Status, usSpeed);
}

void motorGo(uint8_t motor, uint8_t direct, uint8_t pwm)         //Function that controls the variables: motor(0 ou 1), direction (cw ou ccw) e pwm (entra 0 e 255);
{
  if(motor == MOTOR_1)
  {
    if(direct == CW)
    {
      digitalWrite(MOTOR_A1_PIN, LOW);
      digitalWrite(MOTOR_B1_PIN, HIGH);
    }
    else if(direct == CCW)
    {
      digitalWrite(MOTOR_A1_PIN, HIGH);
      digitalWrite(MOTOR_B1_PIN, LOW);
    }
    else
    {
      digitalWrite(MOTOR_A1_PIN, LOW);
      digitalWrite(MOTOR_B1_PIN, LOW);
    }

    analogWrite(PWM_MOTOR_1, pwm);
  }
}


texts: Read speed between two ultrasonic sensors

texts:
I'm new to Arduino and in need of help for this small project.

I'm trying to build an Arduino code that reads the speed of an object passing through two ultrasonic sensors. The plan now is to ping the first ultrasonic sensor once an object passes. The second sensor will then activate and wait for the object to pass by. The time it takes to reach the second sensor will be given into the equation.

Speed will be calculated by the distance between the two ultrasonic sensors divided by the time for the object to reach the second sensor. I would like to display the speed if possible on my computer screen.

Here is my code so far. Any help will be appreciated:

int trig1 = 3; //Trig 1
int trig2 = 4; //Trig 2
int echo1 = 5; //echo1
int echo2 = 6; //echo2
int ECHO1;
int ECHO2;
double first_time;
double second_time;
double final_time;
double speed;

void setup()
{
   pinMode(trig1, OUTPUT);  //sets the digital pin 3 as output
   pinMode(trig2, OUTPUT);  //sets the digital pin 4 as output
   pinMode(echo1, INPUT);  //sets the digital pin 5 as input
   pinMode(echo2, INPUT);  //sets the digital pin 6 as input
}

void loop()
{
  ECHO1 = digitalRead(echo1);

  while (ECHO1 == 0)
  {
    digitalWrite(trig1,HIGH);
    delay(100);
    digitalWrite(trig1,LOW);
    ECHO1 = digitalRead(echo1);
  }

  first_time = time();

  ECHO2 = digitalRead(echo2);

  while (ECHO2 == 0)
  {
    digitalWrite(trig2,HIGH);
    delay(100);
    digitalWrite(trig2,LOW);
    ECHO2 = digitalRead(echo2);
  }

  second_time = time();

  final_time = second_time - first_time;

}


texts: Multiplexing HID and serial on ATMega32U4

texts:
I designed a custom ATMega32U4 based Arduino Leonardo board. I'm using MHeironimus/ArduinoJoystickLibrary to implement an HID joystick. I need to create also a virtual serial port to send NON joystick data to the USB host (Android device).
If I try to set use the usb serial the joystick device is not recognized.
If I stop the serial the joystick works fine.
This's the code:
#include <Arduino.h>
#include <Joystick.h>

#define JOYSTICK_PERIOD 20

const int BUTTON1_PIN = 4;
const int BUTTON2_PIN = 5;

int x = 0, y = 0, rx = 0, ry = 0, din = 0;
long time1, time2;

Joystick_ Joystick(
  JOYSTICK_DEFAULT_REPORT_ID,
  JOYSTICK_TYPE_GAMEPAD,
  2, 0,
  true, true, false,
  true, true, false,
  false, false,
  false, false, false
);

void setup()
{
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);

  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);

  Joystick.begin();
  Joystick.setXAxisRange(0, 1000);
  Joystick.setYAxisRange(0, 1000);
  Joystick.setRxAxisRange(0, 1000);
  Joystick.setRyAxisRange(0, 1000);

  time1 = millis();

  Serial1.begin(9600);
  Serial.begin(9600);
}

void SerialEvent()
{
  int _count = Serial.available();

  for(int _i=0;_i<_count;_i++)
    Serial1.write(Serial.read());
}

void Serial1Event()
{
  int _count = Serial1.available();

  for(int _i=0;_i<_count;_i++)
    Serial.write(Serial1.read());
}

void loop()
{
  time2 = millis();

  long _period = time2 - time1;

  time2 = time1;

  if(_period >= JOYSTICK_PERIOD)
  {
    din = (digitalRead(BUTTON1_PIN) << 1) | digitalRead(BUTTON2_PIN);

    x = analogRead(A0);
    y = analogRead(A1);
    rx = analogRead(A2);
    ry = analogRead(A3);

    Joystick.setButton(0, din);

    Joystick.setXAxis(x);
    Joystick.setYAxis(y);
    Joystick.setRxAxis(rx);
    Joystick.setRyAxis(ry);
  }
}

Anyone has hints?


texts:
I've just received my Uno today and already I think I may have broken it :(

I was able to connect to usb and upload a sketch (the blink). However, I then tried to connect a circuit to do the Hello World LCD example. After trying this a few times, I noticed the LCD chip get very hot...and I had mis-wired it. In any case, after a few more tries, the USB connection to my Arduino UNO stopped working.

I tried swapping the cable, connecting it to another mac and to a windows with no luck. I'm worried I may have shorted the USB bus chip when trying Hello World.

I also tried connecting a 12V DC power supply.

I still get the green power light and the amber L light...
Did I break my Uno?
How do I troubleshoot this one?
thanks


texts:
Im working on a project where I want to connect 32 servos together.
 I got:
-Arduino uno
-2 PCA9685 16-Channel 12-bit PWM/Servo Shield
-power supply 5v 10 A
-All wiring is to the right pins (I have checked that several times)

So I got the 2 PCA9685 16-Channel 12-bit PWM/Servo Shield from Adafruit I connected all the wires as its supposed to be and I connected the shield to an external power supply which is 5V 10A that should be sufficient for it to work but unfortunately servos are not moving at all although the serial monitor is giving numbers I don't know where is the problem coming from.
ps. Im using the Adafruit library
its not even moving one servo (although the servo moves when connected directly to the Arduino.
thank you in advance.

the code I'm using its one of the examples from the library:

/***************************************************
  This is an example for our Adafruit 16-channel PWM & Servo driver
  Servo test - this will drive 8 servos, one after the other on the
  first 8 pins of the PCA9685

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/products/815

  These drivers use I2C to communicate, 2 pins are required to
  interface.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
// you can also call it with a different address and I2C interface
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(&Wire, 0x40);

// Depending on your servo make, the pulse width min and max may vary, you
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you
// have!
#define SERVOMIN  150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  600 // this is the 'maximum' pulse length count (out of 4096)

// our servo # counter
uint8_t servonum = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("8 channel Servo test!");

  pwm.begin();

  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates

  delay(10);
}

// you can use this function if you'd like to set the pulse length in seconds
// e.g. setServoPulse(0, 0.001) is a ~1 millisecond pulse width. its not precise!
void setServoPulse(uint8_t n, double pulse) {
  double pulselength;

  pulselength = 1000000;   // 1,000,000 us per second
  pulselength /= 60;   // 60 Hz
  Serial.print(pulselength); Serial.println(" us per period");
  pulselength /= 4096;  // 12 bits of resolution
  Serial.print(pulselength); Serial.println(" us per bit");
  pulse *= 1000000;  // convert to us
  pulse /= pulselength;
  Serial.println(pulse);
  pwm.setPWM(n, 0, pulse);
}

void loop() {
  // Drive each servo one at a time
  Serial.println(servonum);
  for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) {
    pwm.setPWM(servonum, 0, pulselen);
  }

  delay(500);
  for (uint16_t pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--) {
    pwm.setPWM(servonum, 0, pulselen);
  }

  delay(500);

  servonum ++;
  if (servonum > 7) servonum = 0;
}


texts: Do I need a resistor to control a servo with a PWM signal?

texts:
I working with Arduino Nano Every that has several analog PWM pins. I want to use one to control a small servo.
Do I need to put a resistor between PWM pin and the servo signal?


texts: How can you count the number of interrupts that have taken place?

texts:
I'm trying to program a Timer Interrupt that will go off every 33 ms. I am doing this on the ATtiny85 which has a 20MHz clock. The maximum prescaler I can set is 32 so the longest possible time a single interrupt can be is 408 microseconds.

My plan to reach 33 milliseconds is to just run the interrupt 81 times and that will get me the desired 33 milliseconds. However, I have no clue as to how you can actually count how many time an interrupt has taken place. Anyone on here know how to do that or have any idea as to what would work?


texts:
I'm using a powerbump, input: 3.7v-6v Outputs: 3.3v, to provide the power I'm using 2 CR2025 coin cell batteries(3v each), meaning the powerbump gets 6v, the esp gets the exact 3.27v(I've measured with a multimeter),

But the chip still keeps on brownouting, when I start BLE on the chip


texts: Serial communication between GPS and Arduino Ethernet


texts: Accelstepper - how to switch from fullstep to halfstep in loop?

texts:
I am using Accelstepper library to control a unipolar stepper motor. In my project, I would like to run the stepper in full-step mode when I need speed and in half-step mode when I need precision. As you know, the full-step/half-step selection is done in the very beginning of the sketch...

I found a workaround by creating two instances of Accelstepper for the same stepper. That is:

Accelstepper fast(FULL4WIRE, 2,3,4,5);

Accelstepper slow(HALF4WIRE, 2,3,4,5);

With this, when I call (skipping other details of the code) fast.run() the motor moves fast (full-step) and when I call slow.run() it moves slowly as it is in half step mode.

But;

When it comes to determine to current motor position, this workaround fails, since there are two different values returned by the two functions: fast.currentPosition() and slow.currentPosition(). So this workaroud becomes useless.

My first question is: is there a way in Accelstepper to switch from full-step to half-step and vice versa in the execution(let say in the loop)? If so, the second question can be skipped.

The second: XX.currentPosition() function returns the value of a variable, namely "_currentPos" which is calculated in Accelstepper.cpp file. As I understand, there become, as many _currentPos values as Accelstepper instances. In my case, one for fast and another for slow, and somehow they are kept and calculated individually without any confusion. Is there a way to access (extern?) and set this variable from the sketch, by referencing the specific Accelstepper instence? Briefly, is there a way to copy one motor position to another?

Many thanks.


texts: Cannot send two arguments from a WebClient

texts:
I am using the Arduino WifiWebClient to insert records into a RoR (Ruby on Rails) app. It works but it only inserts one field regardless of the number of arguments I send.

For example, if I test with Curl

curl -d "sale[itemId]=1234&sale[machineId]=4567"  http://myapp.herokuapp.com/sales

It will create a Sale record and populate both fields itemId and machineId. Everything OK.

But when I send the following instruction from the Arduino, it will only populate the first field:

(I am only including the POST method to simplifly the code, the rest of the code is similar to http://arduino.cc/en/Reference/WiFiClient)

void sendPOST() //client function to send/receive POST request data.
{
if (client.connect(URL,PORT)) {  //starts client connection, checks for connection
Serial.println("connected");

Serial.println("POST /sales HTTP/1.1"); //download text
Serial.println("From: Arduino1");
Serial.println("Host: evening-sierra-3769.herokuapp.com");
Serial.println("User-Agent: HTTPTool/1.1");
Serial.println("Connection: close");
Serial.println("Cache-Control : no-cache");
Serial.println("Pragma: no-cache");
Serial.println("Expires: -1");
Serial.println("Content-Type: application/x-www-form-urlencoded");
Serial.print("Content-Length: ");
Serial.println(31);
Serial.println();
Serial.println("sale[machineId]=\"09876543211234\"");
Serial.println("sale[itemId]=\"09876543211234\"");
Serial.println();

client.println("POST /sales HTTP/1.1"); //download text
client.println("From: Arduino1");
client.println("Host: evening-sierra-3769.herokuapp.com");  // Will be needed if apache is configured for VHOSTS
client.println("User-Agent: HTTPTool/1.1");
client.println("Connection: close");
client.println("Cache-Control : no-cache");
client.println("Pragma: no-cache");
client.println("Expires: -1");
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.println(31);
client.println();
client.println("sale[machineId]=09876543211234\r\n");
client.println("sale[itemId]=09876543211234\r\n");
client.println();

Serial.println("ARDUINO: HTTP message sent");
delay(3000);
if(client.available())
{
  Serial.println("ARDUINO: HTTP message received");
  Serial.println("ARDUINO: printing received headers and script response...\n");

  while(client.available())
  {
    char c = client.read();
    Serial.print(c);
  }
}
else
{
  Serial.println("ARDUINO: no response received / no response received in time");
}

client.stop();
}


texts: Is this a good way of making a low power attiny? Unpower instead of sleeping

texts:
I am making a low power rf remote that just has 3 buttons and sends rf signals accordingly.

I've been trying to make pin interrupts work when it's in deep sleep but it's a huge hassle. And then I thought of this:

Is it a bad idea to do this?

I could imagine if you were too fast, you would shut the RF transmitter off while it's sending something, but that shouldn't be an issue because the user would notice nothing changed and will learn to press the button longer.

But the transmitter might also transmit too fast for a user to interrupt it.

And I don't know if debouncing is an issue here. I could just put a capacitor after the buttons.

Of course the code would be something like analogRead which button is pressed and then emit rf signals.

So my question is, is this bad practice and will this kill my battery/attiny/rf emitter?


texts: Safe to control multiple power sources through a switch through the ground?

texts:
I've attached the breadboard layout and schematic of a circuit I'm constructing, which is a simple Arduino radio control car, with a 9V powering the Arduino Uno, and the 6 volt battery pack feeding power to the motors via the L293D. My question is regarding the switch where I've connected the ground from both battery power supplies to one side, and connected the ground of the circuit to the other side. Is this OK and safe to do? Is there anything I should be concerned about with this setup? Is there a safer or better way to do this? What components added or removed (if any) would improve this circuit in terms of power safety and battery longevity?

In case you are wondering why I have two switches, the reason is because I wanted to debug the radio receiver using the serial monitor when I wired this to USB, but I also wanted to prevent it from powering up the motors so my project doesn't try and roll away while it's still connected to the USB cable. The switch I'm asking about in my question is sort of a mains power switch, so when it's off USB I can just flip on both switches and set the robot car free...


texts:
I'm trying to follow this tutorial.
But I'm stuck in this error:

Can't find OV2640 module! pid: 254

I tried to contact the author of the program, but I have not had an answer yet.
I'm using the ArduCAM Mini module OV2640.

Has anyone ever been in this situation?


texts:
Can someone please tell me what's going on with my LCD screen and how I can fix this issues below?

I have the following:

Arduino Uno R3 w/ ATMEGA 328P-PU
16x2 LCD
TowerPro MicroServo SG90
DPDT Slide Switch w/ 120 ohm resistor

Objective:
Read the sensor value (If switch is on or off), and move a servo accordingly while displaying switch state on LCD.

Issue:
LCD display seems to receive random data during program run (see image). All starts up well, and as soon as a few seconds have lapsed in the void loop(), the screen becomes garbled. Also, the switch value (while debugging) gets a zero reading while HIGH, acting accordingly as if the switch was off. The servo motor runs as it should, but gets random pulses every now and again where it starts to buzz, but doesn't turn.

Images:
Three images below.

Schematic:

Coding:

#include <LiquidCrystal.h>
#include <Servo.h>

const int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor
int oldPos = 0;
int pos = 0;
int oldStat = 0;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Servo servo;

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.setCursor (0, 0);
  lcd.print("Starting up FSS!");
  delay(700);
  lcd.clear();
  lcd.print("Init SERVO...");
  delay(500);
  servo.attach(9);
  lcd.clear();
  lcd.print("SERVO Success!");
  delay(400);
  lcd.clear();
  lcd.print("Testing SERVO...");
  servo.write(0);
  delay(200);
  servo.write(90);
  delay(200);
  servo.write(45);
  delay(300);
  lcd.clear();
  lcd.print("SERVO Running!");
  lcd.clear();
  lcd.print("Select AUX Source");
  pinMode(ledPin, OUTPUT);
}

void loop() {
  lcd.clear();
  lcd.setCursor (0, 0);
  lcd.print("Select AUX Src");
  lcd.setCursor(0, 1);

  sensorValue = analogRead(sensorPin);
  Serial.print("Sensor: ");
  Serial.println(sensorValue);

  if(sensorValue == 0){
    //if(sensorValue = oldStat){
      oldStat = sensorValue;
      digitalWrite(ledPin, LOW);
      lcd.print("Switch is OFF");
      pos = 45;

      Serial.println("Switch is OFF");
    //}
  } else{
    digitalWrite(ledPin, HIGH);
    lcd.print("Switch is ON");
    pos = 120;
    Serial.println("Switch is ON");
  }

  if (pos != oldPos){
    servo.write(pos);
  }

  oldPos = pos;

  delay (700);
}


texts: How can I implement double buffering with an Arduino UNO?

texts:
I am creating a tiny game on my Arduino UNO with an Adafruit ST7735 1.8" TFT / SD breakout. I am performing screen operations using the built-in TFT-library.

The problem is screen flickering. Even though I take care to prepare data and minimize the time between clearing the screen and writing the new stuff to it, the screen "refresh()" is significant. I heard someone mention something called double buffering, so I read a bit up on it, but I am frankly clueless on how to implement it on an Arduino UNO.

Is it possible to implement double buffering on an Arduino UNO to prevent screen flickering, and if so, how?

Libraries used:

#include <TFT.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>

The screen is "cleared" like this:

screen.background(0,0,0);  // Clear it
screen.text(buf, 10, 25);  // Write new stuff


texts: DC Motor will not work. Transistor method nor L293D!

texts:
New to Arduinos and stuff.
I have tried the L293D and the transistor method but the motor just wouldnt work.
I have tested the motor and it definitely is fine.
Below is my layout for this attempt:
Bits used:

Arduino UNO
1N4007 Diode
PN2222
230 ohm resistor

My sketch is ::
int motorPin = 3;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(motorPin, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (Serial.available()) {
    int speed = Serial.parseInt();
    if (speed >= 0 && speed <= 255) {
      analogWrite(motorPin, speed);
    }
  }
}

HELP!!!


texts: What's wrong? FastLED and WS2812B simulation works, physical build doesn't

texts:
I'm new to Arduino coding and FastLED. When it comes to coding, I'm a complete novice, however, I've been watching YouTube tutorials to help my knowledge. I have successfully run my code on Wokwi, however, when I upload my code to my Arduino, it uploads without error, yet the WS2812B doesn't run the code correctly and appears to freeze after the first pattern.
The LED strip works just run with my Adafruit code, running a very basic set of patterns I created (different than the below code).
Any help would be greatly appreciated! The code below is what I wrote up in Wokwi and the simulation works flawlessly. The only change when uploading to my Arduino is: NUM_LEDS  135
#include <FastLED.h>
#define NUM_LEDS  16
#define LED_PIN   5
#define BRIGHTNESS  255
#define caseCount 7
CRGB source1[NUM_LEDS];
CRGB source2[NUM_LEDS];
CRGB output[NUM_LEDS];

DEFINE_GRADIENT_PALETTE (christmasBlue_gp) {
  0, 0, 0, 255,
  64, 0, 0, 135,
  127, 255, 255, 255,
  191, 0, 0, 135,
  255, 0, 0, 255
};
CRGBPalette16 bluePal = christmasBlue_gp;

uint8_t blendAmount = 0;
uint8_t patternCounter = 0;
uint8_t source1Pattern = 0;
uint8_t source2Pattern = 1;
bool useSource1 = false;

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(output, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
}

void loop() {

  EVERY_N_MILLISECONDS(5) {
    blend(source1, source2, output, NUM_LEDS, blendAmount);
    if (useSource1) {
      if (blendAmount < 255) blendAmount++;
      } else {
      if (blendAmount > 0) blendAmount--;
      }
  }

  EVERY_N_SECONDS(5) {
    nextPattern();
  }
  runPattern(source1Pattern, source1);
  runPattern(source2Pattern, source2);
  FastLED.show();
}

void nextPattern() {
  patternCounter = (patternCounter + 1) % caseCount;
  if (useSource1) source1Pattern = patternCounter;
  else source2Pattern = patternCounter;
  useSource1 = !useSource1;
  }

void runPattern(uint8_t pattern, CRGB *LEDArray) {
  switch (pattern) {
    case 0:
      movingDots(LEDArray);
      break;
    case 1:
      whiteFill(LEDArray);
      break;
    case 2:
      greenFill(LEDArray);
      break;
    case 3:
      whiteFill(LEDArray);
      break;
    case 4:
      redFill(LEDArray);
      break;
    case 5:
      greenBlueTwinkle(LEDArray);
      break;
    case 6:
      greenRedSplit(LEDArray);
      break;
  }
}

void movingDots(CRGB *LEDarray) {
  uint16_t posBeat = beatsin16(30, 0, NUM_LEDS -1, 0, 0);
  uint16_t posBeat2 = beatsin16(60, 0, NUM_LEDS -1, 0, 0);
  uint16_t posBeat3 = beatsin16(25, 0, NUM_LEDS -1, 0, 127);
  uint16_t posBeat4 = beatsin16(45, 0, NUM_LEDS -1, 0, 127);
  LEDarray[(posBeat + posBeat2) / 2] = CHSV(0, 255, 255);
  LEDarray[(posBeat3 + posBeat4) / 2] = CHSV(120, 255, 255);
  LEDarray[(posBeat3 + posBeat2) / 2] = CHSV(120, 255, 255);
  LEDarray[(posBeat2 + posBeat4) / 2] = CHSV(0, 255, 255);
  LEDarray[(posBeat2 + posBeat4 + posBeat) / 3] = CHSV(0, 0, 255);
  fadeToBlackBy(LEDarray, NUM_LEDS, 1);
}

void whiteFill(CRGB *LEDarray) {
  fill_solid(LEDarray, NUM_LEDS, CRGB::White);
}

void greenFill(CRGB *LEDarray) {
  fill_solid(LEDarray, NUM_LEDS, CRGB::Green);
}

void redFill(CRGB *LEDarray) {
  fill_solid(LEDarray, NUM_LEDS, CRGB::Red);
}

void greenBlueTwinkle(CRGB *LEDarray) {
  EVERY_N_MILLISECONDS(50){
    LEDarray[random8(0, NUM_LEDS-1)] = ColorFromPalette(bluePal, random8(), 255, LINEARBLEND);
    }
  fadeToBlackBy(LEDarray, NUM_LEDS, 1);
  FastLED.show();
}

void greenRedSplit(CRGB *LEDarray) {
  for(int i = 0; i < NUM_LEDS; i++) {
    LEDarray[i] = CHSV(0, 255, 255);
    LEDarray[(NUM_LEDS-1-i)] = CHSV(120, 255, 255);
    FastLED.show();
    delay(100);
    LEDarray[i] = CHSV(0, 255, 255);
  }

  for(int i = NUM_LEDS - 1; i >= 0; i--) {
    LEDarray[i] = CHSV(120, 255, 255);
    LEDarray[(NUM_LEDS-1-i)] = CHSV(0, 255, 255);
    FastLED.show();
    delay(100);
    LEDarray[i] = CHSV(120, 255, 255);
  }
}


texts: COM port problem when uploading bootloader to SAMD21G

texts:
I use an ATSAMD21E16B-AU in my circuit and I want to upload the bootloader with the SAM-BA flash programming tool in this official link:
http://www.atmel.com/Images/Atmel-42366-SAM-BA-Bootloader-for-SAM-D21_ApplicationNote_AT07175.pdf.

I will use that directly with USB cable signals D+, D-, 5V, GND (SAMD microprocessor has internal USB serial hardware and D+ D- pins)

Before I try to upload it, it needs to appear in Device Manager on Windows as a "COM port" with EDBG driver. Because it didn't, SAM-BA doesn't show any COM port as EDBG in the "Select the connection" section.

Can I burn a bootloader to ATSAMD without an JTAG device? For example, I want learn if I can do that with Arduino Zero?


texts: Can't you easily use "quadrature" incremental rotary encoders at 2X or 4X their number of "stops"?

texts:
I bought a 12-step "quadrature" incremental rotary encoder as an input device for a project I'm working on.

When I wrote the code to track "ticks" of rotation, I made it respond to any change in the "A" pin. As a result, I got 24 steps, not 12. They appear to be evenly spaced, and still correctly indicate clockwise or counter-clockwise rotation.

It occurs to me that if I track changes of state in both the "A" and "B" pins, as long as I reverse the logic for identifying clockwize vs. counterclockwise rotation, I could get a 48 step count from the same encoder.

Thus isn't it straightforward to get 2X or 4X the steps from a quadrature  rotary encoder simply by interpreting the signals differently?


texts: Shield board with holes, do I need to solder?

texts:
I have a motor shield.
I can put it on top of my arduino Mega and works perfect.

However, since the shield plugs in on top of the arduino board, I don't have access to 5V and GND from Arduino Mega.

I just have holes on the board with 5V and GND. (look at image)

Do I have to solder a cable there to have access to 5V and GND? or there is another easier way?


texts: Powering a Nano with a 5v mini USB adaptor

texts:
I have made a simple temp sensing circuit that lights an LED when it reaches a certain point. It works perfectly when powered by a USB plugged in to the laptop but when I connect it to a 5V supply with a mini-USB connection nothing happens.

Is this correct and do I need to send power directly to the board on the 5V pin?

Many thanks,
Jack


texts: Trouble with basic communication between two NRF24L01 modules

texts:
Introduction
I am trying to setup a radio communication using the NRF24L01 module because I want to use it to control a tank. The first thing I did when I got the modules was watching some basic tutorials on youtube, for reference I watched HowToMecharonics' video: https://www.youtube.com/watch?v=7rcVeFFHcFM
"Arduino Tutorial: Arduino NRF24L01 Wireless Tutorial with Arduino Uno"
At first I tried to rewrite the code myself to see if I got the concept, but all of my attempts failed, so I tried to copy-paste his exact code and use the arduino IDE, but it didn't work.
Later I noticed that the setup only worked if I plugged both arduinos to the PC, they don't work when plugged in a power supply.
The receiver is an arduino MEGA and the transmitter an UNO.
When I unplug the UNO the IDE says "avrdude: ser_drain(): read error: The device does not recognize the command."
Question
If I unplug the receiver it just doesn't work until I plug it back in, but no error pops up.
It seems strange to me that both arduinos have to be plugged yo the computer at al times, am I doing something wrong?
I also noticed that my modules are slightly different from the ones shown in the viedo, mine doesn't have a label below it
Code
TX
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";

void setup() {
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
}

void loop() {
  const char text[] = "Hello World";
  radio.write(&text, sizeof(text));
  delay(1000);
}

RX
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";

void setup() {
  pinMode(2, OUTPUT);
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
  Serial.println("working");
}

void loop() {
  if (radio.available()) {
    char text[32] = "";
    radio.read(&text, sizeof(text));
    digitalWrite(2, HIGH);
    delay(100);
    digitalWrite(2, LOW);
  }
}


texts: I was trying to build a Bluetooth controlled car. I was near completing it but what I did wrong was that I connected the 5 V output of L298 motor driver to 5V pin of Arduino where I was supposed to connect it in Vin. My Arduino got heated for a couple of seconds. Knowing that I immediately disconnected. Now serial port doesn't work in my Arduino. The serial port option turned gray. I even tried replacing the ATmega IC but got the same result. What might have happened?


texts: How to send data from ThingSpeak to ESP-8266 (Arduino) using ThingHTTP?

texts:
I have made an Arduino kit that acts as a weather station. It sends sensors data (DHT11 & LDR) to the ThingSpeak web server.

Now I want to perform some actions based on the data on the ThingSpeak server (like if temperature exceeds a limit turn on the fan, etc).

I've searched and I found that there's a React app on ThingSpeak, which will trigger events if data exceeds some values.

The problem where I got stuck is that I want to send a signal from the ThingSpeak web server to my ESP8266 (Arduino) to turn on/off the device connected to a relay on Arduino.

I've figured out that there's also a ThingHTTP feature which sends HTTP requests. But I don't know how to send requests/signals to my kit to perform some actions.

I've already spent 2 months building this project, and now I'm stuck in the last part. Please give your valuable suggestions and solutions.


texts:
When i tried powering the board the Atmel IC heats up and led goes of after a second .the board does not get detected on my IDE software .
1) I have tried out finding the issues with the board and solving for same but the board does not revive .
Issues like voltage regulator gets shorted (Pin 1 and 2) .So initially i have thought that removing voltage regulator would solve the problem but still there is short between pin 1 and 2 of 3.3 voltage regulator.
2) tried removing the capacitors connecting vcc  and gnd but with no success of removing the short.
Could Someone would possibly help me to revive the board and fix for the same .


texts: How to determine the SPIFFS size on an esp8266-01?

texts:
I'm confused about my esp8266-01 if they have SPIFFS or not. Is there a way to find it out? If they have, how to get their size?

I've got the following flash id: 0x1440e0.

Example SPIFFS apps keep crashing with wdt reset and lots of dumped hexes.


texts: How can I be engaging the arduino mega with OBD-II UART card?

texts:
Currently I have been doing a project where I need to know the speed of the vehicle, I have implemented the following code but the results have not been good because when the vehicle is in motion always prints STOPPED.

I connected the OBDII-UART card from Sparkfun with Arduino MEGA.

The connection of the cards shown in the image attached below

  1.   char rxData[20];
  2.   char rxIndex = 0;
  3.   String inputString = "";
  4.   boolean stringComplete = false;
  5.   void setup(){
  6.   Serial.begin(9600);
  7.   Serial1.begin(9600);
  8.   Serial.flush();
  9.   Serial1.flush();
  10.   //Reset IC
  11.   Serial1.println("ATZ");
  12.   delay(1500);
  13.   getOBDResponse();
  14.   Serial.println(rxData);
  15.   clearBuffer();
  16.   getOBDResponse();
  17.   Serial.println(rxData);
  18.   clearBuffer();
  19.   //Sets IC to defults
  20.   Serial1.println("ATD");
  21.   delay(1000);
  22.   getOBDResponse();
  23.   Serial.println(rxData);
  24.   clearBuffer();
  25.   getOBDResponse();
  26.   Serial.println(rxData);
  27.   clearBuffer();
  28.   Serial1.println("ATSP0");
  29.   delay(1000);
  30.   getOBDResponse();
  31.   Serial.println(rxData);
  32.   clearBuffer();
  33.   getOBDResponse();
  34.   Serial.println(rxData);
  35.   clearBuffer();
  36.   Serial1.println("010D");
  37.   delay(1000);
  38.   getOBDResponse();
  39.   Serial.println(rxData);
  40.   clearBuffer();
  41.   getOBDResponse();
  42.   Serial.println(rxData);
  43.   clearBuffer();
  44.   Serial1.println("ATDP");
  45.   delay(1000);
  46.   getOBDResponse();
  47.   Serial.println(rxData);
  48.   clearBuffer();
  49.   getOBDResponse();
  50.   Serial.println(rxData);
  51.   clearBuffer();
  52.   //Bus initiation
  53.   Serial1.println("ATSI");
  54.   delay(3000);
  55.   getOBDResponse();
  56.   Serial.println(rxData);
  57.   clearBuffer();
  58.   getOBDResponse();
  59.   Serial.println(rxData);
  60.   clearBuffer();
  61.   Serial.flush();
  62.   Serial1.flush();
  63.   }
  64.   void loop(){
  65.   /*
  66.   if(stringComplete){
  67.   Serial.println(inputString);
  68.   inputString = "";
  69.   stringComplete = false;
  70.   }
  71.   */
  72.   Serial1.flush();
  73.   Serial1.println("010D");
  74.   getOBDResponse();
  75.   Serial.println(rxData);
  76.   clearBuffer();
  77.   getOBDResponse();
  78.   Serial.println(rxData);
  79.   clearBuffer();
  80.   }
  81.   void getOBDResponse(){
  82.   char inChar = 0;
  83.   while(inChar != '\r'){
  84.   if(Serial1.available() > 0){
  85.   if(Serial1.peek() == '\r'){
  86.   inChar = Serial1.read();
  87.   rxData[rxIndex] = '\0';
  88.   rxIndex = 0;
  89.   }else{
  90.   inChar = Serial1.read();
  91.   rxData[rxIndex++] = inChar;
  92.   }
  93.   }
  94.   }
  95.   }
  96.   void clearBuffer(){
  97.   int i;
  98.   for(i = 0; i < 20; i++){
  99.   rxData = '';
  100.   }
  101.   }
  102.   void serialEvent1(){
  103.   while(Serial1.available()){
  104.   char input = (char)Serial1.read();
  105.   inputString += input;
  106.   if(input == '\r'){
  107.   stringComplete = true;
  108.   }
  109.   }

I have based on the example is the page of the card https://learn.sparkfun.com/tutorials/obd-ii-uart-hookup-guide/connecting-to-an-arduino, but when I set the protocol sends me Ok, but when I ask for the speed I send a message from Seeking I do not understand.Information truck tried to read from the console on a laptop

How can I accuratley get the speed of the car?

Well, now I require to get the speed I have entered the command according to the command table ELM327 I quickly attached.


texts:
I have an interesting situation.  I wonder if anyone can help?

I have:

4x Arduino Micros loaded with the basic Blink sketch
5x 12 volt buzzers
A desk full of completely fresh Duracell AA and 9v batteries

If I connect (using VIN and GND) any of the Arduino Micros to either a 9v battery, or a 12v network of 8 AA batteries, then they run the blink sketch, and the appropriate LED flashes on the Arduino as expected.

If I connect any of the buzzers to either a 9v battery, or a 12v network of 8 AA batteries, then they buzz as expected.

If I connect both a buzzer and an Arduino in parallel to either a 9v battery, or a 12v network of 8 AA batteries, then the Arduino works fine, but the buzzer makes barely an inaudible whimper.

If I connect only a buzzer to the Arduino and battery, it works fine.  If whilst the buzzer is buzzing I connect the Arduino, then on every ON or OFF of the blink sketch LED, the buzzer gets quieter and quieter until it can barely be heard.

These buzzers are rated to work at 25mA, so it really astounds me that they can't be run off a battery together with an Arduino.

Any help would be appreciated!

Thanks

Dave


texts: Universal remote control with bluetooth emitter

texts:
I am creating a universal remote control to replace multiple devices I have at home. The IR part was quite easy to implement.
I realised then that the Chromecast with Google TV remote uses Bluetooth, and only Bluetooth, instead of IR.
I have another remote (Foxtel, Australia) that is also Bluetooth, but it accepts IR, so I can just use IR.
I tried to connect the remote to my mobile but, although it shows on the mobile as a possible device to connect, it doesn't complete the connection process.
Is it possible at all to clone the remote into an Arduino and make the Arduino connect to Chromecast to send the commands?
Kind Regards,
Eduardo


texts: How to detect the direction of a rotary encoder?

texts:
I'm trying to detect the direction of rotation for an incremental rotary encoder. I'm supposed to get +1 for clockwise and  -1  for counter-clockwise. However, I receive random values. Any help appreciated.

Following is the code.

const int encoderPinA = 7;
const int encoderPinB = 12;
int val;
int encoderPos = 0;
boolean encoderALast = LOW; // remember the previous pin state

void setup() {
  pinMode(encoderPinA,INPUT);
  pinMode(encoderPinB,INPUT);
  Serial.begin(9600);
}

void loop() {
  analogWrite(3,250); //powering motor
  val = encoder_direction();
  // receive the direction for clockwise 1 and for counter clock wise  -1
  Serial.println(val); // print it in serial monitor
}

int encoder_direction() {
  boolean encoderA = digitalRead(encoderPinA);
  if ((encoderALast == HIGH) && (encoderA == LOW)) {
    if (digitalRead(encoderPinB)) {
      //encoderPos --;
      encoderPos = -1;
    } else {
      //encoderPos ++;
      encoderPos = 1;
    }
    return  encoderPos;
    // return the value either 1 or -1
  }
  encoderALast = encoderA;
}

// using digitalread() code  for four encoders
const int ENCODERS = 4; // the number of encoders
const int encoderPinA[ENCODERS] = { 7, 8, A1 , 2 };
// encoderA pins on 2 and 4
const int encoderPinB[ENCODERS] = { 12, 5, 4 , A2 };
// encoderB pins on 3 and 5
int encoderPos[ ENCODERS] = { 0, 0, 0, 0 };
// initialize the positions to 0
boolean encoderALast[ENCODERS] = { LOW, LOW, LOW, LOW };
// holds last state of encoderA pin

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

int updatePosition(int encoderIndex) {
  boolean encoderA = digitalRead(encoderPinA[encoderIndex]);
  if ((encoderALast[encoderIndex] == HIGH) && (encoderA == LOW)) {
    if (digitalRead(encoderPinB[encoderIndex]) == LOW) {
      //encoderPos[encoderIndex]--;
      encoderPos[encoderIndex] = -1;
    } else {
      //encoderPos[encoderIndex]++;
      encoderPos[encoderIndex] = 1;
    }
    Serial.print("Encoder ");
    Serial.print(encoderIndex+1,DEC);
    Serial.print("=");
    Serial.println (encoderPos[encoderIndex]);
  }
  encoderALast[encoderIndex] = encoderA;
}

void loop() {
  updatePosition(0);
  updatePosition(1);
  updatePosition(2);
  updatePosition(3);
}

// using direct access to digitalread code in order to process faster
int val[4];
int encoderPos = 0;
boolean encoderALast[4] ={LOW, LOW, LOW, LOW};
// remember the previous pin state

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

void loop() {
  for (int ii=0; ii<4;ii++) {
    encoder_direction(ii);
  }
}
int encoder_direction(int m) {
  boolean encoderA;
  boolean encoderB;
  if(m == 0) {
    encoderA = (PIND & _BV (7)) == 0;
    //   digitalRead(7) encoderPinA
    encoderB = (PINB & _BV (4)) == 0;
    // digitalRead(12) encoderPinB
  }
  if (m == 1) {
    encoderA = (PINB & _BV (0)) == 0;
    // digitalRead(8) encoderPinA
    encoderB = (PIND & _BV (5)) == 0;
    // digitalRead(5) encoderPinB
  }
  if (m == 2) {
    encoderA = (PINC & _BV (1)) == 0;
    // digitalRead(A1) encoderPinA
    encoderB = (PIND & _BV (4)) == 0;
    // digitalRead(4)  encoderPinB
  }
  if (m == 3) {
    encoderA = (PIND & _BV (2)) == 0;
    // digitalRead(2) encoderPinA
    encoderB = (PINC & _BV (2)) == 0;
    // digitalRead(A2)  encoderPinB
  }
  if ((encoderALast[m] == HIGH) && (encoderA == LOW)) {
    if (encoderB == LOW) {
      //encoderPos --;
      encoderPos = -1;
    } else {
      //encoderPos ++;
      encoderPos = 1;
    }
    Serial.print(" Encoder ");
    Serial.print(m+1);
    Serial.print(" = ");
    Serial.println(encoderPos);
  }
  encoderALast[m] = encoderA;
}


texts: How can I make ultrasonic sensors resistent to splashes and dirt?

texts:
I wasn't sure where to ask this question, but since it's actually an Arduino project, I'll try it here.

I want to upgrade my old car with ultrasonic parking sensors: I've already bought HC-SR04s as sensors and started to play on my breadboard.

But what I'm still unsure about: if I place them in my car's rear bumber, how can I make them resistent to rain or dirt or something like that?
As pictured on Wikipedia, the sensor is covered with a small piece. But what could I use to cover the holes in the bumper, without interfering with the ultrasonic measuring?


texts: UART error can not compile on Arduino Yun (ATmega32u4)

texts:
This code is used for communication between the Glediator interface and a NeoPixel Matrix, but I receive an error saying 'UCSR0A' is not defined within the scope.

UCSR0A |= (1<<U2X0);
UCSR0B |= (1<<RXEN0)  | (1<<TXEN0) | (1<<RXCIE0);
UCSR0C |= (1<<UCSZ01) | (1<<UCSZ00)             ;
UBRR0H = 0;
UBRR0L = 1; //Baud Rate 1 MBit (at F_CPU = 16MHz)

Any feedback is appreciated.