Relay response slow using Arduino via C# and PC USB

Relay response slow using Arduino via C# and PC USB

By : Own
Date : November 22 2020, 09:00 AM
I hope this helps . I think there is a flaw in the sketch. You want it to act on a single byte of data but you are reading a string. If there is more than one byte of data in the input buffer then all the bytes are being read in. For example, if you sent "0" then "1", then the readString could see "01", and the conversion of that to an int is 1. So essentially it would never see the off command. The opposite is also a problem. "10" would become an int 10 and fall through the case. Re- writing the sketch as @frarugi87 suggested:
code :
     case '0': 
       digitalWrite(RELAY_1, HIGH);

     case '1':
       digitalWrite(RELAY_1, LOW);

Share : facebook icon twitter icon
Arduino Relay Button

Arduino Relay Button

By : Nadeem Alherbawi
Date : March 29 2020, 07:55 AM
I wish this helpful for you AH! This will work here is the code and the schematics for all of you that have this problem (saw on the internet a lot do have this problem), as well THANK YOU ALL for you help in solving this matter! ENJOY!
Circuit (Please note the relay cluster I am using was not available on Fritzing)
code :

int button1 = 7;
int button2 = 6;
int button3 = 4;
int button4 = 2;

int rl1 = 13;
int rl2 = 12;
int rl3 = 11;
int rl4 = 8;

//States for Relay and Button (1)

int state1 = HIGH;      // the current state of the output pin
int reading1;           // the current reading from the input pin
int previous1 = LOW;    // the previous reading from the input pin

//States for Relay and Button (2)

int state2 = HIGH;      // the current state of the output pin
int reading2;           // the current reading from the input pin
int previous2 = LOW;    // the previous reading from the input pin

//States for Relay and Button (3)

int state3 = HIGH;      // the current state of the output pin
int reading3;           // the current reading from the input pin
int previous3 = LOW;    // the previous reading from the input pin

//States for Relay and Button (4)

int state4 = HIGH;      // the current state of the output pin
int reading4;           // the current reading from the input pin
int previous4 = LOW;    // the previous reading from the input pin

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time1 = 0;          // the last time the output pin was toggled
long time2 = 0;
long time3 = 0;
long time4 = 0;

long debounce1 = 200;   // the debounce time, increase if the output flickers
long debounce2 = 200;
long debounce3 = 200;
long debounce4 = 200;

void setup()
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  pinMode(button3, INPUT);
  pinMode(button4, INPUT);

  pinMode(rl1, OUTPUT);
  pinMode(rl2, OUTPUT);
  pinMode(rl3, OUTPUT);
  pinMode(rl4, OUTPUT);


