Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 |
Arduino Time Adjustable Relay Project
In this project, we enter the minutes and seconds data with the buttons. We press the run button and the relay changes position.The device connected to the output of the relay is working. The minutes and seconds count down values. When it is zero, the device at the output of the relay stops.You can add new features to the project.
We see the seven-segment display on many devices our daily life. They are generally operated by scanning method.
Two types of seven-segment display screens are produced.These screens are known as cathode common and anode common. The appropriate screen is used according to the needs of the project. In our project, anode common display screen is used.
We need one relay in the project. We see the module that I designed with 5V coil voltage.
Data entry is one of the most important issues in embedded electronic systems. In our project minute and second data are entered with the help of buttons.
I design developer tools with Altium Designer software.You can buy design files. You can use it in new projects.Altium Designer Projects
https://www.altiumdesignerprojects.com
Project Schematichttps://www.altiumdesignerprojects.com/product/seven-segment-led-display-4x
https://www.altiumdesignerprojects.com/product/led-button-board
https://www.altiumdesignerprojects.com/product/relay-5v
Thanks.
You can follow me.I will share my projects with you.
#include <SevenSeg.h>
/*
Hello
I design developer tools for embedded electronic systems.
You can buy my projects design files.
https://www.altiumdesignerprojects.com
*/
SevenSeg disp(4,5,6,7,8,9,10); // https://github.com/sigvaldm/SevenSeg
// A,B,C,D,E,F,G
//DIGIT PORT 0 1 2 3 4 5 6 // my seven-segment display project
int digitPins[4]={3,2,1,0};
// D1,D2,D3,D4
// SCAN PORT T4,T3,T2,T1 // my seven-segment display project
char displaybuffer[4] = "0000";
word number = 0;
void setup() {
disp.setDigitPins(4, digitPins);
disp.setCommonAnode();
disp.setActivePinState(HIGH,HIGH);
disp.setTimer(2);
disp.startTimer();
}
void loop() {
disp.write(displaybuffer);
displaybuffer[0] = number / 1000 + 48; // 1
displaybuffer[1] = number / 100 % 10 + 48; // 2
displaybuffer[2] = number / 10 % 10 + 48; // 3
displaybuffer[3] = number % 10 + 48; // 4
number++;
delay(500);
}
ISR(TIMER2_COMPA_vect){
disp.interruptAction();
}
#include <SevenSeg.h>
/*
Hello
I design developer tools for embedded electronic systems.
You can buy my projects design files.
https://www.altiumdesignerprojects.com
*/
SevenSeg disp(4,5,6,7,8,9,10); // https://github.com/sigvaldm/SevenSeg
// A,B,C,D,E,F,G
int digitPins[4]={3,2,1,0};
// D1,D2,D3,D4
char displaybuffer[4] = "0000";
byte Minute;
byte Second;
void setup() {
disp.setDigitPins(4, digitPins);
disp.setCommonAnode();
disp.setActivePinState(HIGH,HIGH);
disp.setTimer(2);
disp.startTimer();
Minute = 12;
Second = 34;
}
void loop(){
displaybuffer[0] = Minute / 10 + 48;
displaybuffer[1] = Minute % 10 + 48;
displaybuffer[2] = Second / 10 + 48;
displaybuffer[3] = Second % 10 + 48;
disp.write(displaybuffer);
}
ISR(TIMER2_COMPA_vect){
disp.interruptAction();
}
/*
Hello
I design developer tools for embedded electronic systems.
You can buy my projects design files.
https://www.altiumdesignerprojects.com
*/
word MilliSecond = 0;
byte Second = 0;
byte Minute = 0;
byte lastSecond;
bool timerStart = false;
char rx_byte;
void setup(){
Serial.begin(9600);
noInterrupts(); // disable all interrupts
TCCR1A = 0; // set entire TCCR1A register to 0 //set timer1 interrupt at 1kHz // 1 ms
TCCR1B = 0; // same for TCCR1B
TCNT1 = 0; // set timer count for 1khz increments
OCR1A = 1999; // = (16*10^6) / (1000*8) - 1
//had to use 16 bit timer1 for this bc 1999>255, but could switch to timers 0 or 2 with larger prescaler
// turn on CTC mode
TCCR1B |= (1 << WGM12); // Set CS11 bit for 8 prescaler
TCCR1B |= (1 << CS11); // enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
interrupts(); // enable
}
void loop(){
if(Serial.available() > 0){
rx_byte = Serial.read();
if(rx_byte == '1'){
timerStart = true;
}
if(rx_byte == '2'){
timerStart = false;
}
if(rx_byte == '3'){
Second = 0;
}
}
} // loop
ISR(TIMER1_COMPA_vect){
if(timerStart == true){
MilliSecond++;
if(MilliSecond >= 1000){
MilliSecond = 0;
Second++;
if(Second >= 60){
Second = 0;
Minute++;
if(Minute >= 60){
Minute = 0;
}
}
}
if(Second != lastSecond){
Serial.println("Time -- " + String(Minute) +":"+ String(Second));
}
lastSecond = Second;
}
}
/*
Hello
I design developer tools for embedded electronic systems.
You can buy my projects design files.
https://www.altiumdesignerprojects.com
*/
word MilliSecond = 0;
byte Second = 0;
byte Minute = 0;
byte lastSecond;
bool timerStart = false;
char rx_byte;
void setup(){
Serial.begin(9600);
noInterrupts(); // disable all interrupts
TCCR1A = 0; // set entire TCCR1A register to 0 //set timer1 interrupt at 1kHz // 1 ms
TCCR1B = 0; // same for TCCR1B
TCNT1 = 0; // set timer count for 1khz increments
OCR1A = 1999; // = (16*10^6) / (1000*8) - 1
//had to use 16 bit timer1 for this bc 1999>255, but could switch to timers 0 or 2 with larger prescaler
// turn on CTC mode
TCCR1B |= (1 << WGM12); // Set CS11 bit for 8 prescaler
TCCR1B |= (1 << CS11); // enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
interrupts(); // enable
Second = 45;
Minute = 4;
}
void loop(){
if(Serial.available() > 0){
rx_byte = Serial.read();
if(rx_byte == '1'){
timerStart = true;
}
if(rx_byte == '2'){
timerStart = false;
}
if(rx_byte == '3'){
Second = 0;
}
}
} // loop
ISR(TIMER1_COMPA_vect){
if(timerStart == true){
MilliSecond++;
if(MilliSecond >= 1000){
MilliSecond = 0;
Second--;
if(Second >= 255){
Second = 59;
Minute--;
if(Minute >= 255){
Second = 0;
Minute = 0;
}
}
}
if(Second != lastSecond){
Serial.println("Time -- " + String(Minute) +":"+ String(Second));
}
lastSecond = Second;
}
}
#include <SevenSeg.h>
/*
Hello
I design developer tools for embedded electronic systems.
You can buy my projects design files.
https://www.altiumdesignerprojects.com
*/
SevenSeg disp(4,5,6,7,8,9,10); // A,B,C,D,E,F,G
int digitPins[4]={3,2,1,0}; // D1,D2,D3,D4
char displaybuffer[4] = "0000";
word MilliSecond = 0;
byte Minute = 0;
byte Second = 0;
bool timerStart = false;
void setup(){
disp.setDigitPins(4, digitPins);
disp.setCommonAnode();
disp.setActivePinState(HIGH,HIGH);
disp.setTimer(0) ;
disp.startTimer();
noInterrupts(); // disable all interrupts
TCCR1A = 0; // set entire TCCR1A register to 0 //set timer1 interrupt at 1kHz // 1 ms
TCCR1B = 0; // same for TCCR1B
TCNT1 = 0; // set timer count for 1khz increments
OCR1A = 1999; // = (16*10^6) / (1000*8) - 1
//had to use 16 bit timer1 for this bc 1999>255, but could switch to timers 0 or 2 with larger prescaler
// turn on CTC mode
TCCR1B |= (1 << WGM12); // Set CS11 bit for 8 prescaler
TCCR1B |= (1 << CS11); // enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
interrupts(); // enable
}
void loop(){
timerStart = true;
displaybuffer[0] = Minute / 10 + 48;
displaybuffer[1] = Minute % 10 + 48;
displaybuffer[2] = Second / 10 + 48;
displaybuffer[3] = Second % 10 + 48;
disp.write(displaybuffer);
}
ISR(TIMER0_COMPA_vect){
disp.interruptAction ();
}
ISR(TIMER1_COMPA_vect){
if(timerStart == true){
MilliSecond++;
if(MilliSecond >= 1000){
MilliSecond = 0;
Second++;
if(Minute >= 60){
Minute = 0;
}
}
}
}
#include <SevenSeg.h>
#include <Button.h>
/*
Hello
I design developer tools for embedded electronic systems.
You can buy my projects design files.
https://www.altiumdesignerprojects.com
*/
SevenSeg disp(4,5,6,7,8,9,10); // A,B,C,D,E,F,G
int digitPins[4]={3,2,1,0}; // D1,D2,D3,D4
char displaybuffer[4] = "0000";
Button minutePlus = Button(A0,BUTTON_PULLDOWN); // Minute +
Button minuteMinus = Button(A1,BUTTON_PULLDOWN); // Minute -
Button secondPlus = Button(A2,BUTTON_PULLDOWN); // Second +
Button secondMinus = Button(A3,BUTTON_PULLDOWN); // Second -
Button startButton = Button(A4,BUTTON_PULLDOWN); // RUN
#define relayPin A5
word MilliSecond = 0;
byte Second = 0;
byte Minute = 0;
byte lastSecond;
bool timerStart = false;
bool relayStatus = false;
const byte wait = 125;
void setup(){
pinMode(relayPin, OUTPUT);
disp.setDigitPins(4, digitPins);
disp.setCommonAnode();
disp.setActivePinState(HIGH,HIGH);
disp.setTimer(2);
disp.startTimer();
noInterrupts(); // disable all interrupts
TCCR1A = 0; // set entire TCCR1A register to 0 //set timer1 interrupt at 1kHz // 1 ms
TCCR1B = 0; // same for TCCR1B
TCNT1 = 0; // set timer count for 1khz increments
OCR1A = 1999; // = (16*10^6) / (1000*8) - 1
//had to use 16 bit timer1 for this bc 1999>255, but could switch to timers 0 or 2 with larger prescaler
// turn on CTC mode
TCCR1B |= (1 << WGM12); // Set CS11 bit for 8 prescaler
TCCR1B |= (1 << CS11); // enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
interrupts(); // enable
}
void loop(){
if(relayStatus == false){ // status
if(minutePlus.isPressed()){
Minute++;
delay(wait);
if(Minute >= 60){
Second = 0;
Minute = 0;
}
}
if(minuteMinus.isPressed()){
Minute--;
delay(wait);
if(Minute >= 255) {
Minute = 0;
}
}
if(secondPlus.isPressed()){
Second++;
delay(wait);
if(Second >= 60){
Second = 0;
Minute++;
}
}
if(secondMinus.isPressed()){
Second--;
delay(wait);
if(Minute == 0 && Second >= 255){
Second=0;
}
if(Second >= 255 ){
Second = 59;
Minute--;
if(Minute >= 255 ){
Minute = 0;
}
}
}
if(startButton.isPressed()){
timerStart = true;
relayStatus = true;
digitalWrite(relayPin,HIGH); // role on
delay(50);
}
} // relaystatus
displaybuffer[0] = Minute / 10 + 48;
displaybuffer[1] = Minute % 10 + 48;
displaybuffer[2] = Second / 10 + 48;
displaybuffer[3] = Second % 10 + 48;
disp.write(displaybuffer);
} // loop
ISR(TIMER2_COMPA_vect){
disp.interruptAction ();
}
ISR(TIMER1_COMPA_vect){
if(timerStart == true){
MilliSecond++;
if(MilliSecond >= 1000){
MilliSecond = 0;
Second--;
if(Second >= 255){
Second = 59;
Minute--;
if(Minute >= 255){
Second = 0;
Minute = 0;
}
}
}
}
}
#include <SevenSeg.h>
#include <Button.h>
/*
Hello
I design developer tools for embedded electronic systems.
You can buy my projects design files.
https://www.altiumdesignerprojects.com
*/
SevenSeg disp(4,5,6,7,8,9,10); // A,B,C,D,E,F,G
int digitPins[4]={3,2,1,0}; // D1,D2,D3,D4
char displaybuffer[4] = "0000";
Button minutePlus = Button(A0,BUTTON_PULLDOWN); // Minute +
Button minuteMinus = Button(A1,BUTTON_PULLDOWN); // Minute -
Button secondPlus = Button(A2,BUTTON_PULLDOWN); // Second +
Button secondMinus = Button(A3,BUTTON_PULLDOWN); // Second -
Button startButton = Button(A4,BUTTON_PULLDOWN); // RUN
#define relayPin A5
word MilliSecond = 0;
byte Second = 0;
byte Minute = 0;
byte lastSecond;
bool timerStart = false;
bool relayStatus = false;
const byte wait = 150;
void setup(){
pinMode(relayPin, OUTPUT);
disp.setDigitPins(4, digitPins);
disp.setCommonAnode();
disp.setActivePinState(HIGH,HIGH);
disp.setTimer(2);
disp.startTimer();
noInterrupts(); // disable all interrupts
TCCR1A = 0; // set entire TCCR1A register to 0 //set timer1 interrupt at 1kHz // 1 ms
TCCR1B = 0; // same for TCCR1B
TCNT1 = 0; // set timer count for 1khz increments
OCR1A = 1999; // = (16*10^6) / (1000*8) - 1
//had to use 16 bit timer1 for this bc 1999>255, but could switch to timers 0 or 2 with larger prescaler
// turn on CTC mode
TCCR1B |= (1 << WGM12); // Set CS11 bit for 8 prescaler
TCCR1B |= (1 << CS11); // enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
interrupts(); // enable
}
void loop(){
if(relayStatus == false){ // status
if(minutePlus.isPressed()){
Minute++;
delay(wait);
if(Minute >= 60){
Second = 0;
Minute = 0;
}
}
if(minuteMinus.isPressed()){
Minute--;
delay(wait);
if(Minute >= 255) {
Minute = 0;
}
}
if(secondPlus.isPressed()){
Second++;
delay(wait);
if(Second >= 60){
Second = 0;
Minute++;
}
}
if(secondMinus.isPressed()){
Second--;
delay(wait);
if(Minute == 0 && Second >= 255){
Second=0;
}
if(Second >= 255 ){
Second = 59;
Minute--;
if(Minute >= 255 ){
Minute = 0;
}
}
}
if(startButton.isPressed()){
timerStart = true;
relayStatus = true;
digitalWrite(relayPin,HIGH); // role on
delay(10);
}
} // relaystatus
displaybuffer[0] = Minute / 10 + 48;
displaybuffer[1] = Minute % 10 + 48;
displaybuffer[2] = Second / 10 + 48;
displaybuffer[3] = Second % 10 + 48;
disp.write(displaybuffer);
} // loop
ISR(TIMER2_COMPA_vect){
disp.interruptAction();
}
ISR(TIMER1_COMPA_vect){
if(timerStart == true){
MilliSecond++;
if(MilliSecond >= 1000){
MilliSecond = 0;
Second--;
if(Second >= 255){
Second = 59;
Minute--;
if(Minute >= 255){
Second = 0;
Minute = 0;
timerStart = false;
relayStatus = false;
digitalWrite(relayPin,LOW);
}
}
}
}
}
Comments