Question
program in arduino
17. Implement the luminosity control of street lighting lamp which has 3 different levels of intensity according to the level
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <Wire.h>
#include <LiquidCrystal.h>
#include "RTClib.h"
#define ON 0
#define OFF 1
DateTime now;

RTC_DS3231 rtc;
LiquidCrystal lcd(8, 7, 6, 5, 4, 3); // (rs, e, d4, d5, d6, d7)

const int buttonPin = 2;
const int led=11;
int nob = A3;
int val = 0;
int val1 = 0;
int path=1;
int a=1;
int previousState = HIGH;
unsigned int previousPress;
volatile int buttonFlag;
int buttonDebounce = 20;

int on_hour=1;
int on_minute=1;
int on_second=10;

int off_hour=23;
int off_minute=57;
int off_second=10;

int c_hour=0;
int c_minute=0;
int c_second=0;

int onOrOffFlag = ON;

void showDate(void);
void showTime(void);
void showDay(void);

void loadHandler(int, int , int , int , int , int , int , int , int );

typedef struct userTime
{
int temp_hour;
int temp_minute;
int temp_second;
}userTime_t;
unsigned char checkLessThanOrEqual(userTime_t , userTime_t);


void setup ()
{
Serial.begin(9600);
lcd.begin(16,2);
  
pinMode(buttonPin, INPUT_PULLUP);
pinMode(led,OUTPUT);
attachInterrupt(digitalPinToInterrupt(buttonPin), button_ISR, CHANGE);
  
if (! rtc.begin())
{
Serial.println("Couldn't find RTC Module");
while (1);
}

if (rtc.lostPower())
{
Serial.println("RTC lost power, lets set the time!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  
}

void loop ()
{
if(path)
{
if(a==1)
{
lcd.setCursor(0,0);
lcd.print(" RTC ");
lcd.setCursor(0,1);
lcd.print(" MODE ON ");
delay(2000);
a=0;
}
now = rtc.now();
showTime();
c_hour=now.hour();
c_minute=now.minute();
c_second=now.second();
loadHandler( on_hour, on_minute, on_second, off_hour, off_minute, off_second, c_hour, c_minute, c_second);
delay(1000);
}
else
{
if(a==0)
{
lcd.setCursor(0,0);
lcd.print(" LDR ");
lcd.setCursor(0,1);
lcd.print(" MODE ON ");
delay(2000);
a=1;
}
val = analogRead(nob);
if(val>300 && val<450)
{
lcd.setCursor(0,0);
lcd.print(" 30% ");
lcd.setCursor(0,1);
lcd.print(" Brightness ");
analogWrite(led, 400);
}
else if(val>450 && val<550)
{
lcd.setCursor(0,0);
lcd.print(" 60% ");
lcd.setCursor(0,1);
lcd.print(" Brightness ");
analogWrite(led, 600);
}
else if(val>550 && val<600)
{
lcd.setCursor(0,0);
lcd.print(" 100% ");;
lcd.setCursor(0,1);
lcd.print(" Brightness ");
analogWrite(led, 1023);
}
else if(val<300)
{
lcd.setCursor(0,0);
lcd.print(" 0% ");
lcd.setCursor(0,1);
lcd.print(" Brightness ");
analogWrite(led, 0);
}
}
}

void showTime()
{
lcd.setCursor(0,0);
lcd.print(" Time:");
lcd.print(now.hour());
lcd.print(':');
lcd.print(now.minute());
lcd.print(':');
lcd.print(now.second());
lcd.print(" ");
}


void button_ISR()
{
buttonFlag = 1;
if((millis() - previousPress) > buttonDebounce && buttonFlag)
{
previousPress = millis();
if(digitalRead(buttonPin) == LOW && previousState == HIGH)
{
path =! path;
previousState = LOW;
}
  
else if(digitalRead(buttonPin) == HIGH && previousState == LOW)
{
previousState = HIGH;
}
buttonFlag = 0;
}
}

unsigned char checkLessThanOrEqual(userTime_t a, userTime_t b)
{
if(a.temp_hour < b.temp_hour)
return true;
else
{
if ((a.temp_hour == b.temp_hour) && (a.temp_minute < b.temp_minute))
{
return true;
}
else
{
if(a.temp_hour > b.temp_hour)
return false;
else
{
if((a.temp_minute == b.temp_minute) && (a.temp_second < b.temp_second))
{
return true;
}
else
{
if(a.temp_minute > b.temp_minute)
return false;
else
{
if(a.temp_second == b.temp_second)
{
return true;
}
else
{
return false;
}
}
}
}
}
}
}

void loadHandler(int onTimeHr, int onTimeMin, int onTimeSec, int offTimeHr, int offTimeMin, int offTimeSec, int rtcTimeHr, int rtcTimeMin, int rtcTimeSec)
{

userTime_t in1 = {onTimeHr, onTimeMin, onTimeSec}, in2 = {offTimeHr, offTimeMin, offTimeSec}, rtc_hr = {rtcTimeHr, rtcTimeMin, rtcTimeSec}, a = {}, b = {};

if(checkLessThanOrEqual(in1, in2))
{
onOrOffFlag = ON;
memcpy(&a, &in1, sizeof(userTime_t));
memcpy(&b, &in2, sizeof(userTime_t));
}
else
{
onOrOffFlag = OFF;
memcpy(&a, &in2, sizeof(userTime_t));
memcpy(&b, &in1, sizeof(userTime_t));

}

if((checkLessThanOrEqual(a, rtc_hr)) && (checkLessThanOrEqual(rtc_hr, b)))
{
if(onOrOffFlag == ON)
{
// Switch on the load
digitalWrite(led,HIGH);
lcd.setCursor(0,1);
lcd.print("OffTime:");
lcd.print(off_hour);
lcd.print(':');
lcd.print(off_minute);
lcd.print(':');
lcd.print(off_second);

  
}
else
{
// Switch off the load
digitalWrite(led,LOW);
lcd.setCursor(0,1);
lcd.print(" OnTime:");
lcd.print(on_hour);
lcd.print(':');
lcd.print(on_minute);
lcd.print(':');
lcd.print(on_second);
  
}
}
else
{
if(onOrOffFlag == ON)
{
// Switch off the load
digitalWrite(led,LOW);
lcd.setCursor(0,1);
lcd.print(" OnTime:");
lcd.print(on_hour);
lcd.print(':');
lcd.print(on_minute);
lcd.print(':');
lcd.print(on_second);
}
else
{
// Switch on the load
digitalWrite(led,HIGH);
lcd.setCursor(0,1);
lcd.print("OffTime:");
lcd.print(off_hour);
lcd.print(':');
lcd.print(off_minute);
lcd.print(':');
lcd.print(off_second);
}
}
}

Add a comment
Know the answer?
Add Answer to:
program in arduino 17. Implement the luminosity control of street lighting lamp which has 3 different...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Implement the luminosity control of a street lighting lamp which has 3 different levels of intensity...

    Implement the luminosity control of a street lighting lamp which has 3 different levels of intensity according to the level of darkness. Problem for the arduino program, make the flow diagram.

  • Implement the luminosity control of a street lighting lamp which has 3 different levels of intensity according to the le...

    Implement the luminosity control of a street lighting lamp which has 3 different levels of intensity according to the level of darkness. Using Arduino the question is complete, it is a luminosity controller for a led with 3 levels of brightness.

  • Problem: Implement a FIFO program in which a client sends the server 3 variable names (strings)....

    Problem: Implement a FIFO program in which a client sends the server 3 variable names (strings). A valid variable name is defined for this assignment to be 6 characters or less, consisting only of lower-case letters from a to 'z', inclusive. The server checks the name for validity, and if valid, it counts the number of in the variable name. Each of the original variable names is sent back to the client, along with a message whether it is valid...

  • Question 2 (3 mark): Write a program to implement the class Coffee according to the following...

    Question 2 (3 mark): Write a program to implement the class Coffee according to the following UML diagram and description so that it can display as the output example. Coffee -energy: double -protein: double -fat: double +Coffee +Coffee _energy: double, _protein: double. _fat: double) Coffee(sourceCup: Coffee) -printNutrition Information(): void +main(String[] args): void REQUIREMENTS The program has three constructors: the first one is a default constructor, it initializes the 3 data fields (50.0, 1.5, 1.7) at default; the second initializes the...

  • Description In this homework, you are asked to implement a multithreaded program that will allow ...

    Description In this homework, you are asked to implement a multithreaded program that will allow us to measure the performance (i.e, CPU utilization, Throughput, Turnaround time, and Waiting time in Ready Queue) of the four basic CPU scheduling algorithms (namely, FIFO, SJE PR, and RR). Your program will be emulating/simulating the processes whose priority, sequence of CPU burst time(ms) and I'O burst time(ms) will be given in an input file. Assume that all scheduling algorithms except RR will be non-preemptive,...

  • QUESTION 3 a) Researchers want to test the effect of three different diets on the weight...

    QUESTION 3 a) Researchers want to test the effect of three different diets on the weight gain in 2 week- Diet 2 16 old lambs. The following table records the weight gain by the lambs. Diet 3 15 10 17 Diet 1 16 21 18 At the 0.05 level of significance, assess that there is a difference in the weight gain for each of the diet. (16 marks) b) Ten plots, each 10.4 meters, were randomly chosen in a large...

  • Create a JAVA program for a Kiosk management system. A local kiosk in your neighborhood has...

    Create a JAVA program for a Kiosk management system. A local kiosk in your neighborhood has been heavily challenged by the manual system currently used to manage the kiosk’s day to day operations. The kiosk management have been informed of your newly acquired knowledge in application development and have approached you to create an electronic management system. The system is meant to help the Kiosk in managing its stock and finances; with this in mind your application should then offer...

  • You have a network that spans 6 different sites, each of which has its own data network, each site has a network operator that takes care of the “sub”-network under his/her control.

    HW1.pdfYou have a network that spans 6 different sites, each of which has its own data network, each site has a network operator that takes care of the “sub”-network under his/her control. Current situation: Site Network ID Subnet Mask # of Departments PC /Dept Site 1: NetID: 152.24.48.0 Mask: 255.255.248.0 4 Departments: 180, 50, 240, 100 Site 2: NetID: 152.24.56.0 Mask: 255.255.248.0 5 Departments: 90, 110, 150, 130, 250 Site 3: NetID: 152.24.64.0 Mask: 255.255.252.0 4 Departments: 70, 110, 90,...

  • In Data 4.1 on page 258, we examine a study in which mice were randomly assigned to either a norm...

    In Data 4.1 on page 258, we examine a study in which mice were randomly assigned to either a normal light/dark cycle or to have a light on around the clock. According to the paper describing that study, "The global increase in the prevalence of obesity and metabolic disorders coincides with the increase of exposure to light at night." The study is examining whether light at night plays a causal role in the obesity epidemic. In Data 4.1, we examine...

  • 5) In recent weeks the stock markets in the Wall Street has show an unexpected level...

    5) In recent weeks the stock markets in the Wall Street has show an unexpected level of ups and downs mainly attributed to the uncertainty of healthcare reform under Trump administration and retail stores closing such as Macys’, JCPenny, Sears, another possible cutting govt. programs (in an effort to reduce budget deficit). In the process, the value of the $ has risen against the Euro, the Yuan (Renminbi), yen and many other currencies. A) Given the current condition of the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT