Question

Write the phyton script for the following project: You have a smart light bulb that can...

Write the phyton script for the following project:

You have a smart light bulb that can change color at your house. You want to set it up so when you turned the light switch on, the color change based on the temperature outside your house. You want to develop an application that will notify users of what the temperature is outside by changing the color of an LED light bulb when they turn on the light.

Using PyCharm JetBrains and physical simulator as the sensor (physense_emu) -- "NOT RASPBERRY PIE", the system shall check the temperature when the "switch" is turned on. Use a button to simulate a light switch.

  • If the temperature is cold, change the LED to blue.
  • If the temperature is warm, change the LED to yellow,
  • If the temperature is hot, change the LED to red.

Homework Answers

Answer #1
Arduino LED Temperature Indicator:
const int hot = 87; //set hot parameter
const int cold = 75; //set cold parameter
void setup() {
pinMode(A2, INPUT); //sensor
pinMode(2, OUTPUT); //blue
pinMode(3, OUTPUT); //yellow
pinMode(4, OUTPUT); //red
Serial.begin(9600);
}
void loop() {
int sensor = analogRead(A2);
float voltage = (sensor / 1024.0) * 5.0;
float tempC = (voltage - .5) * 100;
float tempF = (tempC * 1.8) + 32;
Serial.print("temp: ");
Serial.print(tempF);
if (tempF < cold) { //cold
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
Serial.println(" It's Cold.");
}
else if (tempF >= hot) { //hot
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
Serial.println(" It's Hot.");
}
else { //warm
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
Serial.println(" It's warm.");
}
delay(10);
}
Know the answer?
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
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT