Wednesday, 7 December 2022

8 x  8 LED mattrix with arduino- Scrolling Texts

 


This project is about making 8x8 LED metrix display with arduino. The base of this project is the 8x8 LED matrix.

This module is powered by MAX 7219 IC. And you can connect single modules each together you can make a big display.

In this project you can find how to display texts with scrolling on LED metrix.

Connect the wires as follows




VCC --------- Arduino 5v
GND --------- GND
DIN ---------  Pin No 11
CS --------- Pin No 10
CLK ---------  Pin No 13

When the wiring part is completed, you have to download the following arduino libraries.
01. MD_Parola
02.MD_MAX72XX




You can download those libraries from the following link.


Having added those libraries you can upload the code to the project.

The code is given below


// Use the Parola library to scroll text on the display
//
// Demonstrates the use of the scrolling function to display text received
// from the serial interface
//
// User can enter text on the serial monitor and this will display as a
// scrolling message on the display.
// Speed for the display is controlled by a pot on SPEED_IN analog in.
// Scrolling direction is controlled by a switch on DIRECTION_SET digital in.
// Invert ON/OFF is set by a switch on INVERT_SET digital in.
//
// UISwitch library can be found at https://github.com/MajicDesigns/MD_UISwitch
// MD_MAX72XX library can be found at https://github.com/MajicDesigns/MD_MAX72XX
//

#include  //Download this library
#include  //Download this Library
#include 
// set to 1 if we are implementing the user interface pot, switch, etc
#define USE_UI_CONTROL 0

#if USE_UI_CONTROL
#include 
#endif

// Turn on debug statements to the serial output
#define DEBUG 0

#if DEBUG
#define PRINT(s, x) { Serial.print(F(s)); Serial.print(x); }
#define PRINTS(x) Serial.print(F(x))
#define PRINTX(x) Serial.println(x, HEX)
#else
#define PRINT(s, x)
#define PRINTS(x)
#define PRINTX(x)
#endif

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 5
#define CLK_PIN   13
#define DATA_PIN  11
#define CS_PIN    10

String str;
// HARDWARE SPI
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// SOFTWARE SPI
//MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

// Scrolling parameters
#if USE_UI_CONTROL
const uint8_t SPEED_IN = A5;
const uint8_t DIRECTION_SET = 8;  // change the effect
const uint8_t INVERT_SET = 9;     // change the invert

const uint8_t SPEED_DEADBAND = 5;
#endif // USE_UI_CONTROL

uint8_t scrollSpeed = 50;    // Running Speed
textEffect_t scrollEffect = PA_SCROLL_LEFT;
textPosition_t scrollAlign = PA_LEFT;
uint16_t scrollPause = 75; // in milliseconds // Change this amount to delay to start next round :-)




// Global message buffers shared by Serial and Scrolling functions
#define    BUF_SIZE    50

char curMessage[BUF_SIZE] = { "Welcome" };
char newMessage[BUF_SIZE] = {"SETNFIX™"}; //Type the word you want to display on LED matrix
bool newMessageAvailable = true;

#if USE_UI_CONTROL

MD_UISwitch_Digital uiDirection(DIRECTION_SET);
MD_UISwitch_Digital uiInvert(INVERT_SET);

void doUI(void)
{
  // set the speed if it has changed
  {
    int16_t speed = map(analogRead(SPEED_IN), 0, 1023, 10, 150);

    if ((speed >= ((int16_t)P.getSpeed() + SPEED_DEADBAND)) ||
      (speed <= ((int16_t)P.getSpeed() - SPEED_DEADBAND)))
    {
      P.setSpeed(speed);
      scrollSpeed = speed;
      PRINT("\nChanged speed to ", P.getSpeed());
    }
  }

  if (uiDirection.read() == MD_UISwitch::KEY_PRESS) // SCROLL DIRECTION
  {
    PRINTS("\nChanging scroll direction");
    scrollEffect = (scrollEffect == PA_SCROLL_LEFT ? PA_SCROLL_RIGHT : PA_SCROLL_LEFT);
    P.setTextEffect(scrollEffect, scrollEffect);
    P.displayClear();
    P.displayReset();
  }

  if (uiInvert.read() == MD_UISwitch::KEY_PRESS)  // INVERT MODE
  {
    PRINTS("\nChanging invert mode");
    P.setInvert(!P.getInvert());
  }
}
#endif // USE_UI_CONTROL