void loop() {

  reading1 = digitalRead(button1);
  reading2 = digitalRead(button2);
  reading3 = digitalRead(button3);
  reading4 = digitalRead(button4);

  // if the input just went from LOW and HIGH and we've waited long enough
  // to ignore any noise on the circuit, toggle the output pin and remember
  // the time
  //Condition Relay 1
  if (reading1 == HIGH && previous1 == LOW && millis() - time1 > debounce1) {
    if (state1 == HIGH)
      state1 = LOW;
      state1 = HIGH;

    time1 = millis();    

  //Condition Relay 2
    if (reading2 == HIGH && previous2 == LOW && millis() - time2 > debounce2) {
    if (state2 == HIGH)
      state2 = LOW;
      state2 = HIGH;

    time2 = millis();    

  //Condition Relay 3
    if (reading3 == HIGH && previous3 == LOW && millis() - time3 > debounce3) {
    if (state3 == HIGH)
      state3 = LOW;
      state3 = HIGH;

    time3 = millis();    

  //Condition Relay 4
    if (reading4 == HIGH && previous4 == LOW && millis() - time4 > debounce4) {
    if (state4 == HIGH)
      state4 = LOW;
      state4 = HIGH;

    time4 = millis();    

  digitalWrite(rl1, state1);
  digitalWrite(rl2, state2);
  digitalWrite(rl3, state3);
  digitalWrite(rl4, state4);

  previous1 = reading1;
  previous2 = reading2;
  previous3 = reading3;
  previous4 = reading4;
Arduino self shutdown using relay not working

Arduino self shutdown using relay not working

By : William Baldwin
Date : March 29 2020, 07:55 AM
this one helps. Found the solution. Change the digitalWrite from HIGH to LOW and LOW to HIGH for pin 7
code :
void setup() 
    pinMode(7,OUTPUT);    // Relay Signal Pin
    digitalWrite(7,LOW); // <-- change this


    digitalWrite(7,HIGH);  // shutdown the circuit <-- change this too

void loop() 
Arduino Uno, 4x4 Keypad to relay

Arduino Uno, 4x4 Keypad to relay

By : Liquicitizen Sander
Date : March 29 2020, 07:55 AM
it fixes the issue You had two extra curly brackets } and { that closed your main loop prematurely. You have also not declared keypad anywhere. I have commented them out below:
code :
#include <Keypad.h>

const byte numRows = 4;
const byte numCols = 4;

int relePin = 10;

char keymap[numRows][numCols] =
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}

byte rowPins[numRows] = {9, 8, 7, 6};
byte colPins[numCols] = {5, 4, 3, 2};

Keypad myKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

void setup() {


  pinMode(relePin, OUTPUT);

void loop() {

  char keypressed = myKeypad.getKey();
  if (keypressed != NO_KEY);
  //} These two line are your problem
  //char key = keypad.getKey(); // keypad was not declared anywhere, I assume it was meant to be this:
  char key = myKeypad.getKey();
  if (int(key) == 1) {
    digitalWrite(relePin, LOW);
    digitalWrite(relePin, HIGH);
Arduino Relay not Powering

Arduino Relay not Powering

By : Manoj Saini
Date : March 29 2020, 07:55 AM
wish helps you While this is not the right place to post about electronics, It appears that your relay only triggers at 12V, Arduino supplies 3.3V and 5V, not enough to trigger your relay.
How to control one relay with two arduino boards?

How to control one relay with two arduino boards?

By : David Weber
Date : March 29 2020, 07:55 AM
will help you If either board can turn the relay on, you can "OR" the two output pins with diodes into the relay. This would also mean that one Arduino cannot turn the relay OFF if the other one is still ON.
Of course, you should use something to drive the relay -- don't hook it directly to the Arduino:
Related Posts Related Posts :
  • Xml-Serialization is not working
  • HTML Agility Pack can't find classes with trailing spaces
  • ComputeHash Calls Inexplicably Differ
  • Creating an array that holds both integers and datetime C#
  • GroupBy multiple columns in Linq with Take()
  • Rename multiple symbols at once? (using Roslyn)
  • Cast lambda in delegate
  • DataContractSerializer using default properties
  • LINQ Query Sum in recordset
  • change left-hand boolean value to be opposite of the right hand value
  • Get node from XmlDocument using xpath
  • Why does a Control's BeginInvoke() target delegate never occur after Dispose() is called on the Control?
  • A pattern for returning an object created by multiple repositories
  • Change Tracking in Excel
  • MVC5 Compilation Bug
  • where I need to set my await compared to the code
  • How to make the transition from "traditional" to reactive MVVM
  • Exception when calling RDORecipients.AddMultiple(ref Array, object) in Redemption
  • Switch a Task<T> where T is an enum
  • c# neo4j cypher use regular exp
  • Calling a method from a LINQ select
  • LINQ Specified Cast is Not Valid with a ushort Table Column
  • Why does ReSharper recommend the removal of its own fix?
  • WPF UserControl with nullable dependency property dependent on checkbox value
  • Generating a random number and putting it in a TextBlock
  • Convert datetime string with this format: (yyyy-MM-dd'T'hh:mm:ss-zzz)
  • Check for True or Null value in Linq to Entity
  • Overload resolution, extension methods and genericity in C#
  • Mono can't load Facebook library (from NuGet)
  • Enumerating sql server instances
  • How to avoid duplicate primary key in Entity Framework manual Insert?
  • Shift + F10 in TextBox KeyDown event
  • Failed to assign to property 'Windows.UI.Xaml.Controls.ContentControl.Content'
  • Factory Pattern without a Switch or If/Then
  • c# How to make smooth arc region using graphics path
  • How to Optimize Reactive implementation of recursive function
  • Encrypted connection string can not be decrypted
  • How to know if a user can read and list files of a directory
  • Add a background colour to a MediaComposition
  • How to get a list of recently edited files?
  • System.ArgumentOutOfRangeException linq c#
  • Uri canonicalization compacting FTP scheme
  • Detecting foreign key conflicts
  • Autofac multiple database support
  • 'System.NullReferenceException'
  • Set a different language for ASP.NET MVC errors
  • checkbox checked or click event not firing in datatemplate
  • Get Current Executable Directory On Map Drive
  • Would executing the SqlCommand be completely moot/redundant, and slow things down?
  • Table To Dictionary <String,Object> using Lambda Expression
  • Azure Service Bus Queue sending a message in NodeJs to .NET client
  • Create Unique Hashcode for the permutation of two Order Ids
  • Cannot submit selected option to contoller
  • How to upsert a document in MongoDB .Net?
  • C# Passing a Class Property Name as String Parameter
  • Remove all occurences of several characters from a string
  • How to configure Teamcity to ignore some tests
  • Why am I getting a cannot implicitly convert int to bool error?
  • C# ScrollBar in TableLayoutPanel with FlowLayouts
  • datagridview custom fill resize
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co