Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Wednesday, March 7, 2018

Arduino relay, control 220v devices code and hardware(circuit diagram)

At the first part of the video (Part-A), I will explain each line of the small code.
At the second part of the video (Part-B) I will build the hardware.

I  build a solution to power on a water pump(or other 220v devices) when there is water overflow.
You can do it to power on other AC (220V) appliances such as Lights, TVs, etc.


Part-A (Code explanation).

Video link for Part-A below this line:
https://youtu.be/mQLTWnA4ZHI


Download code here: Download link
or copy the code unter this line:


#define relay1 4             //Defines pin 4
#define relay2 7             //Defines pin 7         
#define sensor 2          //Define sensor pin 2 (input pin)
#define alwaysHigh 10     //gives 5v to the sensor
//#define ledPin 8 

int sensorState=0;    //keeps the reading of sensor pin 2 (high or low)
int flag=0;     // Takes values 0 or 1. When the sensorState changes.

void setup() {
 // Open serial communications and wait for port to open:
  Serial.begin(9600);

    //pinMode(ledPin, OUTPUT);  // Set the LED pin as output
    pinMode(sensor, INPUT);     // Set the Sensor pin as input
 
    pinMode(relay1, OUTPUT);     
    pinMode(relay2, OUTPUT);
    pinMode (alwaysHigh, OUTPUT);   //5V sourch, gives power to sensor
 
 
    digitalWrite(relay1, !(LOW));  //OFF
    digitalWrite(relay2, !(LOW));  //OFF
    digitalWrite(alwaysHigh, HIGH); //ON

    Serial.println("Relay-1 is OFF");
    Serial.println ("Relay-2 is OFF");
    Serial.print("\n");
}


void loop() {
    sensorState= digitalRead(sensor);
    //Serial.println(sensorState);
    if (sensorState == HIGH) {               // check if the sensor is in water(short circuit)
      digitalWrite(relay1, !(HIGH));                  // turns Relay1 ON
      digitalWrite(relay2, !(HIGH));                  // turns Relay2 ON
      if (flag==0){
        flag=1;
        Serial.println("relays are now ON");
      }
    }
    else{
      digitalWrite(relay1, !(LOW));             // turns Relay1 OFF                       
      digitalWrite(relay2, !(LOW));             // turns Relay2 OFF
      if (flag==1){
        flag=0;
        Serial.println("relays are now OFF");
      }
    }
} //loop end bracket


Part-B (Hardware)


Video link for Part-B below this line:
https://youtu.be/mimGR6aEHNA




Saturday, January 16, 2016

Arduino HC-06 bluetooth pc-button (schema and arduino code here)

The following project gives you the ability to switch on your desktop computer over bluetooth.

The way this thing works is:  You send a command over bluetooth (by pressing a key on your phone) and the electromagnet(attached on the arduino nano) connects two cables (that are acting as a switch).

The following circuitry support 5V and 12V electromagnets with the usage of PN222A transistor as shown 

It is necessary to connect those two cables direct on the mainboard of your pc (where the power button connector is  placed)

Another alternative could be a relay switch, but in this case I used an electromagnet.
 




Video on Youtube   --> https://youtu.be/ChciUi8SHEA





Arduino Code under this line:


//  voulios.blogspot.com (Technology Blog)
//  Chrysovalantis Eleftheriadis

int button = 8;  
int state;        //State '1' activates power-on button, state '0' deactivates it.
int flag=0;       //makes sure that the serial only prints once the state


void setup() {
    pinMode (button, OUTPUT);
    Serial.begin(9600);
}

void loop() {
    //if some date is sent, reads it and saves in state
    if(Serial.available() > 0){    
      state = Serial.read();
      Serial.println(state);  
      flag=0;
    }  
   
    if (state == '0') {   
        digitalWrite(button, LOW);
        if(flag == 0){
          Serial.println("Button is deactivated");
          flag=1;
        }
    }

    //Receives '1' from serial and activates the power button for 3 secs
    else if (state == '1') {
        digitalWrite(button, HIGH);     //activates the button
        delay(3000);                    //for three seconds
        state='0';                      //sets the state to '0' (for the next loop)
        if(flag == 0){
          Serial.println("Power Button has been pressed for 3 seconds");
          flag=1;
        }
    }
          

}


Saturday, August 15, 2015

Automatically Turn Off Your Computer. Windows shutdown app. Shutdown Timer. Free download, C source code

For your reasons you want to shutdown your computer after minutes or an hour, etc.
With this simple app you can shutdown your computer in a very simple way.

1. Execute the program
2. Give the minutes you want your computer to shutdown
3. That is all. The computer will automatic shutdown


Download here



Otherwise you could run CMD (Command Prompt)