void readSerial(void)
{
  static char *cp = newMessage;

  while (Serial.available())
  {
    *cp = (char)Serial.read();
    if ((*cp == '\n') || (cp - newMessage >= BUF_SIZE-2)) // end of message character or full buffer
    {
      *cp = '\0'; // end the string
      // restart the index for next filling spree and flag we have a message waiting
      cp = newMessage;
      newMessageAvailable = true;
    }
    else  // move char pointer to next position
      cp++;
  }
}

void setup()
{
  Serial.begin(57600);
  Serial.print("\n[Parola Scrolling Display]\nType a message for the scrolling display\nEnd message line with a newline");

#if USE_UI_CONTROL
  uiDirection.begin();
  uiInvert.begin();
  pinMode(SPEED_IN, INPUT);

  doUI();
#endif // USE_UI_CONTROL

  P.begin();
  P.displayText(curMessage, scrollAlign, scrollSpeed, scrollPause, scrollEffect, scrollEffect);

//Testing purpose only :-)
}

void loop()
{


  
#if USE_UI_CONTROL
  doUI();
#endif // USE_UI_CONTROL

  if (P.displayAnimate())
  {
    if (newMessageAvailable)
    {
      strcpy(curMessage, newMessage);
      newMessageAvailable = false;
    }
    P.displayReset();
  }
  readSerial();
}

Saturday, 2 July 2022

Arduino LED CLOCK with DS 3231 RTC module

 


This is an LED clock with SD 323 RTC module. This module is able to give the time accurately and it is very easy to code without hard coding.


 RTC Module


 Rotary Encoder

 D400 transistor




I hope you have watched my previous project made to create arduino LED clock with setnfix. The wiring for SSDs are as same as that project.



www.setnfix.com/2020/02/arduino-led-rtc-clock-with-seconds-and.html

However, I have made some changes by doing some experiments. Specially I have used only NPN transistors instead of using both NPN and PNP transistors.

2. There is a Rotary encoder to set the time and change the time as well.

3.A switch is fixed to change the 12h mode to 24 hours mode.

Operation Main part of this project is atmega 328 programming IC and it is connected RTC module DS 3231. The RTC module has a battery cell and it can be sored the current time. Therefore, even the device power is down, once the power came the correct time will be displayed.

Time display using DIY SSDs with LED bulbs. those are powered by NPN transistors (D400). In order to display the time multiplex method is used. Adjustment Just the programme is uploaded, the computer time will be displayed. 1. Press one time the rotary encoder to change the minutes : you can up and down the minutes by rotating the rotary encoder. 2. Press one more time the rotary encoder to change the Hours: you can up and down the hours by rotating the rotary encoder. after the 12 noon, it will show 13,14,15 etc up to 23 and the 24 will be displayed as0. 3.Press again to save the time. As press the 3rd time, the seconds will be "00" with saving the time. 24/12 hour mode ** You can change the mode from 24 hour to 12 hour by pressing the button switch. List of Items Atmega 328p : https://s.click.aliexpress.com/e/_Ar9cvT

DS3231 RTC module : https://s.click.aliexpress.com/e/_9HuQMt

D400/2n2222 transistors : https://s.click.aliexpress.com/e/_9jYHU9

Red LED bulbs : https://s.click.aliexpress.com/e/_A2rVtR

Rotary Encoder : https://s.click.aliexpress.com/e/_AaU7Kh




Circuit Diagram


The code is as follows;

    
/*
This is programmed by BMIAK Basnayaka for SETNFIX youtube channel.
www.setnfix.com
youtube.com/setnfix
Date June 6th 2022

***************************************************************************
Operation
Main part of this project is atmega 328 programming IC and it is connected RTC module DS 3231. The RTC module has a battery cell and it can be sored the current time. Therefore, even the device power is down, once the power came the correct time will be displayed.
Time display using DIY SSDs with LED bulbs. those are powered by NPN transistors (D400). In order to display the time multiplex method is used.

Adjustment
Just the programme is uploaded, the computer time will be displayed. 

1. Press one time the rotary encoder to change the minutes : you can up and down the minutes by rotating the rotary encoder.
2. Press one more time the rotary encoder to change the Hours: you can up and down the hours by rotating the rotary encoder. after the 12 noon, it will show 13,14,15 etc up to 23 and the 24 will be displayed as0.
3.Press again to save the time. As press the 3rd time, the seconds will be "00" with saving the time.
24/12 hour mode
** You can change the mode from 24 hour to 12 hour by pressing the button switch.

List of Items

Atmega 328p :  https://s.click.aliexpress.com/e/_Ar9cvT
DS3231 RTC module : https://s.click.aliexpress.com/e/_9HuQMt
D400/2n2222 transistors : https://s.click.aliexpress.com/e/_9jYHU9
Red LED bulbs : https://s.click.aliexpress.com/e/_A2rVtR
Rotary Encoder : https://s.click.aliexpress.com/e/_AaU7Kh

The circuit diagram and the codes cab be seen in the youtube posts.


*/
// modified connexion by niq_ro from http://nicuflorica.blogspot.com
// dataseet: http://www.tme.eu/ro/Document/dfc2efde2e22005fd28615e298ea2655/KW4-563XSA.pdf

