Posted August 22, 20168 yr I thought this could be use full for some else as well. "Disclaimer - This relates to AC current run trough a relay with DC volts so if you didn't understand what this is do not continue!! - I do not take any responsibility for ANY damages or loss of life, fingers , wife and or pets included " (Just to cover my self ) I have some security lights around the house and a fairly high quality perimeter alarm system and to top it off a DVR jut to check in if the Alarm did go off. The power supply for the cameras takes a fair amount of juice to run and we only use the cameras to view remotely , also I dont care for recording as it is useless most of the time , in my case any way. The idea was to create a remote switch that I could switch the cameras on so that I could view what is going on if the need arises. Now I know Vellman has a kit that does something similar but the cost on the kit is quite high and you dont have much flexibility on it either. So this is what I came up with: A Arduino powered Relay controller with a LDR so that you can control the relay with one of those old cell phones that is somewhere in a drawer. Al that the cell phone must be able to do is Have a screen that lights up when you call it Have n call blocking feature that prevent some telemarketing guy switching on your camera / lights The kit costs is around : 1 x Arduino Compatible board ( They are quite cheap) R 190 on BoB 1 x Relay Board R 25 for a Single relay This is what I needed. 1 x LDR any size will do as you will calibrate later. 1 x Strip board to set everything up ( Maybe some one could get us some pc boards made up ) Some wires Now seeing that most of us here is DIY people I am not going to waste time on writing a full tutorial on how to build a PC board , setup Arduino and how this work , there is a massive amount of information available on the net on this topic and as per usual - Google is your friend. What I needed was Be able to turn on the security lights and Cameras at the same time if I wanted to look at the cameras or if we arrive late at home and need to get the lights on (You could use two relays but this will push your costs up as you would need most likely a GMS shield for this. I used a day night switch to prevent the lights to come on in day time.) Be able to turn the lights on or off in the house , else you will need to phone the relay If the alarm goes off the lights must come one and then stay on for a x amount of time after the Alarm is reset This basically works on the principle of the LDR detecting the phone screen light that come's on (Hence any old phone will do) and then trigger the relay, I build in a delay in the code so that if the phone screen does come on when blocking a call it will only be on for a short while , in my case the screen is on for only 2 seconds if it is a blocked number. When I call it I need it to ring for two times and the relay will trigger , you will need to play with the numbers to fit you phone ... Then I have a "Door bell" button in the house that you can push to turn the lights on or off. My Alarm also has a "gate" that closes when it get triggered so that is connected as well but you don not need to use it.You can only use the phone if you need just that. Now for the good stuff: First off , I am by no means a prolific programmer and most of what you see here is a general mashup of bits of code that I got over then net if you can improve on it PLEASE do so as I would also like to learn a bit more on it. This took me almost 4 weeks to figure out (part of it was not knowing what I was doing) so please don't go and try making money of this just share it along ...... (Thought it might be necessary to say that) // Pins that will be used int LDR = A0; // select the input pin for ldr const int LED = 13; // just a status LED to show that the relay is on or off ( You can go and check out side as well const int CheckPin = 11; // This pin is Used to ensure that Timer is only used when the Alarm Relay is activated first const int Relay = 10; // The Relay that Controls the Lights const int WallSwitch = 8; // The main switch that will be wall mounted (Might be a "bell" Push button (*PinButton) const int AlarmTrigger = 9 ; // The Relay that will be triggered when the alarm goes off (* Alarm Relay) //Variables int LDRValue = 0; // variable to store the value coming from the sensor int prev_LDRValue = 0; // variable to store the previous state of the sensor unsigned long LastOnTimeLDR = 0; int stateRelay = LOW; long startOnLDR = 0; // The Last time that input was recieved // Variables for the WallSwitch //int state = LOW; // the current state of the output pin int reading; // the current reading from the input pin int previous = LOW; // the previous reading from the input pin // the follow variables are long's because the time, measured in miliseconds, // will quickly become a bigger number than can be stored in an int. long time = 0; // the last time the output pin was toggled long debounce = 200; // the debounce time, increase if the output flickers // Variables that will be used for the Alarm Trigger int stateButtonAlarm ; // to Chek the state of the Alarm Relay int ledState = LOW; // ledState used to set the LED unsigned long previousMillis = 0; // will store last time LED was updated long OnTime = 100; // milliseconds of on-time long OffTime = 5000; //## milliseconds of how long before the light time goes off ## EDIT CODE TO DECIDE HOW LONG THE LIGHTS SHOULD BE ON## int stateCheckPin = LOW; void setup() { // Asighn the Pins to what they need to do pinMode (LED, OUTPUT); pinMode (CheckPin,OUTPUT); pinMode (Relay, OUTPUT); // Triggers that will give inputs pinMode (AlarmTrigger,INPUT); pinMode (WallSwitch, INPUT); Serial.begin(9600); //sets serial port for communication - you will need this to see what is you LDR's output to calibrate acordingly } void loop() { // LDR Code to Switch the Relay on or off by calling the Cell phone for X amount of time LDRValue = analogRead(LDR); // read the value from the sensor Serial.println(LDRValue); //prints the values coming from the sensor on the screen if (prev_LDRValue<=35 && LDRValue>35){ //first if statement check for LDR has gone from below 35 to above 35, and set startOnLDR to millis. startOnLDR=millis();// Start the Timer prev_LDRValue=LDRValue; } if (LDRValue<35) { startOnLDR=0; prev_LDRValue=LDRValue;} { if (startOnLDR!=0 and (millis()-startOnLDR) >=2000) { // ## EDIT THIS VALUE TO THE TIME THAT THE PHONE WILL BE ON## if (millis() - LastOnTimeLDR > 1000UL) { // To check if the relay was triggered before and to keep the relay on after the event. if(stateRelay == HIGH){ stateRelay = LOW; } else { stateRelay = HIGH; } } digitalWrite (LED , stateRelay) ; digitalWrite (CheckPin , HIGH) ; // This pin need to be set high to prevent other timed code to trigger the relay digitalWrite (Relay , stateRelay) ; LastOnTimeLDR = millis(); } delay(100); } // The code to Switch the Relay on or Off via the Wall switch reading = digitalRead(WallSwitch); // if the input just went from LOW and HIGH and we've waited long enough to ignore any noise on the circuit, toggle the output pin and remember the time if (reading == HIGH && previous == LOW && millis() - time > debounce) { if (stateRelay == HIGH) stateRelay = LOW; else stateRelay = HIGH; digitalWrite (CheckPin , HIGH ) ; // This pin need to be set high to prevent other timed code to trigger the relay time = millis(); } digitalWrite (LED, stateRelay ); digitalWrite (Relay , stateRelay ) ; previous = reading; // The Code to Switch the Relay on if triggered by the Alarm and the lights will be on for as long as the Alarm is sounding and there after still 10 Min stateButtonAlarm = digitalRead(AlarmTrigger); stateCheckPin = digitalRead(CheckPin); unsigned long currentMillis = millis(); if((stateButtonAlarm == HIGH ) && (currentMillis - previousMillis >= OnTime)) { stateRelay = HIGH; // Turn it on previousMillis = currentMillis; // Remember the time digitalWrite (CheckPin , LOW); // Chage to low so that timer can be used to switch the Light off digitalWrite(LED, stateRelay); // Update the actual LED digitalWrite (Relay,stateRelay); } else if ((stateButtonAlarm == LOW && stateCheckPin == LOW ) && (currentMillis - previousMillis >= OffTime)) // Only activate it Checkpin is Low { stateRelay = LOW; // turn it off previousMillis = currentMillis; // Remember the time digitalWrite(LED, stateRelay); // Update the actual LED digitalWrite (Relay,stateRelay); } }
August 22, 20168 yr Author 7 minutes ago, PaulF007 said: Here is a mock up of the setup that I used you would obviously use PIN 10 for the relay but I used the LED just to make sure every thing work as expected.
August 22, 20168 yr Author You could use a shield but this will push the costs up considerably and as I already have three phones laying around and only one need this suited me better - Many ways to skin a cat -
August 22, 20168 yr Author Heck you could also use a Bluetooth interface with a android phone ( My next project )
August 22, 20168 yr There's a project somewhere with an old Nokia phone for opening. Can't find it now, could only find this: http://hackaday.com/2015/01/01/controlling-nokia-phones-with-arduino/ The reference to Gnokii, I've used gnokii to send smses, works really well. I've also used Kannel with an old Vodacom stick to receive SMSes. That also worked better than I ever expected.
August 22, 20168 yr Author Cool that could do the trick as well a bit invasive for my knowledge but the sky is the limit with these micro possessors!
August 22, 20168 yr You could also just use a 12V day/night sensor to switch on the DVR! Much cheaper, and with less work Put both the phone and the day/night sensor in a dark container and it will trigger as soon as the phone rings. Then, if you want to, add a "delay off" circuit and set it to 30 minutes or whatever you need to ensure long enough recording. Stick the DVR + CCTV on a 12V battery to make life easier as well. BUT, with the Arduino you now have the ability todo some other stuff as well.
August 22, 20168 yr Author 15 minutes ago, SilverNodashi said: You could also just use a 12V day/night sensor to switch on the DVR! Much cheaper, and with less work Put both the phone and the day/night sensor in a dark container and it will trigger as soon as the phone rings. Then, if you want to, add a "delay off" circuit and set it to 30 minutes or whatever you need to ensure long enough recording. Stick the DVR + CCTV on a 12V battery to make life easier as well. BUT, with the Arduino you now have the ability todo some other stuff as well. The problem with this will be that you can get quite a few "false" switched , the phone number that I got from PEP gets atleas 5 or 6 sms/call's in a week and that is a brand "new" number ... The dvr on its own also does not take a lot of power , I dont have a hard drive installed. And if you keep that on the images comes on instant else you have to wait for the dvr to boot up. But as I said many ways to skin a cat , so I am told by the way , cats not my thing ...
August 22, 20168 yr 29 minutes ago, PaulF007 said: The problem with this will be that you can get quite a few "false" switched , the phone number that I got from PEP gets atleas 5 or 6 sms/call's in a week and that is a brand "new" number ... The dvr on its own also does not take a lot of power , I dont have a hard drive installed. And if you keep that on the images comes on instant else you have to wait for the dvr to boot up. But as I said many ways to skin a cat , so I am told by the way , cats not my thing ... True. Another, much simpler, but more expensive approach: Centurion has a GSM intercom. I use one for something similar, but with the intercom itself disabled (took the speaker & mic out). I can phone it to do something, or SMS it todo something else - in this case switch on a pump on the farm. The nice thing about it, is that the intercom is connected to the solar battery so I can send an sms to the intercom and get a voltage update as well. This one has two relays, which can be open / close as needed, and I had one spare
August 22, 20168 yr Author Cool. I am also looking into the Ethernet shield but then you need to be connected to the internet as well. So many option so little time ..
August 22, 20168 yr Just now, PaulF007 said: Cool. I am also looking into the Ethernet shield but then you need to be connected to the internet as well. So many option so little time .. There's a GSM shield as well
August 22, 20168 yr Author Jip I know but they are a bit pricey for my liking , the one problem with Arduino is that when you start playing with the addon's things can get a bit silly quickly. With the eEthernet shield I think you can get a bit more bang for your hard earned bucks ,,, If SAPO wasn't so bad these days Fleabay was always a good place for these things but lately its been a real pain ...
August 22, 20168 yr Author I had a look at these as well - Very Nice if you read the description - . http://www.miro.co.za/catalogue/micro-instruments-npm-r10-snmp-12-48v-50-amp/ http://www.miro.co.za/catalogue/micro-instruments-5-port-relay-board-for-npm-r9/ Can remember the price but will logon later and check what their dealer price was - memory serves it wasn't cheap ..
August 22, 20168 yr 6 minutes ago, PaulF007 said: If SAPO wasn't so bad these days Fleabay was always a good place for these things but lately its been a real pain ... For orders under R300... I'm okay if it gets lost. Most of the time it gets through, it just takes around 6 weeks. I ordered a canbus shield from alice1101983 along with some padding stuff, took a month and a day to get here. In that month I got impatient of course and made my own shield on strip board, but the shield arrived in time for prototyping, and it was actually quite nice having two of them :-)
August 22, 20168 yr 25 minutes ago, PaulF007 said: Ah I forgot about alice .... 24 years just waiting for a chance...
August 22, 20168 yr 5 hours ago, PaulF007 said: Jip I know but they are a bit pricey for my liking , the one problem with Arduino is that when you start playing with the addon's things can get a bit silly quickly. With the eEthernet shield I think you can get a bit more bang for your hard earned bucks ,,, If SAPO wasn't so bad these days Fleabay was always a good place for these things but lately its been a real pain ... Can you solder? Check this out: https://www.robotics.org.za/index.php?route=product/product&path=237&product_id=1514 Or this: https://www.robotics.org.za/index.php?route=product/product&path=237&product_id=1200
August 22, 20168 yr Author Ah now that's better. At that price I will learn how to solder - Same as working with a Axpert you get it cheap but then you also have to put in the effort. Thank you for posting that! Grrr now there goes little more of my money , going to use that one on my Generator auto start as there I would like some feedback...
August 22, 20168 yr 18 minutes ago, PaulF007 said: going to use that one on my Generator auto start Are you going to also auto switch off and measure the temp and fuel level?
August 22, 20168 yr Author Jip that why I would need the feed back. Some thing in the order of "Generator Started , Fuel medium , Oil ok , Temp ok. Maybe a status sms that will give you general feedback, Temp ectr, But I have the funny suspicion that I might need some guidance on some of the coding ... Obviously a SMS if some thing went wrong ... Any takers on such a project?
August 22, 20168 yr Jip that why I would need the feed back. Some thing in the order of "Generator Started , Fuel medium , Oil ok , Temp ok. Maybe a status sms that will give you general feedback, Temp ectr, But I have the funny suspicion that I might need some guidance on some of the coding ... Obviously a SMS if some thing went wrong ... Any takers on such a project? Look at mqqt. For comunication between devices. Sending mail ,sms ect. Sent from my SM-G920F using Tapatalk
August 22, 20168 yr Author Hold on a moment before we all go into Sheldon mode and over design a space rocket to get to the mall. I was thinking of going maybe Arduino with some Analog outputs. Most oil pressure units on these one cylinder engines is either high or low with no half and with the fuel level I would do the same , Full , half , stop with about 5L spare so that you don't run the engine dry , very bad for those small diesel pumps. On the temp I might do the same and run them all from the 12v Battery. Any way that was my thinking , that is also what my skills permits and will waste most of you guy's time if we go into anything higher grade.. Pfff - Running windows to start a generator
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.