C:\> shutdown -s -t 180    -Enter-
-s   means shutdown computer
-t   means after how many seconds will execute the command
180 are the seconds after that will the computer shutdown
 --------------------------------
C:\> shutdown -a      -Enter-
-a   mean abort the shutdown execution
with this command you will abort shutdown



------------------------------------
------------------------------------



-----------------------------------
C Code after this line
-----------------------------------
#include <stdio.h>
#include <time.h>
#include <windows.h>






//delay code-block
void delay (unsigned int secs) {
    unsigned int retTime;
    retTime = time(0) + secs;     // Get finishing time.
    while (time(0) < retTime);    // Loop until it arrives.
}





int main()
{
    int i;
    int minutes;
    int flag=0;
   
    minutes=0;
   
   
       
       
    printf ("Give minutes to Shutdown: ");
    scanf("%d", &minutes);
    minutes= minutes *60;




    delay(minutes-30);       
    printf("Remaining 30 secs\n");
    delay(20);
   
   
    printf ("Remaining less than 10 seconds, press continuously ESC to abort\n");
    for (i=10;i>=0;i--)
    {
        delay(1);        //delay 10 seconds
        printf("\n");
        printf("Remaining secs: %d", i);


       
        if(GetAsyncKeyState(VK_ESCAPE ) < 0)
        {
            flag=1;
            break;
        }
       
    }
   
    if (flag==0)
        system("shutdown /s");
    return 0;
}

Thursday, July 23, 2015

Task killer with new features. End the processes easy. C delay, store in file

The New version of task killer, features:

1) Delay on execution, and ability to change the process-name

 Download Here: Download



Code in C
-----------------------------------
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <windows.h>
#define length 30



//delay code-block
void delay (unsigned int secs) {
    unsigned int retTime;
    retTime = time(0) + secs;     // Get finishing time.
    while (time(0) < retTime);    // Loop until it arrives.
}

int main(void)
{
    char str[length];
    char command[length];
    int i;
    int name_change;    //To change the process name in the file.log
    FILE *file;         //My text file where i store the process name
   
   
    name_change=0;
   
   
   
   
    //new vls start
    printf ("If you want to change the process name \nPress continiusly the Shift Key\n");
   
    for (i=10;i>=0;i--)
    {
        delay(1);        //delay 10 seconds
        printf("\n");
        printf("Remaining secs: %d\n", i);

    //If enter is continiusly pressed, Then you can change the process name   
    if(GetAsyncKeyState(16 ) < 0)
        {
        printf("Shift is pressed\n");
        name_change=1;
        break;
        }
   
    //if(GetAsyncKeyState(16 ) < 0)
    //    printf("Shift is pressed");
    //if(GetAsyncKeyState(13 ) < 0)
    //    printf("Enter is pressed");

    }
   
   
   
   
    //new vls start
   
    fflush(stdin);
    if (name_change==1)
    {
        printf ("Give Proccess name: ");
        scanf ("%s", &str);
        printf ("you gave: %s\n");
       
       
        //file=fopen("keys.log","a+");     //To add new strings
        //fputs("Valantis",file);
       
        file=fopen("keys.log", "w+");    //To replace an old string with a new one
        fputs(str, file);
        fflush(file);
       
    }
   
    //test end
   
   
   

   
   
   
    //vls start
       fflush(stdin);    //new
    file=fopen("keys.log", "r");//"w+");    //To read from file (only)
    fseek(file, SEEK_SET, 0);

      
   
   


    /* Read and display data */
    fread(str, length, 1, file);
    //new
    int count=0;
    for (i=0;i<length;i++)
    {
   
    count+=1;
    //printf("Total Characters =%d",count);
    }
    //new
   
       fclose(file);
    //vls end
   
    strcpy(command, "taskkill /F /IM ");
    strcat(command, str);
    strcat(command, ".exe");
   
    printf ("\n");
    //printf("%s\n", command);
   
    system (command);
   
   

return 0;
}


-----------------------------------

Wednesday, July 22, 2015

Task kill with C. Kill processes on windows Vista/win7

A simple routine which kills processes on windows: vista/win7. You can simply write the name of the proccess and done. Process is terminated


The other way to do it is to write on cmd (command prompt) the following command:
Start -> CMD -> Enter ->
C:\> taskkill /F /IM nameOfProcess.exe



You can download source code and executable file Here: Download

Saturday, January 10, 2015

Learn how can you sum two numbers on C with an extra easy video guide

CODE

--Copy from the line below--

#include <stdio.h>

main()  
{
int number1 = 10;   
int number2 = 20;
int sum;       
sum = number1 + number2;  
printf("The Sumary of Number1 %d with number2 %d is the following %d", number1, number2, sum);
scanf("%d", &sum);
}
--Until the line above --