#include 
#include "RTClib.h"
RTC_DS3231 rtc;
int sH;
int sM;
byte minutes1 = 0;
byte hours1 = 0;
byte minutes = 0;
byte hours = 0;
int OldScnd=0;

int digit1 = 3; // 15
int digit2 = 5;//12
int digit3 = 6; //11
int digit4 = 9;//5
int digit5 = 10; //3
int digit6 = 11; //2

int segA = 0; //Display pin 18
int segB = 1; //Display pin 17
int segC = 2; //Display pin 16
int segD = 4; //Display pin 14
int segE = 7; //Display pin 13
int segF = 8; //Display pin 6
int segG = 12; //Display pin 4


int hPin = A0;
int segDP = A1; // AM/PM LED

int encoder0PinA = A2;
int encoder0PinB = A3;
int encoder0Pos = 0;
int encoder0PinALast = LOW;
int n = LOW;
const int buttonPin = 13;
// Variables will change:
int ledState = HIGH;         // the current state of the output pin
int buttonState;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin
int reading = 0;
int dUP = 0;

// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers


int clickPin = 0;
int clickNow = 0;

/*
  // Date and time functions using a DS1307 RTC connected via I2C and Wire lib
  // original sketck from http://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/
  // add part with SQW=1Hz from http://tronixstuff.wordpress.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/
  // add part with manual adjust http://www.bristolwatch.com/arduino/arduino_ds1307.htm

*/

// use for hexa in zecimal conversion
int zh, uh, ore;
int zm, um, miniti;

