Question

In: Computer Science

THIS IS FOR ARDUINO PROGRAMMING Write code that checks the sensor data and meets the following...

THIS IS FOR ARDUINO PROGRAMMING

  1. Write code that checks the sensor data and meets the following conditions:
    1. For night conditions, turn on white LED 1
    2. For day conditions, turn off white LED 1
    3. Code should check intervals every 5 seconds.

NEED THE BELOW CODE TO FIT THE ABOVE REQUIREMENTS.

const int lightSensor = 5; //light sensor variable
float sensValue = 0; //variable to hold sensor readings
const int button = 3; //pin for button reads
const int LED1 = 5;
const int LED2 = 8; //

void SerialOutput() {
Serial.print(“Light Sensor Value=”); //send to screen
Serial.print(sensValue, 2); //output variable to screen
Serial.print(“\n”); //drop a line
}

void setup() {
// put your setup code here, to turn once:
pinMode(button, INPUT); //setup button pin for input reads
Serial.begin(9600); //start serial coms
}

void loop() {
// put your main code here, to run repeatedly:
sensValue = analogRead(lightSensor); //read from sensor
SerialOutput ();
delay(1000); //wait for 1 second
}

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks

const int lightSensor = 5; //light sensor variable
float sensValue = 0; //variable to hold sensor readings
const int button = 3; //pin for button reads
const int LED1 = 5;
const int LED2 = 8;

//light sensor value upto which is considered dark, or night
//change this as needed.
const int threshold = 200;

void SerialOutput()
{
    Serial.print("Light Sensor Value ="); //send to screen
    Serial.print(sensValue, 2); //output variable to screen
    Serial.print("\n"); //drop a line
}

void setup()
{
    // put your setup code here, to turn once:
    pinMode(button, INPUT); //setup button pin for input reads
    pinMode(LED1, OUTPUT); //setting LED1 for output
    Serial.begin(9600); //start serial coms
}

void loop()
{
    sensValue = analogRead(lightSensor); //read from sensor
    //if sensorValue is below threshold, it means its dark, or low light
    //in which case, we switch ON LED1
    if (sensValue <= threshold) {
        digitalWrite(LED1, HIGH);
    }
    //otherwise (value above threshold) we switch OFF LED1
    else {
        digitalWrite(LED1, LOW);
    }
    SerialOutput();
    delay(1000); //wait for 1 second
}

Related Solutions

We need to code an LCD with a temperature and humidity sensor for the arduino UNO...
We need to code an LCD with a temperature and humidity sensor for the arduino UNO board. The LCD should simply display the temperature and humidity reading from the DHT11 sensor. We must do this without the use of arduino or lcd libraries, and only use raw c code. For example we need to use PORTD |= (1<<5); to set the pin to 5. The LCD is connected to pins A0 and A1, and it is using I2C. The temperature...
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS; 1. LED 1 TURNS ON AND...
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS; 1. LED 1 TURNS ON AND STAYS ON THE ENTIRE TIME THE BOARD IS RUNNING EXCEPT AT 30 SECOND INTERVALS THEN LED 1 TURNS OFF AND BACK ON 2. LED 2 TURNS ON IN LIGHT CONDITIONS AND OFF IN DARK CONDITION THANK YOU!
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS 1. LED 3 TURNS ON IN...
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS 1. LED 3 TURNS ON IN DARK CONDITIONS AND OFF IN LIGHT CONDITIONS 2. LED 4 TURNS ON WITH FIRST BUTTON PRESS AND STAYS ON UNTIL A SECOND BUTTON PRESS
Draw the schematic and code for an Arduino controlled system using a temperature sensor and fan.
Draw the schematic and code for an Arduino controlled system using a temperature sensor and fan.
Write an Arduino Program that detects a reflective surface using the line sensor array of a...
Write an Arduino Program that detects a reflective surface using the line sensor array of a QTR-3RC (*Must be specific to this sensor! please this is important*) Must include a function that when called returns.. 0 (line to the left of the robot) 1 (line under the robot on the left side) 2 (line under the robot on the right side) 3 (line to the right of the robot) Output the results to the serial port in 0.5 second intervals...
Write an Arduino Program that detects a reflective surface using the line sensor array of a...
Write an Arduino Program that detects a reflective surface using the line sensor array of a QTR-3RC (*Must be specific to this sensor! please this is important*) Must include a function that when called returns.. 0 (line to the left of the robot) 1 (line under the robot on the left side) 2 (line under the robot on the right side) 3 (line to the right of the robot) Output the results to the serial port in 0.5 second intervals...
Write code in C language in the Arduino IDE ADC data using Serial plotter Serial plot...
Write code in C language in the Arduino IDE ADC data using Serial plotter Serial plot : raw data, delay data (int) Purpose: Delay Block (**Using Class**) Input : u(t) Output : o(t)=u(t-h) sample time=0.02 Delay (h) = 0.4
arduino c code only write a code that counts down a timer on serial monitor and...
arduino c code only write a code that counts down a timer on serial monitor and if A1 is typed into serial monitor prints the timer counting down and writes at 1 second hello and at 5 secs goodbye and repeats every 5 secs A2 is typed as above at 2 seconds writes hello and 3 seconds writes goodbye A3 same as above but at 3 seconds says hello and 2 seconds goodbye This continues until c is pressed to...
Create a code showing Arduino IMU data being plotted by your Python code.  
Create a code showing Arduino IMU data being plotted by your Python code.  
*Code in C* Write a function that checks if a number is a perfect cube. Write...
*Code in C* Write a function that checks if a number is a perfect cube. Write another function that calculates the integer cubic root. Under the main program: Prompt the user to input a number Tell the user if the number is a perfect cube or not Print the cubic root if the inputted number is a perfect cube.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT