Question

Assignment 2: Simulate a Sensor to control an alarm Before you attempt this assignment, it is...

Assignment 2: Simulate a Sensor to control an alarm

Before you attempt this assignment, it is suggested you understand circuits (and the Arduino code) 1B and 1C.

Sensor

That being said, in this assignment, we’ll be mimicking an Infrared Sensor (detects objects) by utilizing the potentiometer. The potentiometer will provide us voltage potential that we can vary from 0V to 5V (similar to 1B). This voltage potential represents the output of a sensor. Assume the sensor cannot detect anything beyond 10 yards. So, if an object is in front of the sensor at 5 yards out, the output of the sensor should be 2.5 volts. At 0 yards out, the sensor output should be approximately 5 volts.

Now that you’ve established your sensor, it will be your job to utilize this sensor to trip a visual alarm system.

Visual Alarm

Imagine this microcontroller unit is on a vehicle operated by a person. You are designing a visual alarm system that will alert the driver if the vehicle approaches an object.

You are tasked to do this.

A Solid Green LED is on when no object is detected by the sensor (red, yellow, and blue LEDs remain off).

A flashing Yellow LED when the vehicle approaches an object (green, red, and blue LEDs remain off).

Alternating Blue and Red flashing LEDs when the vehicle is close to an object (green and yellow LEDs remain off.

What you’ll turn in

You’ll upload your Arduino code and your schematic in a single file. The schematic can be handrawn or you may use a CAD program to draw your schematic. Keep in mind, your schematic should be detailed enough so somebody can build your design. What I mean by this is, label your inputs, outputs, sensors, etc. (A0, A1, GND, 5V, 1, 2, etc.).

Tip

Understand the code of 1B and 1C. Additionally, research how to implement “if statements” in Arduino. There are numerous sources and examples online on how to properly use “if statements.” You’ll most likely need “if statements” to complete this assignment.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

int sensorPin = A0; // select the input pin for the sensor (potentiometer)
int greenLed = 12; // select the pin for the green LED
int redLed = 11; // select the pin for the green LED
int yellowLed = 10; // select the pin for the green LED
int blueLed = 9; // select the pin for the green LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// declare the four led pins as OUTPUT:
pinMode(greenLed, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(yellowLed, OUTPUT);
pinMode(blueLed, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
sensorValue = analogRead(sensorPin); // read the raw data coming in on analog pin 0
float voltage = sensorValue * (5.0 / 1024.0); // Convert the raw data value (0 - 1023) to voltage (0.0V - 5.0V)

//If no objetct detected (object is beyond 10 yard distance), then voltage will be zero.
if (voltage == 0) {
digitalWrite(greenLed, HIGH);
digitalWrite(redLed, LOW);
digitalWrite(yellowLed, LOW);
digitalWrite(blueLed, LOW);
}
// If objetct is within 10 yard distance, voltage will be greater than zero.
else {
// When the voltage is less than 4V, the distance will be greater than 2 yards.
while ((voltage < 4)&&(voltage>0)) {
digitalWrite(greenLed, LOW);
digitalWrite(redLed, LOW);
digitalWrite(blueLed, LOW);
digitalWrite(yellowLed, HIGH);
delay (1000);
digitalWrite(yellowLed, LOW);
}
// When the voltage is more than 4V, the distance will be less than 2 yards.
// This distance is considered as close object. You can change the value according to the requirement.
while (voltage > 4){
digitalWrite(greenLed, LOW);
digitalWrite(yellowLed, LOW);
digitalWrite(blueLed, LOW);
digitalWrite(redLed, HIGH);
delay (1000);
digitalWrite(blueLed, HIGH);
digitalWrite(redLed, LOW);
}
}
}

Add a comment
Know the answer?
Add Answer to:
Assignment 2: Simulate a Sensor to control an alarm Before you attempt this assignment, it is...
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
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