void setup() {


  {
    //Serial.begin(9600);
    delay(3000); // wait for console opening

    if (! rtc.begin()) {
      Serial.println("Couldn't find RTC");
      while (1);
    }

    if (rtc.lostPower()) {
      Serial.println("RTC lost power, lets set the time!");

      // Comment out below lines once you set the date & time.
      // Following line sets the RTC to the date & time this sketch was compiled
      rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

      // Following line sets the RTC with an explicit date & time
      // for example to set January 27 2017 at 12:56 you would call:
      //rtc.adjust(DateTime(2017, 1, 27, 12, 56, 0));
    }
  }

  pinMode(segA, OUTPUT);
  pinMode(segB, OUTPUT);
  pinMode(segC, OUTPUT);
  pinMode(segD, OUTPUT);
  pinMode(segE, OUTPUT);
  pinMode(segF, OUTPUT);
  pinMode(segG, OUTPUT);
  pinMode(segDP, OUTPUT);
  pinMode(hPin,INPUT_PULLUP);

  pinMode(digit1, OUTPUT);
  pinMode(digit2, OUTPUT);
  pinMode(digit3, OUTPUT);
  pinMode(digit4, OUTPUT);
  pinMode(digit5, OUTPUT);
  pinMode(digit6, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode (encoder0PinA, INPUT);
  pinMode (encoder0PinB, INPUT);

}




void loop() {

  //DateTime now = Myset.now();
  DateTime now = rtc.now();

  reading = digitalRead(buttonPin);

  if (reading != lastButtonState) {
    // reset the debouncing timer
    lastDebounceTime = millis();
  }

  if ((millis() - lastDebounceTime) > debounceDelay) {
    // whatever the reading is at, it's been there for longer than the debounce
    // delay, so take it as the actual current state:

    // if the button state has changed:
    if (reading != buttonState) {
      buttonState = reading;

      // only toggle the LED if the new button state is HIGH
      if (buttonState == LOW) {
        clickPin = clickPin + 1;
        delay(500);
      }
    }
  }

  //if (clickPin > 3) {clickPin =0;}
  // save the reading. Next time through the loop, it'll be the lastButtonState:
  lastButtonState = reading;

  if (clickPin==0){//*********************************************************

  DateTime future (now + TimeSpan(0, 0, 0, 0));

  long timp = future.hour() * 10000UL + future.minute() * 100 + future.second();
  Serial.println(" timp : ");
  Serial.print(timp);
sM = future.minute(); // load current minute for adjustment
sH = future.hour(); // load current hours for adjustment

//*************************************************************************************
//24 details code 
//*************************************************************************************

int hData = digitalRead(hPin);
if (hData ==0){

  if (timp > 130000){
    timp = timp - 120000;
  }

}

//*************************************************************************************
//24 details code END
//*************************************************************************************

//----------------------------------------------------------------------------

  for (int i = 10 ; i > 0  ; i--) {
    if (timp >= 100000) displayNumber01(timp);
    else displayNumber02(timp);
  }

  }//*********************************************************



  
Serial.println(clickPin);

//*************************************************************************************
// Code for Segment LEDS
//*************************************************************************************
int Scnd = now.second();

if (Scnd != OldScnd){
          if (Scnd % 2==0){
            digitalWrite(segDP,HIGH);} else{digitalWrite(segDP,LOW);}
          }

 OldScnd = Scnd;
 //*************************************************************************************
 // Code for Segment LEDS END
 //*************************************************************************************

//*************************************************************************************
if (clickPin > 0){ // Editing Mode Started---------------------------------------------
//*************************************************************************************
  
n = digitalRead(encoder0PinA);
   if ((encoder0PinALast == LOW) && (n == HIGH)) {
     if (digitalRead(encoder0PinB) == LOW) {

            if (clickPin==1){sM = sM-1;delay(5); if (sM < 0)sM =59;delay(5);}
            if (clickPin==2){sH=sH-1; delay(5);if (sH < 0)sH =23;delay(5);}
            delay(100);
       
     } else {

            if (clickPin==1){sM = sM +1;delay(5); if (sM > 59)sM =0; delay(5);}
            if (clickPin==2){sH=sH+1;delay(5); if (sH > 23)sH =0;delay(5);}
           delay(100);
     }
     }
encoder0PinALast = n;
//DateTime now = rtc.now();
//Serial.println("H : ");
//Serial.println(future.hour(),DEC);

long timp = sH * 10000UL + sM *100;

  for (int i = 20 ; i > 0  ; i--) {
    if (timp >= 100000) displayNumber01(timp);
    else displayNumber02(timp);
  }

if (clickPin > 2){
   //DateTime future (now + TimeSpan(0, sH, sM, 0));
rtc.adjust(DateTime(1985, 4, 7, sH,sM, 0));
//rtc.adjust(DateTime(2017, 1, 27, 12, 56, 0));
delay(500);
sH=0;
sM=0;


clickPin=0; // reset the pin after saving time
  
}

//*************************************************************************************  
  }// Editing Mode END````````````````````````````````````````````````````````````````
//*************************************************************************************
  

}//===========================VOID LOOP END==============================================



void displayNumber01(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for (int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch (digit) {
      case 1:
        digitalWrite(digit1, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 2:
        digitalWrite(digit2, DIGIT_ON);
        //digitalWrite(segDP, LOW);
        break;
      case 3:
        digitalWrite(digit3, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 4:
        digitalWrite(digit4, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 5:
        digitalWrite(digit5, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 6:
        digitalWrite(digit6, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;

    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS);

    //Turn off all segments
    lightNumber(10);

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    digitalWrite(digit5, DIGIT_OFF);
    digitalWrite(digit6, DIGIT_OFF);
  }
}

void displayNumber02(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for (int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch (digit) {
      case 1:
        lightNumber(10);
        //digitalWrite(segDP, HIGH);
        break;
      case 2:
        digitalWrite(digit2, DIGIT_ON);
        //digitalWrite(segDP, LOW);
        break;
      case 3:
        digitalWrite(digit3, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 4:
        digitalWrite(digit4, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 5:
        digitalWrite(digit5, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 6:
        digitalWrite(digit6, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS);

    //Turn off all segments
    lightNumber(10);

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    digitalWrite(digit5, DIGIT_OFF);
    digitalWrite(digit6, DIGIT_OFF);
  }
}

void displayNumber03(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for (int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch (digit) {
      case 1:
        digitalWrite(digit1, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 2:
        digitalWrite(digit2, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 3:
        digitalWrite(digit3, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 4:
        digitalWrite(digit4, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 5:
        digitalWrite(digit5, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 6:
        digitalWrite(digit6, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS);

    //Turn off all segments
    lightNumber(10);

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    digitalWrite(digit5, DIGIT_OFF);
    digitalWrite(digit6, DIGIT_OFF);
  }
}

void displayNumber04(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for (int digit = 4 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch (digit) {
      case 1:
        lightNumber(10);
        //digitalWrite(segDP, HIGH);
        break;
      case 2:
        digitalWrite(digit2, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 3:
        digitalWrite(digit3, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 4:
        digitalWrite(digit4, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 5:
        digitalWrite(digit5, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 6:
        digitalWrite(digit6, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS);

    //Turn off all segments
    lightNumber(10);

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    digitalWrite(digit5, DIGIT_OFF);
    digitalWrite(digit6, DIGIT_OFF);
  }
}

void displayNumber05(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for (int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch (digit) {
      case 1:
        digitalWrite(digit1, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 2:
        digitalWrite(digit2, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 3:
        digitalWrite(digit3, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 4:
        digitalWrite(digit4, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 5:
        digitalWrite(digit5, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
      case 6:
        digitalWrite(digit6, DIGIT_ON);
        //digitalWrite(segDP, HIGH);
        break;
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS);

    //Turn off all segments
    lightNumber(10);

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    digitalWrite(digit5, DIGIT_OFF);
    digitalWrite(digit6, DIGIT_OFF);
  }
}

void displayNumber06(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for (int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch (digit) {
      case 1:
        digitalWrite(digit1, DIGIT_ON);
       // //digitalWrite(segDP, HIGH);
        break;
      case 2:
        digitalWrite(digit2, DIGIT_ON);
        ////digitalWrite(segDP, HIGH);
        break;
      case 3:
        digitalWrite(digit3, DIGIT_ON);
        ////digitalWrite(segDP, HIGH);
        break;
      case 4:
        digitalWrite(digit4, DIGIT_ON);
        ////digitalWrite(segDP, HIGH);
        break;
      case 5:
        digitalWrite(digit5, DIGIT_ON);
        ////digitalWrite(segDP, HIGH);
        break;
      case 6:
        digitalWrite(digit6, DIGIT_ON);
        ////digitalWrite(segDP, HIGH);
        break;
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS);

    //Turn off all segments
    lightNumber(10);

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    digitalWrite(digit5, DIGIT_OFF);
    digitalWrite(digit6, DIGIT_OFF);
  }
}
//Given a number, turns on those segments
//If number == 10, then turn off number
void lightNumber(int numberToDisplay) {

#define SEGMENT_ON  HIGH
#define SEGMENT_OFF LOW

  switch (numberToDisplay) {

    case 0:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_ON);
      digitalWrite(segF, SEGMENT_ON);
      digitalWrite(segG, SEGMENT_OFF);
      break;

    case 1:
      digitalWrite(segA, SEGMENT_OFF);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_OFF);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_OFF);
      digitalWrite(segG, SEGMENT_OFF);
      break;

    case 2:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_OFF);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_ON);
      digitalWrite(segF, SEGMENT_OFF);
      digitalWrite(segG, SEGMENT_ON);
      break;

    case 3:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_OFF);
      digitalWrite(segG, SEGMENT_ON);
      break;

    case 4:
      digitalWrite(segA, SEGMENT_OFF);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_OFF);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_ON);
      digitalWrite(segG, SEGMENT_ON);
      break;

    case 5:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_OFF);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_ON);
      digitalWrite(segG, SEGMENT_ON);
      break;

    case 6:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_OFF);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_ON);
      digitalWrite(segF, SEGMENT_ON);
      digitalWrite(segG, SEGMENT_ON);
      break;

    case 7:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_OFF);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_OFF);
      digitalWrite(segG, SEGMENT_OFF);
      break;

    case 8:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_ON);
      digitalWrite(segF, SEGMENT_ON);
      digitalWrite(segG, SEGMENT_ON);
      break;

    case 9:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_ON);
      digitalWrite(segG, SEGMENT_ON);
      break;

    // all segment are ON
    case 10:
      digitalWrite(segA, SEGMENT_OFF);
      digitalWrite(segB, SEGMENT_OFF);
      digitalWrite(segC, SEGMENT_OFF);
      digitalWrite(segD, SEGMENT_OFF);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_OFF);
      digitalWrite(segG, SEGMENT_OFF);
      break;

  }

} // ending the code

      
The circuit diagram can be seen in the youtube posts as well. Download the Code : bit.ly/3HCpwWt


Saturday, 22 January 2022

Programming DS 3231 RTC module with Arduino



DS3231 is a low-cost, extremely accurate I2C real-time clock (RTC), with an integrated temperature-compensated crystal oscillator (TCXO) and crystal. The device incorporates a battery input, disconnect the main power supply and maintains accurate timekeeping. Integrated oscillator improve long-term accuracy of the device and reduces the number of components of the production line. The DS3231 is available in commercial and industrial temperature ranges, using a 16-pin 300mil SO package.

Buy now the module with a discount DS3231 Module

RTC maintains seconds, minutes, hours, day, date, month, and year information. Less than 31 days of the month, the end date will be automatically adjusted, including corrections for leap year. The clock operates in either the 24 hours or band / AM / PM indication of the 12-hour format. Provides two configurable alarm clock and a calendar can be set to a square wave output. Address and data are transferred serially through an I2C bidirectional bus.

 

Module parameters:

1. Size: 38mm (length) * 22mm (W) * 14mm (height)

2. Weight: 8g

3. Operating voltage :3.3 - 5 .5 V

4. Clock chip: high-precision clock chip DS3231

5. Clock Accuracy :0-40 range, the accuracy 2ppm, the error was about 1 minute

6. Calendar alarm clock with two

7. Programmable square-wave output

8. Real time clock generator seconds, minutes, hours, day, date, month and year timing and provide valid until the year 2100 leap year compensation

9. Chip temperature sensor comes with an accuracy of ± 3

10. Memory chips: AT24C32 (storage capacity 32K)

11. IIC bus interface, the maximum transmission speed of 400KHz (working voltage of 5V)

12. Can be cascaded with other IIC device, 24C32 addresses can be shorted A0/A1/A2 modify default address is 0x57

13. With rechargeable battery LIR2032, to ensure the system after power failure, the clock move any natural normal

14. Packing: single anti-static packaging

 



Wiring instructions ( for Arduino uno r3 for example):

SCL → A5

SDA → A4

VCC → 5V

GND → GND

 This is an introduction video about DS 3231 RTC module which I am going to use in LED clock building. There are 6 pins, but I am using only 4 pins for this purpose.

Connect ground pin of the module to the ground of Arduino, and connect VCC pin of the module to the arduino 5 volt pin. Then connect SDA pin of the module to the arduino analog pin number 4 and the SCL pin of the module to the arduino analog pin number 5.






Now the wiring part is over. You can test the module with serial monitor. Before that, you have to download the DS 3231 library. The link to download is given below.

Once the zip file is downloaded, open the arduino software and go to 

Sketch > include Library > add Zip library.



From the opened window, navigate the location of the library zip file is downloaded and select the file then ADD.


Library is now added.

Download the code from the link given below and upload to the arduino.

After the code is uploaded, you can open the serial monitor to check the time.



Study the programme as you need to work with this in future as well.

I hope you understand the basics about the DS 3231 RTC module.

Stay with setnfix. 


Monday, 13 September 2021

Car Battery Faults indicator : Low/Charge/Good and Engine Start/Alternator Testing




Due to the travel restrictions, i was unable to start my car around one week.

However, a day, I had an important work and I tried to start the car. The car did not start.

Then I checked the battery and the battery level was 8.7 volts. It is impossible. then I checked an un usual power consumption even the car is stopped. There was a simple wire short.
That time, I thought that if there is a way to notify that the low battery, It would be a great help to avoid such difficulties. Therefore, I decided to create this circuit and tested well.


You can build this on a vero board or on a PCB as follows.



Battery is Good, But need to be charged

Alternator is working well, Battery is good and the car engine started

Battery is low/bad





Watch the details.







Sunday, 5 September 2021

How to activate any Microsoft Office Package for Free

Microsoft office package is the most of users are using for personal and official documents, calculations and data base requirements. However, it is more high risk to use a crack software as there may be virus harm to you device. Therefore, This tutorial will help you to solve that issue.

Follow these steps and activate your office package.


STEP 01 :

1st you have to find the Microsoft office package version. You can find it visiting Files > Account.


STEP 02 :

Then find the path of the software installed in your computer



STEP 03 :

Then Copy the path

STEP 04 :

Now, Open the File given in the following link and paste the path as follows



STEP 05 :

Then copy a serial key as suitable to your Ms Office package and paste as follows.


STEP 06 :

Now Search "CMD" and Run as Administrator the Command Prompt


STEP 07 :
Now Copy the 1st code in the text file and press on the command prompt and press enter.


STEP 08 :
Now Copy the 2nd code in the text file and press on the command prompt and press enter. Wait a while....



STEP 09 :
Now Copy the 3rd code in the text file and press on the command prompt and press enter. Wait a while....



STEP 10 :
Now Copy the 4th code in the text file and press on the command prompt and press enter. Wait a while....


Now you can see the activation is successful message.



Download the file


Watch For More






Saturday, 7 August 2021

Tank Water Level Indicator.


You may have bad experiences having forgotten to close the water valve and wasting water and money 😉. Or you nay have a bad experience having forgotten to fill the water tank and no water situations.

I know that you will realize this is not an complex circuit but this is very useful to solve those issue in your real life.

Since it is a simple circuit, shall we move to the project.

The circuit is based on 4 transistors and the out out is given by 4 LEDs. Following are the required parts.

  • 2N2222 Transistors









  • 120 ohm Resistors









  • LEDs







  • Wires and cables.
  • a PVC pipe

The circuit is given below.



Watch the following video for more details.

Wednesday, 28 July 2021

Car Steering Wheel Control Unit with Arduino


 If you are a regular visitor to my website or YouTube Channel, you have already experience the same kind of project. The purpose of making this project is to make help the vehicle owner that they have no Steering Wheel audio control switches. But I know including me it is very helpful to control audio using such physicals switches.

The previous tutorial was about making a simple controller with switches. But I wanted to improve it especially for traditional volume controllers and few more important switches. 
Accordingly, I was done some researches to make this project successful. I will show those testing projects as well later.

Watch the Video Description.




The final project is included especially two controllers with Rotary Encoders. One is for Volume and another one is for move the back and next.




You may need the following parts,


Atmega 328P IC                     -    01


16Mhz Cristal                         -    01








22pf ceramic capacitors          -    02











D400 Transistors                     -    04











Rotary Encoders                      -    02











7805 Regulator                        -    01











104 pf Ceramic                        -    01











10uf capacitor                         -     01











IN 4001 Diode                        -    01






27k (1/4W)Resistors               -    04











100 pf Capacitors                    -    04











10k (1/4W)Resistors               -    10










5k Preset                                    -  01











1 k (1/4W) Resistors                    01

Wires











Arduino Board










Soldering equipment's







Connectors, etc,
























Plastic Box












Read the Following circuit diagram carefully before making the project.

You can use the following PCB plan for easy construction.




You can use the following link to download the diagram.


How to connect the wires.

01. Give the power 12 volts from the car ACC wire and ground the pin correctly.

02.Connect KEY 1 wire with the KEY 1 of the unit and 
    There may be two wires called “KEY” and “KEY 1” in-car head unit. Sometimes the “KEY” wire will not work correctly. If so connect the KEY 1 wire with the car steering wheel control unit.


03.Tune the correct delay to activate the switch using the 5k preset.

Go to the Settings >Steering Wheel Learning of your car head unit Then,








Touch the "volume UP button" of the car head unit and rotate to right side the rotary encoder 1. If the device is not detected or the click is too much long, adjust the delay time using 5k variable resistors (preset)

Then Touch the "volume DOWN" button of the car head unit and rotate to the left side the rotary encoder 1.

AliExpress.com Product - Scrubs Medical Uniforms Women 2021 Short Sleeve V-Neck Pocket Care Workers T-Shirt Tops Summer uniformes de enfermera mujer A50

 Accordingly, you can program all the keys.

Check the video for more details. Steering Learning



You can download the arduino code from the following link.



/*this car steering wheel audio control buttons is programmed as universal circuit.
 * This can be used to Volume up and down and, to back and next button. The both rotary encoder 
 * swiches are recommended for that purposes. and also more 2 switches are with the rotary encoders.
 * 
 * Programmed by : BMIAK Basnayaka
 * for SetNFix Youtube channel
 * web : http://www.setnfix.com
 * date : 08.06.2021
 * Video Link https://youtu.be/m4KO8INEGUo
 */





//Volume Controler
int testPin=A0;
int volOne = A2;
int volTwo = A1;
 int directionV=0;
 int counterV = 0; 
 int currentStateCLKV;
 int previousStateCLKV; 

//Next and previous Button
#define nextOne A4
#define nextTwo  A3
 int counterN = 0; 
 int currentStateCLKN;
 int previousStateCLKN;

int progSwitch = A5;
int progData=0;

int volUp = 12;
int volDown = 11;
int back = 10;
int next = 9;

int delayMe =0; // Time need to click a button to activate 1000 = 1 second
int delayBtn = 2000; // Time need to click a button to prgramme the buttons 1000 = 1 second



void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);

pinMode(volOne,INPUT);
pinMode(volTwo, INPUT);
pinMode(nextOne,INPUT);
pinMode(nextTwo,INPUT);
pinMode(progSwitch,INPUT);
pinMode(volUp,OUTPUT);
pinMode(volDown,OUTPUT);
pinMode(back,OUTPUT);
pinMode(next,OUTPUT);
pinMode(testPin,OUTPUT);

  previousStateCLKV = digitalRead(volOne);
  previousStateCLKN = digitalRead(nextOne);
}

void loop() {


progData = analogRead(progSwitch);
delayMe = map(progData,0,1023,200,2000);

//Serial.println(delayMe);
volumeControler();
nextPrevious();





//
//delay(1000);

}

  
void volumeControler(){
  //Volume Controler
// Read the current state of inputCLK
currentStateCLKV = digitalRead(volOne);

//Serial.println(currentStateCLKV);

   // If the previous and the current state of the inputCLK are different then a pulse has occured
   if ((currentStateCLKV == LOW)&&(previousStateCLKV==HIGH)){ 
       
//Serial.println(currentStateCLKV);
     // If the inputDT state is different than the inputCLK state then 
     // the encoder is rotating counterclockwise
     if (digitalRead(volTwo)==LOW) { 
           
        digitalWrite(volDown,HIGH);
        analogWrite(testPin,10);
        Serial.println("DOWN");
        delay(delayMe);
        digitalWrite(volDown,LOW);
        analogWrite(testPin,0);
       //previousStateCLKV = currentStateCLKV; 
       
     } else {
      
       // Encoder is rotating clockwise
        digitalWrite(volUp,HIGH);
        analogWrite(testPin,20);
        Serial.println("UP");
        delay(delayMe);
        digitalWrite(volUp,LOW);
        analogWrite(testPin,0);
      // previousStateCLKV = currentStateCLKV; 
     }
//Serial.println(counterV);
   } 
   // Update previousStateCLK with the current state
   previousStateCLKV = currentStateCLKV; 


/*if (directionV == 1){
digitalWrite(volDown,HIGH);
Serial.println("DOWN");
delay(delayMe);
digitalWrite(volDown,LOW);directionV =0;}

if (directionV == 2){
digitalWrite(volUp,HIGH);
Serial.println("UP");
delay(delayMe);
digitalWrite(volUp,LOW);directionV =0;}
*/



}

void nextPrevious(){

// Read the current state of inputCLK
   currentStateCLKN = digitalRead(nextOne);
    
   // If the previous and the current state of the inputCLK are different then a pulse has occured
   if ((currentStateCLKN==LOW) && (previousStateCLKN==HIGH)){ 
       
     // If the inputDT state is different than the inputCLK state then 
     // the encoder is rotating counterclockwise
     if (digitalRead(nextTwo) ==LOW) { 
       counterN --;
        digitalWrite(next,HIGH);
        analogWrite(testPin,30);
        Serial.println("BACK");
        delay(delayMe);
        analogWrite(testPin,0);
        digitalWrite(next,LOW);
       
       
     } else {
       // Encoder is rotating clockwise
       counterN ++;
        digitalWrite(back,HIGH);
        Serial.println("NEXT");
        analogWrite(testPin,40);
        delay(delayMe);
        digitalWrite(back,LOW);
        analogWrite(testPin,0);
       
     }

   } 
   // Update previousStateCLK with the current state
   previousStateCLKN = currentStateCLKN; 
 }