Question

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


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 LEDG=8;
int LEDR=9;
int LEDY=10;
int LEDB=11;
void setup() {
Serial.begin(9600);
pinMode(LEDG, OUTPUT);
pinMode(LEDR, OUTPUT);
pinMode(LEDY, OUTPUT);
pinMode(LEDB, OUTPUT);

}

void loop() {
// read the input on analog pin 0 from sensor:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);

if (voltage ==0) //Green light on
{
digitalWrite(LEDR,LOW);
digitalWrite(LEDB,LOW);
digitalWrite(LEDY,LOW);
  
digitalWrite(LEDG,HIGH);
delay(1000);
  
}

else if(voltage==5) //blue & red flashing
{
digitalWrite(LEDY,LOW);
digitalWrite(LEDG,LOW);
  
digitalWrite(LEDR,HIGH);
digitalWrite(LEDB,LOW);
delay(1000);
digitalWrite(LEDB,HIGH);
digitalWrite(LEDR,LOW);
delay(1000);
}

else //yellow flashing
{
digitalWrite(LEDR,LOW);
digitalWrite(LEDB,LOW);
digitalWrite(LEDG,LOW);

  
digitalWrite(LEDY,HIGH);
delay(1000);
digitalWrite(LEDY,LOW);
delay(1000);
}
  
}

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