Show Posts
Pages: [1] 2 3 ... 5
1  Using Arduino / Programming Questions / Re: Reset Function is not working in my code on: September 14, 2014, 05:26:45 pm
I cleaned my code, however I am stuck in an infinite loop. I tried the if statement in my scrolltext function but the scroll happen only one time. When I use the while loop it get stuck there for ever and pressing another key doesn't do anything. It just keep scrolling at the first one I pressed. Here is my new code.
Code:
#include <Keypad.h>
const byte ROWS = 2;
const byte COLS = 2;
char keys[ROWS][COLS] =
{
  {
    '1','3'      }
  ,{
    '7','9'      }
  ,};
byte rowPins [ROWS] = {
  5,6};
byte colPins [COLS] = {
  7,8};
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
const int pirPin = 9;
const int namePin = 13;     
const int offPin = 10;     
const int cvnPin = 11;   
const int vacatPin = 12;   
const int herePin = 2;   
const int latchPin = 3;
const int clockPin = 4;
int val = 0;
int seq[14] = {
  1,2,4,8,16,32,64,128,64,32,16,8,4,2};       
void scrollText(int X, int Y ){
 val = digitalRead(pirPin);
 Serial.println('val');
  while(val == HIGH){
    for (int n = 0; n < 14; n++)
    {
      digitalWrite(latchPin, LOW);             
      shiftOut(X, clockPin, MSBFIRST, seq[n]);         
      digitalWrite(latchPin, HIGH);           
      delay(50);
    }
    for (int n = 0; n < 14; n++)
    {
      digitalWrite(latchPin, LOW);             
      shiftOut(Y, clockPin, MSBFIRST, seq[n]);         
      digitalWrite(latchPin, HIGH);           
      delay(50);
    }
  }

void setup()
{
  Serial.begin (9600);
  pinMode(namePin, OUTPUT);
  pinMode(offPin, OUTPUT);
  pinMode(cvnPin, OUTPUT);
  pinMode(vacatPin, OUTPUT);
  pinMode(herePin, OUTPUT);     
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(pirPin, INPUT);   
}
void loop()
{
 
  byte key = kpd.getKey();
  if (key)
    switch (key) {
    case '1':
      scrollText(namePin,offPin);
      break;
    case '3':
      scrollText(namePin,cvnPin);
      break;
    case '7':
      scrollText(namePin,vacatPin);
      break;
    case '9':
      scrollText(namePin,herePin);
      break;
    }
}


I hope you give me some suggestions or solution to the problem. Thank you.
2  Using Arduino / Programming Questions / Re: Reset Function is not working in my code on: September 09, 2014, 09:55:26 am
Thank you so much for all these good feedbacks.
Hahaha. I was desperate that's why I chose to crash my car instead of falling from a cliff smiley.
I did change the names to something meaningful.
You are right, the function handlekeypress is only for printing the numbers. It doesn't do anything else.
I will clean my code and try to figure out another way to fix the problem.
Thank you very much
3  Using Arduino / Programming Questions / Re: Reset Function is not working in my code on: September 08, 2014, 04:35:39 pm
I don't know how that function  (i.e. handlekeypress) works. If I removed it, somehow, the keypad doesn't input anything when I press a button.
Thank you for your feedback
4  Using Arduino / Programming Questions / Re: Reset Function is not working in my code on: September 08, 2014, 04:31:04 pm
Answer to the last question. I thought of resetting because when I do it manually on the arduino it allows me to push another button to display another message, if I didn't, pushing another button will not get me out of the loop. If I fixed that I wouldn't need a reset function but after multiple tries, I thought using this software reset will help even though I didn't like it.
5  Using Arduino / Programming Questions / Reset Function is not working in my code on: September 07, 2014, 06:42:12 pm
I am using a reset function in my code but for some reason it’s not resetting my Arduino.
I tested the function with other code and it worked but in this one it didn’t. I tried calling the function in different spot in the code but no results.
This project is using an Arduino Uno, a keypad, shift registers, LEDs, resistors and wires.
I am working on breadboard to test before I put the project together.
Basically the project is like this: when the person pushes a key a message start scrolling if the PIR detected motion if not the Arduino should reset itself through the reset function (which I tested and worked) and the Arduino waits to detect another person or wait for another key to be pushed and display another message (of course if motion is detected)
I hope someone looks at my code and help me find out why the resetFunc() is not working.
Note: I only have one case in the switch. I am trying first to get work with one. The rest should be the same.
            Currently, when I push the Key "1" from the keypad nothing happen until i wave my hand near the PIR which is what I want but it keeps scrolling for ever even if I am not near the PIR.
Thank you.

Code:
#include <Keypad.h>
const byte ROWS = 2;
const byte COLS = 2;
char keys[ROWS][COLS] =
{
  {
    '1','3'    }
  ,
  {
    '7','9'    }
  ,
};

byte rowPins [ROWS] = {
  5,6};
byte colPins [COLS] = {
  7,8};
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


int pirPin = 9;
int dataPin1 = 13;     //Name Pin. Define which pins will be used for the Shift Register control
int dataPin2 = 10;     //Off Pin
int dataPin3 = 11;    //CVN Pin
int dataPin4 = 12;    //Vacation Pin
int dataPin5 = 2;    //Here Pin
int latchPin = 3;
int clockPin = 4;
int val = 0;
int pirState = LOW;
int PirState = PirFun();
int seq[14] = {
  1,2,4,8,16,32,64,128,64,32,16,8,4,2};       //The byte sequence



void setup()
{
  Serial.begin (9600);
  pinMode(dataPin1, OUTPUT);
  pinMode(dataPin2, OUTPUT);
  pinMode(dataPin3, OUTPUT);
  pinMode(dataPin4, OUTPUT);
  pinMode(dataPin5, OUTPUT);     
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(pirPin, INPUT);
}



void handleKeypress (const char key)
{
  Serial.println (key);
}


void(* resetFunc)(void)=0;



boolean PirFun(){
  val = digitalRead(pirPin);
}




void loop()

{

  for (int n = 0; n < 14; n++)
  {
    digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
    shiftOut(dataPin1, clockPin, MSBFIRST, seq[n]);          //Send the data
    digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
    delay(30);
  }



  byte key = kpd.getKey();
  if (key)
    handleKeypress (key);

  switch (key) {
  case '1':

   
    while(PirState == HIGH){




      for (int n = 0; n < 14; n++)
      {
       
        digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
        shiftOut(dataPin1, clockPin, MSBFIRST, seq[n]);          //Send the data
        digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
        delay(10);


      }
      for (int n = 0; n < 14; n++)
      {


        digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
        shiftOut(dataPin2, clockPin, MSBFIRST, seq[n]);          //Send the data
        digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
        delay(10);


      }
 

    }

    break;

  }

if(PirState == LOW){

        resetFunc();
      }
}
6  Using Arduino / Project Guidance / Re: PIR Sensor Software Issues on: April 28, 2014, 11:35:02 am
Yes I agree with you. It's proper to put it in a separate function, but that's not the problem I have. The code will still work if I fix the PIR issues.
7  Using Arduino / Project Guidance / PIR Sensor Software Issues on: April 27, 2014, 06:14:17 pm
Hi,
  I am using a pir (3 pin PIR) in my project and somehow the PIR is not responding. It doesn't detect motion. I tried the PIR with a simple code that turns an LED when motion is detected and it worked fine on the same pin i am using (i.e. Pin 9) however when I upload the code below the pir doesn't work. I hope someone could help me figure out the problem. I think the issue is purely software issue.
Code:

Code:
#include <Keypad.h>
const byte ROWS = 2;
const byte COLS = 2;
char keys[ROWS][COLS] =
{
  {
    '1','3'  }
  ,
  {
    '7','9'  }
  ,
};

byte rowPins [ROWS] = {
  5,6};
byte colPins [COLS] = {
  7,8};
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


int pirPin = 9;
int dataPin1 = 13;     //Name Pin. Define which pins will be used for the Shift Register control
int dataPin2 = 10;     //Off Pin
int dataPin3 = 11;    //CVN Pin
int dataPin4 = 12;    //Vacation Pin
int dataPin5 = 2;    //Here Pin
int latchPin = 3;
int clockPin = 4;
int val = 0;

int seq[14] = {
  1,2,4,8,16,32,64,128,64,32,16,8,4,2};       //The byte sequence



void setup()
{
  Serial.begin (9600);
  pinMode(dataPin1, OUTPUT);
  pinMode(dataPin2, OUTPUT);
  pinMode(dataPin3, OUTPUT);
  pinMode(dataPin4, OUTPUT);
  pinMode(dataPin5, OUTPUT);    
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(pirPin, INPUT);
}




void handleKeypress (const char key)
{
  Serial.println (key);
}



void loop()

{

  for (int n = 0; n < 14; n++)
  {
    digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
    shiftOut(dataPin1, clockPin, MSBFIRST, seq[n]);          //Send the data
    digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
    delay(20);
  }


  byte key = kpd.getKey();
  if (key)
    handleKeypress (key);

  val = digitalRead(pirPin);

  switch (key) {
  case '1':
//  Serial.println("entering loop");
    while(HIGH == val)
    {
      for (int n = 0; n < 14; n++)
      {
        digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
        shiftOut(dataPin1, clockPin, MSBFIRST, seq[n]);          //Send the data
        digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
        delay(20);
      }
      for (int n = 0; n < 14; n++)
      {
        digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
        shiftOut(dataPin2, clockPin, MSBFIRST, seq[n]);          //Send the data
        digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
        delay(50);
      }

    }
//Serial.println("exiting loop");
    break;
Serial.println("after break");
  case '3':
    while(HIGH == val)
    {
      for (int n = 0; n < 14; n++)
      {
        digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
        shiftOut(dataPin1, clockPin, MSBFIRST, seq[n]);          //Send the data
        digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
        delay(20);
      }
      for (int n = 0; n < 14; n++)
      {
        digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
        shiftOut(dataPin3, clockPin, MSBFIRST, seq[n]);          //Send the data
        digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
        delay(50);
      }

    }


    break;

  case '7':
    while(HIGH == val)
    {
      for (int n = 0; n < 14; n++)
      {
        digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
        shiftOut(dataPin1, clockPin, MSBFIRST, seq[n]);          //Send the data
        digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
        delay(20);
      }
      for (int n = 0; n < 14; n++)
      {
        digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
        shiftOut(dataPin4, clockPin, MSBFIRST, seq[n]);          //Send the data
        digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
        delay(50);
      }

    }


    break;

  case '9':
    while(HIGH == val)
    {
      for (int n = 0; n < 14; n++)
      {
        digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
        shiftOut(dataPin1, clockPin, MSBFIRST, seq[n]);          //Send the data
        digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
        delay(20);
      }
      for (int n = 0; n < 14; n++)
      {
        digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
        shiftOut(dataPin5, clockPin, MSBFIRST, seq[n]);          //Send the data
        digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
        delay(50);
      }

    }


    break;

  }

}


Here is the code that I am using for the PIR you can find it scattered in the code above. I just copied it here below so you see what I am doing:

Code:

Code:
int pirPin = 9;
int val = 0;
pinMode(pirPin, INPUT);
val = digitalRead(pirPin);
 while(HIGH == val)


Thank you very much

Moderator edit: [code] [/code] tags added.
8  Using Arduino / Project Guidance / PIR Doesn't Respond on: April 24, 2014, 12:30:22 pm
Hi,
  I am using a pir (3 pin PIR) in my project and somehow the PIR is not responding. It doesn't detect motion. I tried the PIR with a simple code that turns an LED when motion is detected and it worked fine on the same pin i am using (i.e. Pin 9) however when I upload the code below the pir doesn't work. I hope someone could help me figure out the problem. I think the issue is purely software issue.
Code:
#include <Keypad.h>
const byte ROWS = 2;
const byte COLS = 2;
char keys[ROWS][COLS] =
{
  {
    '1','3'  }
  ,
  {
    '7','9'  }
  ,
};

byte rowPins [ROWS] = {
  5,6};
byte colPins [COLS] = {
  7,8};
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


int pirPin = 9;
int dataPin1 = 13;     //Name Pin. Define which pins will be used for the Shift Register control
int dataPin2 = 10;     //Off Pin
int dataPin3 = 11;    //CVN Pin
int dataPin4 = 12;    //Vacation Pin
int dataPin5 = 2;    //Here Pin
int latchPin = 3;
int clockPin = 4;
int val = 0;

int seq[14] = {
  1,2,4,8,16,32,64,128,64,32,16,8,4,2};       //The byte sequence



void setup()
{
  Serial.begin (9600);
  pinMode(dataPin1, OUTPUT);
  pinMode(dataPin2, OUTPUT);
  pinMode(dataPin3, OUTPUT);
  pinMode(dataPin4, OUTPUT);
  pinMode(dataPin5, OUTPUT);     
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(pirPin, INPUT);
}




void handleKeypress (const char key)
{
  Serial.println (key);
}



void loop()

{

  for (int n = 0; n < 14; n++)
  {
    digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
    shiftOut(dataPin1, clockPin, MSBFIRST, seq[n]);          //Send the data
    digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
    delay(20);
  }


  byte key = kpd.getKey();
  if (key)
    handleKeypress (key);

  val = digitalRead(pirPin);

  switch (key) {
  case '1':
//  Serial.println("entering loop");
    while(HIGH == val)
    {
      for (int n = 0; n < 14; n++)
      {
        digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
        shiftOut(dataPin1, clockPin, MSBFIRST, seq[n]);          //Send the data
        digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
        delay(20);
      }
      for (int n = 0; n < 14; n++)
      {
        digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
        shiftOut(dataPin2, clockPin, MSBFIRST, seq[n]);          //Send the data
        digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
        delay(50);
      }

    }
//Serial.println("exiting loop");
    break;
Serial.println("after break");
  case '3':
    while(HIGH == val)
    {
      for (int n = 0; n < 14; n++)
      {
        digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
        shiftOut(dataPin1, clockPin, MSBFIRST, seq[n]);          //Send the data
        digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
        delay(20);
      }
      for (int n = 0; n < 14; n++)
      {
        digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
        shiftOut(dataPin3, clockPin, MSBFIRST, seq[n]);          //Send the data
        digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
        delay(50);
      }

    }


    break;

  case '7':
    while(HIGH == val)
    {
      for (int n = 0; n < 14; n++)
      {
        digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
        shiftOut(dataPin1, clockPin, MSBFIRST, seq[n]);          //Send the data
        digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
        delay(20);
      }
      for (int n = 0; n < 14; n++)
      {
        digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
        shiftOut(dataPin4, clockPin, MSBFIRST, seq[n]);          //Send the data
        digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
        delay(50);
      }

    }


    break;

  case '9':
    while(HIGH == val)
    {
      for (int n = 0; n < 14; n++)
      {
        digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
        shiftOut(dataPin1, clockPin, MSBFIRST, seq[n]);          //Send the data
        digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
        delay(20);
      }
      for (int n = 0; n < 14; n++)
      {
        digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data
        shiftOut(dataPin5, clockPin, MSBFIRST, seq[n]);          //Send the data
        digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data
        delay(50);
      }

    }


    break;

  }

}

Here is the code that I am using for the PIR you can find it scattered in the code above. I just copied it here below so you see what I am doing:

Code:
int pirPin = 9;
int val = 0;
pinMode(pirPin, INPUT);
val = digitalRead(pirPin);
 while(HIGH == val)

Thank you very much
9  Development / Other Software Development / expected unqualified-id before if on: March 24, 2014, 12:39:43 am
I am trying to use a keypad to take the input of one key to turn a sepicific pin on. I have a total of 4 inputs, so when the person press the right button it will turn the right pin. The issue I am having is: I get "expected unqualified-id before if " . I used the switch and got the same issue. Do you know what I am doing wrong?
Here is the code that I am running:
Code:
#include <Keypad.h>
int pirPin = 8;
int NamePin = 9;
int HerePin =10;
int CvnPin = 2;
int OffPin = 11;
const byte ROWS = 3;
const byte COLS = 3;
char keys[ROWS][COLS] =
{
  {
    '1','2','3'     }
  ,
  {
    '4','5','6'     }
  ,
  {
    '7','8','9'     }
  ,

};
byte rowPins [ROWS] = {
  5, 4, 3};
byte colPins [COLS] = {
  8, 7, 6 };
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
  Serial.begin (9600);   
  pinMode(NamePin, OUTPUT);
  pinMode(HerePin, INPUT);   
  pinMode(CvnPin, OUTPUT);
  pinMode(OffPin, INPUT);

void handleKeypress (const char key)
{
  Serial.println (key);
}
if(key == '1')
{
  digitalWrite(NamePin, LOW);
  delay(1000);
  digitalWrite(NamePin, HIGH);
  delay(1000);

else if (key = '3')
digitalWrite(NamePin, LOW);
delay(1000);
digitalWrite(HerePin, HIGH);
delay(1000);
else if (key = '7')
digitalWrite(NamePin, LOW);
delay(1000);
digitalWrite(CvnPin, HIGH);
delay(1000);
else (key = '9')
digitalWrite(NamePin, LOW);
delay(1000);
digitalWrite(OffPin, HIGH);
delay(1000);
}
void loop()
{
  byte key = kpd.getKey();
  if (key)
    handleKeypress (key);
}
10  Development / Other Software Development / Re: Standalone on: March 14, 2014, 10:49:30 am
I live in USA. I think I'll try buying from Sparkfun this time. they are familiar to me.
Thank you for your help
11  Development / Other Software Development / Re: Standalone on: March 14, 2014, 01:36:20 am
First, thank you very much for getting back to me.
I performed the test you suggested. here is the outcome:
1- I don't think I still have the original ATMEGA328 that came with the Arduino. I bought the arduino 3 years ago and later I bought 10 ATMEGA328Ps to use in  projects that I may think about; then I stopped for a while and now I wanted to go back to Arduino, so I am not sure if I still have the original or not but I know that I used these 328 before in other circuits and worked fine. I guess I need to go back and try them again.
2- As I mentioned in a previous message I use the Arduino IDE to upload the code to the ATMEGA328P. When the upload is completed I get a message on the IDE that the upload is completed, if not it spits some errors.
3-When I uploaded your code I saw that LED near pin 13 on the Arduino blinking at a rate of 5HZ (approx.) I also opened the serial monitor to see the message and got "Hello from Arduino"
4- I pressed the reset button that is near the USB plug on the Arduino to see what will happen and didn't notice any changes except that every time you hit reset the serial monitor prints the message, the LED blinking rate was the same.
5- However when I unplug and plug the USB (Recycle power) the sketch got lost. I had to upload it to get it back to normal.
That's what I observed.
Now you made me think that maybe these 328s is the problem. I hope so.
Can you suggest a place where I can get a good 328 ; also could tell me what to look for when you buy these little devices. Thank you again. Thank you.
 
12  Development / Other Software Development / Re: Standalone on: March 13, 2014, 01:50:24 am
I am, basically, trying to implement the first example (using one shift register). The example can be seen here:
http://arduino.cc/en/tutorial/ShiftOut#.UyFRC4VRHKd
The purpose is to use it for a scroll sign but before I get there. I wanted to get the basics first.
The final project will be like this: I will use a range finder or another mention sensor and when triggered it will cause a message to scroll.
for now I just wanted to be able to get that first example working without loosing the sketch when I recycle power.
I got the 328s a while ago. I remember the seller told me they have a boot-loader installed in them and should work just like the one you buy with the Arduino.
You raised a good question. I don't know what a bootloader does and are there different bootloaders?
Thank you very much for your help.
13  Development / Other Software Development / Re: Standalone on: March 11, 2014, 11:49:14 pm
Yes! My code is only being used while the 328 is plugged into the Uno board.
What would be a meaningful title and where should I post it to get a good answer to this.
I've built small projects where I used the 328 on a breadboard but, again, I noticed that with some programs it works fine in the UNO or on the breadboard but with some programs it doesn't when you recycle power.
Thanks
14  Development / Other Software Development / Re: Standalone on: March 10, 2014, 04:16:50 pm
Thank you  smiley
I am using this: ATMEGA328P-PU
I don't know if it's a standalone microprocessor or not, I don't know how to check for that. But I know it works for other program such as a blinking LED program. It works all the time even after recycling power. Also I made a small alarm system using a range finder, LEDs and a buzzer and no issues, but I had problem with a program that I used to control a micro pump and another one involving a keypad. So I don't know if it's the code or  using the wrong microprocessor but if that's the case why it worked with some programs and not others.
To upload I use the arduino UNO. I had the microprocessor plugged in the Arduino UNO and I used the USB and my laptop to upload the software to it using the Arduino evironment.
I hope I was clear in explaining the issue and thank you for considering my post. Thanks a lot, if you help me with this you will save me a lot of headaches.
15  Development / Other Software Development / Standalone on: March 10, 2014, 01:13:49 am
Hi,
I am experimenting with shift registers and LEDs, basically turning on and off LEDs one by one (scrolling) as a first step.
I uploaded the following code to my Arduino. It worked fine (i.e. turn on and of 8 LEDs connected to the output of a shift register) however when I recycle power to the Arduino, the circuit stops working. To get it work I need to upload the code again and keep it like that, any recycling of power will require uploading the code again.
I tried few time getting help about this topic because I had this issue with other projects in the past, but so far no one provided any helpful suggestion. I hope this time someone will help. Thank you
here the code:

Code:
//Pin Definitions
// 7HC595N has three pins
int data = 2; // where we send the bits to control outputs
int clock = 3; // keeps the data in sync
int latch = 4; // tells the shift register when to activate the output sequence

void setup()
{
   // set the three control pins to output
  pinMode(data, OUTPUT);
  pinMode(clock, OUTPUT); 
  pinMode(latch, OUTPUT); 
 
  Serial.begin(9600); // so we can send debug messages to serial monitor
}

void loop(){
   
    outputBytes(); // our basic output which writes 8-bits to show how a shift register works.
    //outputIntegers(); // sends an integer value as data instead of bytes, effectively counting in binary.
}
 
void outputIntegers(){
     for (int i=0;i<256;i++){
        digitalWrite(latch, LOW);     
        Serial.println(i);  // Debug, sending output to the serial monitor
        shiftOut(data, clock, MSBFIRST, i);
        digitalWrite(latch, HIGH);   
        delay(100);   
     }
}

void outputBytes(){
    /* Bytes, or 8-bits, are represented by a B followed by 8 0 or 1s.
        In this instance, consider this to be like an array that we'll use to control
        the 8 LEDs. Here I've started the byte value as 00000001
    */   
       
    byte dataValues = B00000001; // change this to adjust the starting pattern
   
    /* In the for loop, we begin by pulling the latch low,
        using the shiftOut Arduino function to talk to the shift register,
        sending it our byte of dataValues representing the state of the LEDs
        then pull the latch high to lock those into place.
       
        Finally, we shift the bits one place to the left, meaning the next iteration
        will turn on the next LED in the series.
       
        To see the exact binary value being sent, check the serial monitor.
    */
   
    for (int i=0;i<8;i++){
      digitalWrite(latch, LOW);     
      Serial.println(dataValues, BIN);  // Debug, sending output to the serial monitor
      shiftOut(data, clock, MSBFIRST, dataValues);
      digitalWrite(latch, HIGH);   
      dataValues = dataValues << 1; // Shift the bits one place to the left -  change to >> to adjust direction
      delay(30);   
    }
 
}
Pages: [1] 2 3 ... 5