Thanks. The second code is working with an led wired up instead of a relay. As soon as my relays turn up, i can crack on with it and add features like pump on indication led and power indication led
I have added a section so that an led turns on when the relay is triggered and goes off when relay disconnects. It compiles and uploads. When i run the Arduino, it doesn't turn off after its stated time of one minute.
Could someone please check it over for me
//Arduino Nano V3.0---ATmega328
//** Turns Relay on for ONE Hour Then Turns It Off
//**Libraries #include <elapsedMillis.h>
int PowerLed = 2;
int OnLed = 3;
int RelayOne = 4;
//int OnSwitch = 1;
boolean running = false;
void setup() {
//Enable Serial comms Serial.begin(9600);
byte buttonState = digitalRead(RelayOne); // read the state of the pushbutton value
// check if the pushbutton is pressed.
if (buttonState == HIGH) { // if it is, the buttonState is HIGH:
digitalWrite(OnLed, HIGH); // turn LED on:
}
else {
digitalWrite(OnLed, LOW); // turn LED off:
// the setup routine runs once when you press reset
pinMode(RelayOne, OUTPUT);
digitalWrite(RelayOne, HIGH);
delay(60UL * 1UL * 1000UL);
digitalWrite(RelayOne, LOW);
}
}
//**********Arduino Nano V3.0---ATmega328**********
//** Turns Relay on for ONE Hour Then Turns It Off
//**Libraries
#include <elapsedMillis.h>
int PowerLed = 2;
int OnLed = 3;
int RelayOne = 4;
//int OnSwitch = 1;
void setup() {
//Enable Serial comms
Serial.begin(9600);
//Pin Outputs
pinMode(PowerLed, OUTPUT);
pinMode(OnLed, OUTPUT);
pinMode(RelayOne, OUTPUT);
//pinMode(OnSwitch, INPUT); //Initiates Arduino Reset Switch When Pressed
}
void loop()
{
int buttonState = 0;
buttonState = digitalRead(RelayOne); // read the state of the pushbutton value
// check if the pushbutton is pressed.
if (buttonState == HIGH) { // if it is, the buttonState is HIGH:
digitalWrite(OnLed, HIGH); // turn LED on:
}
if (buttonState == LOW) {
digitalWrite(OnLed, LOW); // turn LED off:
}
{
// the setup routine runs once when you press reset
pinMode(RelayOne, OUTPUT);
digitalWrite(RelayOne, HIGH);
delay(2000);
digitalWrite(RelayOne, LOW);
}
}
// the setup routine runs once when you press reset
Talk about a useless assed comment. Why is this in loop()?
pinMode(RelayOne, OUTPUT);
Why is this in loop()?
{
// the setup routine runs once when you press reset
pinMode(RelayOne, OUTPUT);
digitalWrite(RelayOne, HIGH);
delay(2000);
digitalWrite(RelayOne, LOW);
}
What are these curly braces for?
Perhaps you need a delay() after turning the relay off, before you turn it on again on the next pass through loop(), so that you can actually see it change to off.
There is NOTHING in that code that is concerned about time, so the comment at the top is misleading.
Why the bad attitude when someone asks for help? Mistakes in the coding are bound to happen and that is the whole point in asking for someone to look it over. I am currently trying to learn to code so useless assed comments on my lame attempt at code are not appreciated. The genuine help is appreciated
You may not like his style but @PaulS's comments are usually accurate.
Obviously the compiler doesn't care where you put comments or whether they make sense. But using sensible comments is very helpful to humans reading code - mostly, helpful for you. If you make a practice of having accurate comments you can often see flaws in your logic.
Update your code and show us the new version in a new post - i.e. leave the earlier post unchanged.