Relay problem from a new Arduino user

Hi I am new to the forum and have been looking for a way to turn a relay on and off. I want to push a button to start the circuit and flash an led 3 times (this bit I can do. well I am pretty sure i can). Then I want to check the voltage on my super capacitor bank and switch a relay on if they are lower than 2 volts. Once I get 2.6 volts on my super capacitors I want the relay to switch off and the led to flash until i press the button to turn off the led. I only got my arduino uno 2 days ago and I just cannot work it out. If there is any kind soul out there who can help I will be very grateful for any help to point me in the right direction. Thank you for your time.. :slight_smile:

Try this link: LMGTFY - Let Me Google That For You

Hi and thank you for your help. I have managed to sort out my sketch which is very simple and works fine except when the super caps are fully charged 5.3 volts (they have a small load on them draining the voltage slowly) the relay ticks on/off every 2 seconds. I know this is due to the delay(2000); line of code but i would like the charge circuit to click in at 4 volts Ie when val = around 400. is there a way of doing this? I know I probably seem stupid to you guys but I am just starting out with Arduino and am new to programing. I have attached my sketch below.
Thank you
Jeremy

int sensePin =0;
int relayPin = 9;
int ledPin = 13;
void setup(){
analogReference (DEFAULT);
pinMode (relayPin, OUTPUT),
pinMode (ledPin, OUTPUT);
Serial.begin(9600);
}

void loop() {
int val = analogRead(sensePin);
if(val <530) digitalWrite(relayPin, HIGH);

else digitalWrite(relayPin, LOW);

if(val <530) digitalWrite(ledPin, LOW);
else digitalWrite(ledPin, HIGH);

Serial.println(analogRead(sensePin));
delay(2000);
}

Seems too obvious, but does it do what you want if you replace those two 530s with 400?

Hi and thanks for your reply. It is just the relay ticking that is the problem whatever the voltage is set to. I want the circuit to turn off at full charge(530) and then kick in when the caps are down to 4 volts (400) I am running an lm317 voltage regulator to put out 3.5 volts to a radio I made and the regulator puts out enough voltage if the caps are at 4 volts. This is just a bit of fun and I am trying to learn a bit about programming the arduino. Is there a simple solution that I am missing?
Thank you

In which case, have one if that turns the relay on if val < 400. Use a second separate if to turn it off when val >= 530.

Thanks WildBill That was what I was missing. It works great now that i have put this in. I have a lot to learn but that is one more thing under my belt now
Thanks again.

if(val <400) digitalWrite(relayPin, HIGH);

if(val>530) digitalWrite(relayPin, LOW);
:slight_smile:

Hi everyone.
I am new to programming and have an arduino uno. I have made a simple programme to charge my supercapacitors and have it working fine. But now I wish to change things a little and that is where I am having my problems.
This is what I am using at the moment. I have 2, 2.7 volt supercapacitors in series making 5.4 volts running a simple electronics project and I wish to use my arduino to rum my charging circuit at 2 different voltages i.e. 2.7 volts and 5.4 volts for different electronics projects. I have built a simple charger to run off of my arduino and it works fine I just connect my arduino up and it keeps my circuit running fine and the 3 leds give me an idea of the state of charge for my supercapacitors. This is my programme.
5.35v supercap charger

int sensePin =0;
int relayPin = 9;
int lowledPin = 12;
int okledPin = 11;
int fullchargePin = 13;
void setup(){
 analogReference (DEFAULT);
 pinMode (relayPin, OUTPUT);
 pinMode (lowledPin, OUTPUT);
 pinMode (okledPin, OUTPUT);
 pinMode (fullchargePin, OUTPUT);
Serial.begin(9600); 
}

void loop() {
  int val = analogRead(sensePin);
  if(val <300) digitalWrite(relayPin, HIGH);
  if (val <99) digitalWrite (lowledPin, LOW);  
   if(val >100) digitalWrite (lowledPin, HIGH);
   if (val >450) digitalWrite(okledPin, HIGH);
   if (val <329) digitalWrite(okledPin, LOW);
  if(val>530
  ) digitalWrite(relayPin, LOW);
 if(val <490) digitalWrite(fullchargePin, LOW);
  
  else digitalWrite(fullchargePin, HIGH);
  

  Serial.println(analogRead(sensePin));
  delay(2000);
}

Moderator edit: CODE TAGS added.

I want to modify this charger to use one led to be an indicator and use a push button to control my charger

This is what I would like the charger to do to do.
Press button and hold for one second led flashes once relay latches charges to 2.65 volts then relay unlatches led flashes until button is pressed again.
Press button and hold for two seconds led flashes twice, relay latches and charges to 5.35 volts then relay unlatches, led will flash until button is pressed
I go the idea from this video on you tube (link below) but this guy is not willing to help. He is happy to sell me a kit which I thought about but I am sure this can be done on my uno but I do not know where to start Thank you for taking the time to read my post