Challenge

Project 1

1.Switching ON/OFF Lights based on light intensity:

Hardware Required

  • NodeMCU
  • LDR
  • Resistor
  • LED
  • Breadboard
  • Micro USB cable
  • Connecting Wires

LDR : Output is analog in nature, so it gets connected to the A0 pin of the NodeMCU.

LED : It is connected to D1 pin and to Ground(GND) pin of NodeMCU.

Program:

const int ledPin = 5; //Pin no 5 to led
const int ldrPin = A0;//ldr pin to analog pin

void setup()

{

Serial.begin(9600);//start the serial transmission

pinMode(ledPin, OUTPUT);//setting the ledpin to output mode

pinMode(ldrPin, INPUT);//setting ldr pin to input mode

}

void loop() {

int ldrStatus = analogRead(ldrPin);//reading the ldr value and storing it in a variable

if (ldrStatus <=300)//checking the condition if it is less than the threshold(300)

{

digitalWrite(ledPin, HIGH);//turning on the light

Serial.print(ldrStatus);//printing the value of ldr on serial monitor

Serial.println("It is DARK, LED is ON");//print a message

}

else//if condition is not satisfied

{

digitalWrite(ledPin, LOW);//turn off the light

Serial.println("LED is OFF");//print a message

}

}

2.Switching ON/OFF fan based on temperature:

Hardware Required

  • NodeMCU
  • Fan
  • Resistor
  • DHT11 sensor
  • Breadboard
  • Micro USB cable
  • Connecting Wires
#include"DHT.h" // include libraries required to the program
#define DHTPIN 1
#define DHTTYPE DHT11
#define pwm 2 // pwm is for the fan speed
voide setup()
{
Serial.begin(9600);//start the serial transmission
analogWrite(pwm,255);//to turn on the fan to see if it is working
dht.begin();//start the dht sensor
}
void loop()
{
float t=dht.readtemperature();//read the dht 11 sensor temperature value
if(t<20)//check the conditions
{
analogWrite(pwm,0);//turn off the fan if temperature is less than 20 degree celsius
dealy(100);
}
else if((t>=20)&&(t<=24))
{
analogWrite(pwm,51);//turn on the fan to 227rpm for temperature 21 to 24 dergree celsius
delay(100);
}
else if((t>24)&&(t<=26)
{
analogWrite(pwm,102);//turn on the fan to 428rpm for temperature 25 to 26 dergree celsius
delay(100);
}
else if((t>26)&&(t<=28))
{
analogWrite(pwm,153);//turn on the fan to 654rpm for temperature 27 to 28 dergree celsius
delay(100);
}
else if(t==29)
{
analogWrite(pwm,204);//turn on the fan to 826rpm for temperature 29 degree celsius
delay(100);
}
else if(t>29)
{
analogWrite(pwm,255);//turn on the fan to 100rpm for temperature greater than 29 degree celsius
delay(100);
}
else
{
analogWrite(pwm,0);//turn off the fan if it does not satisfy any condition
delay(100);
}
delay(2000);
}
3.Switching ON fire alarm based in smoke detection:

Hardware Required

  • NodeMCU
  • Smoke sensor
  • Resistor
  • Buzzer
  • Breadboard
  • Micro USB cable
  • Connecting Wires
int redLed = 10;//components are assigned to  the pins red led to pin 10,green to pin 12,buzzer to 8 and smoke sensor to A0
int greenLed = 12;
int buzzer = 8;
int smokeA0 = A0;
// Your threshold value
int sensorThres = 100;

void setup()
{ pinMode(redLed, OUTPUT);//setting pin modes pinMode(buzzer, OUTPUT);//redled and green led as output pinMode(smokeA0, INPUT);//smoke sensor as input Serial.begin(9600);//serial data transmission starts at baud rate of 9600 } void loop() { int analogSensor = analogRead(smokeA0);//read the smoke sensor value // Checks if it has reached the threshold value if (analogSensor > sensorThres) { digitalWrite(redLed, HIGH); //if yes then turn the red light and turn on the buzzer digitalWrite(12, LOW); tone(buzzer, 1000, 200); } else { digitalWrite(redLed, LOW);//if no then turn on the green light and turn off the buzzer digitalWrite(12, HIGH); noTone(buzzer); } delay(500); }
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.