Skip to main content

Posts

Showing posts from November, 2011

InduinoX and wireless relays: Part II

In my last post , I played a bit with the wireless relays to turn on a light. In this post I will show how to use LDR to detect when to turn on the light depending on the ambient light. Lets dive into the code quickly #define TRUE  1 #define FALSE 0 int LIGHT_PIN = 7; int SLEEP_TIME = 100; int LDR_PIN = 3; int LDR_THRESHOLD_FOR_DARK = 350; int MAX_COUNT_BEFORE_TOGGLE = 10; int isLightOn = FALSE; int toggleCount = 0; void setup() {   turnOffDevice(LIGHT_PIN);   digitalWrite(LIGHT_PIN, LOW);   Serial.begin(115200); } void turnOffDevice(int pin) {   pinMode(pin, INPUT); } void turnOnDevice(int pin) {   pinMode(pin, OUTPUT); } void toggleLight() {   if (isLightOn) {     turnOffDevice(LIGHT_PIN);     isLightOn = FALSE;   } else {     turnOnDevice(LIGHT_PIN);     isLightOn = TRUE;   } } void toggleLightIfNecessary(int input, int threshold) {   if (input > threshold) {     toggleCount++;     if (toggleCou