Go Down

Topic: Relays will remain on when code is uploaded,  (Read 262 times) previous topic - next topic

adnanchanna

Hello readers

Hope you all are fine, I have query when I uploading relay code in serial communication, at the upload time all relays are will remain ON, However I want to control my own self through mobile phone via bluetooth code is following as:

#include <SD.h>





char val;         // variable to receive data from the serial port
int ledpin; // LED connected to pin 2 (on-board LED)
void setup()
{
  pinMode(ledpin = 12, OUTPUT); // Engine Ignition Relay.
  pinMode(ledpin = 11, OUTPUT); // Engine OFF Relay.
  pinMode(ledpin = 10, OUTPUT); // Generator Load Relay.
  pinMode(ledpin = 9, OUTPUT);//   K-Electric Load Relay.
  pinMode(ledpin = 8, OUTPUT);//   Solonoid Volve Relay.
  pinMode(ledpin = 7, OUTPUT);//   Reset Relay.
  pinMode(ledpin = 6, OUTPUT);
  pinMode(ledpin = 5, OUTPUT); 
    Serial.begin(115200);       // start serial communication at 115200bps

}

void loop()

{
  if( Serial.available() )       // if data is available to read
  {
    ;
  }
  val = Serial.read();         // read it and store it in 'val'

 
  if( val == 'A' )               //
  {
    digitalWrite(ledpin = 12, HIGH);    // Engine Ignition Start Engine UP
  }
 
  if( val == 'a' )               //
  {
    digitalWrite(ledpin = 12, LOW);  // Engine Ignition Start Engine Down
  }

  if( val == 'B' )               //
  {
    digitalWrite(ledpin = 11, HIGH);    // Engine OFF
  }
 
  if( val == 'b' )               //
  {
    digitalWrite(ledpin = 11, LOW);  // This is for spare
  }

  if( val == 'C' )               // 
   {
    digitalWrite(ledpin = 10, HIGH);  // Generator load will ON
         
}

  if( val == 'c' )               //
  {
    digitalWrite(ledpin = 10, LOW);  // Generator load will OFF
     
 
  }
  if( val == 'D' )               //
  {
    digitalWrite(ledpin =9 , HIGH);  // K-Electric load will ON
                     
  }
 
 
  if( val == 'd' )               //
  {
    digitalWrite(ledpin =9 , LOW);  // K-Electric load will OFF
                     
  }


 
  if (val == 'E')
  {
     digitalWrite(ledpin = 7, HIGH);   // CNG
                    delay(1000);
                 digitalWrite(ledpin = 7, LOW);
              delay(1000);
    }

  if (val == 'e')
  {
    digitalWrite (ledpin= 7, HIGH); // CNG
   
    digitalWrite (ledpin= 8, HIGH); //Petrol
   
    }

 if (val == 'F')

  {
    digitalWrite (ledpin = 8, LOW); // Petrol
   
    }
 
 if (val == 'f')

 {
  digitalWrite (ledpin = 8, LOW); //System off
  digitalWrite (ledpin = 7, LOW); //System off
 
  }
 
 


// Reset all Relay function.

if (val == 'R')

{
  digitalWrite(ledpin= 12, HIGH);
  digitalWrite(ledpin= 11, HIGH);
  digitalWrite(ledpin= 10, HIGH);
  digitalWrite(ledpin= 9, HIGH);
  digitalWrite(ledpin= 8, HIGH);
  digitalWrite(ledpin= 7, HIGH);
  digitalWrite(ledpin= 6, HIGH);
  digitalWrite(ledpin= 5, HIGH);
 delay(1000);
  digitalWrite(ledpin= 12, LOW);
  digitalWrite(ledpin= 11, LOW);
  digitalWrite(ledpin= 10, LOW);
  digitalWrite(ledpin= 9, LOW);
  digitalWrite(ledpin= 8, LOW);
  digitalWrite(ledpin= 7, LOW);
  digitalWrite(ledpin= 6, LOW);
  digitalWrite(ledpin= 5, LOW);
   delay(1000);

  }

if (val == 'r')

{
  digitalWrite(ledpin= 12, HIGH);
  digitalWrite(ledpin= 11, HIGH);
  digitalWrite(ledpin= 10, HIGH);
  digitalWrite(ledpin= 9, HIGH);
  digitalWrite(ledpin= 8, HIGH);
  digitalWrite(ledpin= 7, HIGH);
  digitalWrite(ledpin= 6, HIGH);
  digitalWrite(ledpin= 5, HIGH);
 delay(100000);
  digitalWrite(ledpin= 12, LOW);
  digitalWrite(ledpin= 11, LOW);
  digitalWrite(ledpin= 10, LOW);
  digitalWrite(ledpin= 9, LOW);
  digitalWrite(ledpin= 8, LOW);
  digitalWrite(ledpin= 7, LOW);
  digitalWrite(ledpin= 6, LOW);
  digitalWrite(ledpin= 5, LOW);
   delay(1000);

  }


   
  }
 

ieee488


adnanchanna

once relay code uploaded in arduino , relay will remain on, however I want to control my self
 

rw950431


This kind of code

Code: [Select]
pinMode(ledpin = 12, OUTPUT);

is very unusual and may or may not be doing what you think it should do.  The more usual syntax is

Code: [Select]
pinMode(12, OUTPUT);

That is, remove the ledpin= and just use the pin number

There is also
Code: [Select]

  digitalWrite(ledpin= 5, HIGH);
 delay(100000);
  digitalWrite(ledpin= 12, LOW);


Not sure if you intend to wait 100 seconds there instead of the 1 second you used everywhere else.



Usual reminder to use the code tags...


Go Up