Pushbutton works intermittently (Arduino) - button

I'm playing with Arduino and I've tried a simple circuit where an LED lights up when you press a pushbutton, using the attachInterrupt() function.
Here is the code:
const byte LED = 11;
const byte Pushbutton = 2;
// run setup code
void setup() {
pinMode(Pushbutton, INPUT);
pinMode(LED, OUTPUT);
attachInterrupt(digitalPinToInterrupt(Pushbutton), LEDManager, CHANGE);
}
void loop() {}
// <summary>LED manager HIGH or LOW</summary>
void LEDManager() {
digitalWrite(LED, digitalRead(Pushbutton));
}
My circuit works but intermittently or when I touch the wire connected to pin D2.
I don't understand why and I need some help!
Update
I've tried many configurations and when I use new wires it works! The problem was welds, they were not well done and had probably damaged the wires (my soldering iron was too hot).
(Spoiler, a new fail! Wow!)
Update 2!
This time, I changed the circuit and connected pin D2 to the COM port of the pushbutton. The COM port is connected to a 10k ohm resistor that is connected to the Gnd pin and 3.3V pin is connected to the ON port of the pushbutton (I was inspired by that, thanks ingo).
It's finally working, alleluia !

I changed the circuit and connected pin D2 to the COM port of the pushbutton. The COM port is connected to a 10k ohm resistor that is connected to the Gnd pin and 3.3V pin is connected to the ON port of the pushbutton (I was inspired by that, thanks ingo).

Related

ESP32 output pins not working with Arduino IDE

So this is my first time working with ESP32 or any MCU at all and I'm trying to blink an external LED connected to my GPIO16 pin but it doesn´t seem to be working. My board is a 38pin ESP32 with only one internal LED connected to pin 1 (not to pin 2 as many other esp32 dev boards) which I was actually able to blink with the blink example program.
I've tried connecting my external LED positive terminal to GPIO17 and GPIO18 as well but still doesn't work. I'm grounding my LED negative terminal with one of the GND pins of the dev board and I've also tried using the other 2 GND pins available but the result is the same.
In the Arduino IDE I'm using ESP32 Dev Module as my board in the boards manager and the serial communication seems to be working just fine, I'm just not being able to output the HIGH and LOW signals to light up my LED.
The limiting resistor I'm using is a 220 Ohm.
Here's the code I've been trying to achieve this:
int ledPin = 16;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop () {
digitalWrite(ledPin,HIGH);
delay(1000);
digitalWrite(ledPin,LOW);
delay(1000);
}
Is it possible that my pins are outputting a very low voltage or that they might not work?
I leave a picture of my pinout. Thank you very much in advance!!
ESP32 Dev Module 38 Pin Layout

HC-05 bluetooth module not working properly from a distance

I have started learning about arduino and just bought a bluetooth module, HC-05. From where i bought, it says it has range of approx.10 meters. I made hc-05 connection with arduino in below described ways
I am using it as a slave with default configurations, 9600 baud rate and HC-05 name with pin 1234
GND of HC05 -> GND of `arduino`
VCC of HC05 -> 5V of `arduino`
TX of HC05 -> RX of `arduino`
RX of HC05 -> TX of `arduino` via voltage divider network 2k---|---1k
Below is my arduino code
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX
// Connect the HC-05 TX to Arduino pin 2 RX.
// Connect the HC-05 RX to Arduino pin 3 TX through a voltage divider.
int pin = 13;
char c = ' ';
void setup()
{
Serial.begin(9600);
Serial.println("Arduino is ready");
pinMode(pin,OUTPUT);
// HC-05 default serial speed for communication mode is 9600
BTserial.begin(9600);
Serial.println("BTserial started at 9600");
}
void loop()
{
if (BTserial.available()>0){
c = BTserial.read();
Serial.println(c);
switch (c){
case '1' :
digitalWrite(pin,HIGH);
break;
case '2' :
digitalWrite(pin,LOW);
break;
default: break;
}
}
}
Following things happening to me:
When I power the module I am able to discover it with my phone but only when I hold my phone very near to the module. If I move away from the HC05 module, for example 3-4 feet, I am not able to discover it.
2.After connecting with it (while holding phone near to the module), I am able to send data to it but again, if I move away , only a few steps, I am unable to send data and I disconnect from it automatically. Also if I change direction of the antenna even then no communication happens.
My purpose is to control my home's lights and TV with the help of this module and Relays. But HC05 is useless so far. I was hoping that I would code it and wire it and hang it on a wall and interact it with and andoird app.
Is it suppose to happen like this? or there's something wrong with my module's antenna
thank you.

Arduino Nano no serial communication SIM800C

