Hello there,
I have a small problem, i don't know how to stop screen saver with arduino.
A few words about project....
I use Arduino UNO with motion sensor that is connected to PC (+Gobetwino app). When PC starts up, windows load normally a scrren saver after 1 min (i set this in windows settings). Now, what i want to do is that, when a user is near this motion sensor, arduino should do something to stop the screen saver and user should view normal desktop. When user isn't near PC, there should be running a scrren saver.
In my code when user is near PC, and the distance between PC and user is lower than 120cm, arduino should send a command to gobetwino and gobetwino run a vbs script that simulate key press. But somethings is wrong and often screen saver is not running after user absence.
I was thinking about key pressing or mouse click without using gobetwino. But those libraries aren't compatible with Arduino UNO.
Does anyone know how to fix that? Other solutions?
In my opinion there is something wrong with code... maybe delays?
In code there are also addintional libraries for RTC but with that everything is fine.
#include <Wire.h>
#include "RTClib.h"
#include <Time.h>
#include <TimeAlarms.h>
RTC_DS1307 rtc;
int Trig = 2;
int Echo = 3;
long EchoTime;
int Distance; // distance in cm
int MaximumRange = 200; // max distance
int MinimumRange = 2; // min distance
int zblizenie = 0; // variable for store if user is near pc
int temp = 0; // secondary variable for store information about position of user
// MOTION SENSOR SETTINGS
void czujnikSetup(){
pinMode(Trig, OUTPUT);
pinMode(Echo, INPUT);
}
// MOTION SENSOR OTHER SETTINGS
void czujnikLoop()
{
// set low TRIG 2us
digitalWrite(Trig, LOW);
delayMicroseconds(2);
// set high TRIG 10us
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
// set low TRIG - start measurement
digitalWrite(Trig, LOW);
EchoTime = pulseIn(Echo, HIGH);
// default - we calculate the distance
Distance = EchoTime / 58;
if (Distance < 120){ //user is near pc
zblizenie = 1;
}
else{ //user isn't near PC
zblizenie = 0;
}
}
// delay between another measurement
delay(200);
setThat();
}
// CONNECTION BETWEN SENSOR AND GOBETWINO
void setThat(){
if(zblizenie==temp){
if(temp==0){ // user isn't near pc
temp=1;
}
else if(temp==1){ //user is near pc
Serial.println("#S|KILL|[]#"); // send to gobetwino, gobetwino will run a script that simulate a key press so screen saver will turn off
temp=0;
}
}
}
// DEFAULT SETTINGS
void setup(){
Serial.begin(9600);
pinMode(13, OUTPUT);
czujnikSetup();
}
// MAIN PROGRAMM
void loop(){
czujnikLoop();
}