I am trying to get my SIM800C to talk with my Arduino. There is no communication happening, though.
#include <SoftwareSerial.h>
SoftwareSerial at(2, 3);
void setup() {
Serial.begin(9600);
at.begin(9600);
}
void loop() {
// try every 2 seconds
delay(2000);
Serial.println("sending AT ... ");
at.println("AT");
while (at.available() > 0) {
Serial.write(at.read());
}
}
I am not able to get an OK back. SIM800C is supposed to detect the baud rate by itself.
I am sure there has to be a simple stupid mistake. I just don't know what to do at this point. I obviously already checked for cable break. Out of desperation I already tried to switch RX and TX. I also tried different baud rates (whatever is within the usual limitations of SoftwareSerial) but it should automatically detect it once a couple of AT commands got in anyway.
Weird enough, the pin PWX on the SIM800C needs to be hooked up to a GND to work. It started blinking every second now and is responding to AT commands.
Also it turned out that this specific module does not ship with autobauding enabled, as stated by the SIM800C documentation. The correct baud rate is 115200.
There are some problems you need to consider:
Use below sample code which transfers data between PC and SIM. Sometimes SIM module would go into power down state and won't respond on any AT command but would print some results in the serial monitor.
As already mentioned in comments it seems that your wiring is wrong and as you declared Software Serial as SoftwareSerial at(2, 3); which means pin 2 is Rx on Arduino and should connect to Tx pin of SIM and pin 3 is Tx on Arduino and should connect to Rx pin of SIM. Please don't mess with the pins and connect the pins like below correctly.
Arduino SIM
Rx 2 ----> Tx
Tx 3 ----> Rx
I'm not sure if you can power on SIM800 with a 500mA USB connector, make sure that use an external 1/2 A power supply for VCC of SIM module.
Look at the blink speed of SIM module if it connected and powered on it would blinky with 3 seconds delay and if it blinks fast, it means that it is being restarted. Also if SIM powered on correctly it would print some info like SIM READY, CALL READY, etc.
Try other baud rates like 115200 and see if you get anything on power on.
I put some macro definition to make pin mappings more clear.
#include <SoftwareSerial.h>
//SIM800 TX is connected to Arduino D2
#define SIM800_TX_PIN 2
//SIM800 RX is connected to Arduino D3
#define SIM800_RX_PIN 3
//Create software serial object to communicate with SIM800
SoftwareSerial serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN);
void setup() {
//Begin serial comunication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
while(!Serial);
//Being serial communication witj Arduino and SIM800
serialSIM800.begin(9600);
delay(1000);
Serial.println("Setup Complete!");
}
void loop() {
//Read SIM800 output (if available) and print it in Arduino IDE Serial Monitor
if(serialSIM800.available()){
Serial.write(serialSIM800.read());
}
//Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800
if(Serial.available()){
serialSIM800.write(Serial.read());
}
}
Yes this module will not work in this configuration. There is a pin of V_TTL With 5V pin.. This pin enables the TTL logic converter of your GSM.. You have to connect this pin to 5V in case of arduino and to 3V in case of ESP8266.See the pin configuration here

Wemos D1 not able to run code

I bought this board
As far as I can tell I installed the drivers and libraries properly(I can see the board in the usb devices and upload the code), but every time I try to run a program, I get this result in the serial monitor and the board doesnt light up any led. I also tried to just print an hello world, but i get the same result.
My configs are :
And a example is:
I hope you can help me out, thank you!
I think the issue with the LED not blinking is because many of the ESP12 boards use GPIO 2 rather than GPIO 1 for the built in LED.
See this issue for more details.
Try adding this to the beginning of the sketch:
#define LED_BUILTIN 2
or just use 2 in place of LED_BUILTIN
which will re-define LED_BUILTIN to use gpio 2 rather than gpio 1
As for the serial monitor, I have not directly used the Arduino IDE in a while, but you are not printing anything to the serial port anyway.
Here is an updated version of the sketch that should blink the led and print some messages to the monitor. (set the baud rate of the serial port to 115200 in the IDE)
#define LED_BUILTIN 2
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
}
// the loop function runs over and over again forever
void loop() {
Serial.println("turning ON LED");
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
// but actually the LED is on; this is because
// it is acive low on the ESP-01)
delay(1000); // Wait for a second
Serial.println("turning OFF LED");
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
delay(2000); // Wait for two seconds (to demonstrate the active low LED)
}
The problem in my case was a faulty board. I requested a new one from the seller, and the one worked just fine with the code that I provided in the question.

Arduino YUN: Serial Communication not working

I have been unable to use the serial monitor with the Arduino YUN, I can download the compiled sketch with IDE 1.5.5 (on Windows XP via the USB connector that appears as COM6), the serial monitor opens but displays nothing. In order to investigate I modified the Blink example sketch as follows:
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
Serial.begin(9600);
while (!Serial) {;}
Serial.println("Blink Program");
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.println("Blink Program -H");
delay(5000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
Serial.println("Blink Program -L");
delay(5000); // wait for a second
}
The sketch upoloads and runs, I see the LED blinking, it does not wait for SerialMonitor to open. The SerialMonitor displays nothing. I have noticed that during the upload COM6 disappers from the Windows device manager, a new port COM7 appears, the upload completes successfully, COM7 disappears and COM6 reappears.
I have also found that the YunSerialTerminal example is not working.
Do other people have successfully used the IDE 1.5.5 SerialMonitor on Windows XP?
Should I conclude that my Arduino Yun board is malfunctioning?
Any help would be greatly appreciated.
I had the same problem. A reset on 32U4 solved the problem (the button on the left top corner, next to the Ethernet connector). The serial port appeared on the arduino 1.5.x IDE and the connection was established and the data received.
Bridge and Console should be used when the selected port is the wifi one, not the real serial port.
I hope that helps.
Best,
I am running 1.5.5 and had a similar problem. Console.begin() and Bridge.begin() work just fine. Serial gives me nothing. I started with the following.
void setup() {
// for debugging, wait until a serial console is connected
Serial.begin(9600);
delay(4000);
while(!Serial);
Serial.print("Initializing the bridge...");
Bridge.begin();
Serial.println("Done");
}
void loop()
{
Serial.println("running...");
}
Try to change your USB cable(needs to be USB data cable) and Port settings in Arduino IDE. Tools-->Port-->COM6(Arduino Yun).
This solved my problem in Windows.

Resources