0% found this document useful (0 votes)
5 views12 pages

Week 1

The document outlines a series of Arduino projects over five days, focusing on various applications such as blinking LEDs, traffic lights, temperature sensors, security lights, and motion detectors. Each project includes code snippets for implementation, demonstrating how to use different sensors and components with Arduino boards. The projects aim to teach programming and circuit design skills through practical examples.

Uploaded by

HESBON OYUNGE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views12 pages

Week 1

The document outlines a series of Arduino projects over five days, focusing on various applications such as blinking LEDs, traffic lights, temperature sensors, security lights, and motion detectors. Each project includes code snippets for implementation, demonstrating how to use different sensors and components with Arduino boards. The projects aim to teach programming and circuit design skills through practical examples.

Uploaded by

HESBON OYUNGE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

DAY 1: MONDAY

ACTIVITY 1: BLINKING LED USING ARDHUINO BOARD AND BREADTH BOARD


(CODE)

const int LED_PIN = 13;

void setup() {

pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {

digitalWrite(LED_BUILTIN, HIGH);

delay(1000);

digitalWrite(LED_BUILTIN, LOW);

delay(1000);
}

1|Page
ACTIVITY 2: TRAFFIC LIGHTS USING ARDHUINO BOARD AND BREADTH
BOARD (CODE)

const int RED_LED = 8;

const int YELLOW_LED = 9;

const int GREEN_LED = 10;

void setup() {

pinMode(RED_LED, OUTPUT);
pinMode(YELLOW_LED, OUTPUT);

pinMode(GREEN_LED, OUTPUT);
}

void loop() {

digitalWrite(RED_LED, HIGH);

delay(5000);

digitalWrite(RED_LED, LOW);
digitalWrite(YELLOW_LED, HIGH);

delay(2000);

digitalWrite(YELLOW_LED, LOW);

digitalWrite(GREEN_LED, HIGH);

delay(5000);

digitalWrite(GREEN_LED, LOW);

2|Page
DAY 2: TUESDAY

ACTIVITY 1: CRITICAL TEMPERATURE SENSOR

const int lm35Pin = A0;

const int ledPin = 13;


void setup() {

Serial.begin(9600);

pinMode(ledPin, OUTPUT);

void loop() {

int sensorValue = analogRead(lm35Pin);

float temperature = (sensorValue * 5.0 * 100.0) / 1024.0;

Serial.print("Temperature: ");
Serial.print(temperature);

Serial.println(" *C");

if (temperature < 50) {

Serial.println("NORMAL");

digitalWrite(ledPin, LOW);

else {
Serial.println("ABNORMAL");

digitalWrite(ledPin, HIGH);

delay(1000);

3|Page
ACTIVITY 2: LED GLOWS AS THE TEMPERATURE INCREASES

const int lm35Pin = A0;

const int ledPin = 9;

void setup() {
Serial.begin(9600);

pinMode(ledPin, OUTPUT);

void loop() {

int sensorValue = analogRead(lm35Pin);

float temperature = (sensorValue * 5.0 * 100.0) / 1024.0;

Serial.print("Temperature: ");

Serial.print(temperature);
Serial.println(" *C");

int brightness;

if (temperature < 15) {

brightness = 50;

} else if (temperature >= 15 && temperature <= 20) {

brightness = 128;

} else {
brightness = 255;

analogWrite(ledPin, brightness);

delay(1000);

4|Page
DAY 3: WEDNESDAY

ACTIVITY 1: SECURITY LIGHTS

const int ldrPin = A5;

const int ledPin = 9;


void setup() {

Serial.begin(9600);

pinMode(ledPin, OUTPUT);

void loop() {

int ldrValue = analogRead(ldrPin);

Serial.print("LDR Value: ");

Serial.println(ldrValue);
if (ldrValue < 500) {

digitalWrite(ledPin, HIGH);

Serial.println("Light ON (Dark)");

} else {

digitalWrite(ledPin, LOW);

Serial.println("Light OFF (Bright)");

}
delay(1000);

5|Page
ACTIVITY 2: LCD DISPLAY (SERIES)

#include <Wire.h>

#include "DFRobot_LCD.h"

const int colorR = 255;


const int colorG = 0;

const int colorB = 0;

DFRobot_LCD lcd(16,2);

void setup() {

lcd.init();

lcd.setRGB(colorR, colorG, colorB);

lcd.print("hello, world!");

delay(1000);
}

void loop() {

lcd.setCursor(0, 1);

lcd.print(millis()/1000);

delay(100);

6|Page
DAY 4: THURSDAY

ACTIVITY 1: LCD DISPLAY NORMAL AND ABNORMAL TEMPERATURE


#include <Wire.h>
#include "DFRobot_LCD.h"
const int colorR = 255;
const int colorG = 0;
const int colorB = 0;
const int lm35Pin = A0;
DFRobot_LCD lcd(16, 2);
void setup() {
Wire.begin();
lcd.init();
lcd.setRGB(colorR, colorG, colorB);
lcd.print("KENYA NI HOME!");
delay(2000);
lcd.clear();
}
void loop() {
float sensorValue = analogRead(lm35Pin);
float temperature = (sensorValue * 5.0 / 1023.0) * 100;
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print(" C ");
lcd.setCursor(0, 1);
if (temperature < 50) {
lcd.print("NORMAL TEMPERATURE ");
} else {
lcd.print("ABNORMAL ");
}
delay(1000);
}

7|Page
ACTIVITY 2: MOTION DETECTOR TO DISPLAY “INTRUDER DETECTED”

(PIR SENSOR)
#include <Wire.h>

#include "DFRobot_LCD.h"

const int colorR = 255;

const int colorG = 0;

const int colorB = 0;

const int pirPin = 2;

const int ledPin = 3;

DFRobot_LCD lcd(16, 2);

bool prevState = LOW;

void setup() {

Wire.begin();

lcd.init();

lcd.setRGB(colorR, colorG, colorB);

lcd.print("");

delay(2000);

lcd.clear();

pinMode(pirPin, INPUT);

pinMode(ledPin, OUTPUT);

void loop() {

bool motionDetected = digitalRead(pirPin);

if (motionDetected != prevState) {

lcd.clear();

lcd.setCursor(0, 0);

if (motionDetected) {

lcd.print("INTRUDER DETECTED!");

digitalWrite(ledPin, HIGH); // Turn LED ON

} else {

lcd.print("NO INTRUDER ");

digitalWrite(ledPin, LOW);

prevState = motionDetected;

8|Page
}

delay(500);

DAY 5: FRIDAY
ACTIVITY 1: MOTION DETECTOR USING IR SENSOR

#include <Wire.h>

#include "DFRobot_LCD.h"

#define PIR_PIN 2

#define LED_PIN 13

const int colorR = 255;

const int colorG = 0;


const int colorB = 0;

DFRobot_LCD lcd(16, 2);

unsigned long lastMotionTime = 0;

unsigned long motionCooldown = 5000;

bool lastMotionState = LOW;

void setup() {

pinMode(PIR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);

lcd.init();

lcd.setRGB(colorR, colorG, colorB);

lcd.setCursor(0, 0);

lcd.print("System Ready...");

delay(2000);

lcd.clear();
}

9|Page
void loop() {

int motion = digitalRead(PIR_PIN);


if (motion == HIGH && lastMotionState == LOW && (millis() - lastMotionTime > motionCooldown)) {

lastMotionTime = millis();

String alertMsg = "INTRUDER ALERT! ";

lcd.clear();

lcd.setCursor(0, 0);

lcd.print(alertMsg);
digitalWrite(LED_PIN, HIGH);
for (int i = 0; i < alertMsg.length(); i++) {

lcd.scrollDisplayLeft();

delay(300);

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("INTRUDER ALERT!");
}

else if (motion == LOW && lastMotionState == HIGH) {

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("No Motion");

digitalWrite(LED_PIN, LOW);

lastMotionState = motion;
delay(100); // Small delay to prevent too fast polling
}

10 | P a g e
ACTIVITY 2: RUN TWO SENSORS IR AND LM35
#include <Wire.h>
#include "DFRobot_LCD.h"
#define IR_PIN 2
#define LED_PIN 13
#define LM35_PIN A0
const int colorR = 255;
const int colorG = 0;
const int colorB = 0;
DFRobot_LCD lcd(16, 2);
unsigned long lastMotionTime = 0;
unsigned long motionCooldown = 5000;
bool lastMotionState = LOW;
void setup() {
pinMode(IR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
lcd.init();
lcd.setRGB(colorR, colorG, colorB);
lcd.setCursor(0, 0);
lcd.print("System Ready...");
delay(2000);
lcd.clear();
}
void loop() {
int motion = digitalRead(IR_PIN);
float temperature = analogRead(LM35_PIN) * (5.0 / 1023.0) * 100;

if (motion == HIGH && lastMotionState == LOW && (millis() - lastMotionTime > motionCooldown)) {

lastMotionTime = millis();
String alertMsg = "LIGHT ON! ";
lcd.clear();

11 | P a g e
lcd.setCursor(0, 0);
lcd.print(alertMsg);
digitalWrite(LED_PIN, HIGH);
for (int i = 0; i < alertMsg.length(); i++) {
lcd.scrollDisplayLeft();
delay(300);
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("INTRUDER DETECTED!");
}
else if (motion == LOW && lastMotionState == HIGH)
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("");
digitalWrite(LED_PIN, LOW);
}
lastMotionState = motion;
lcd.setCursor(0, 1);
lcd.print("");
lcd.print(temperature, 1);
lcd.print(" C");
if (temperature < 50) {
lcd.print(" NORMAL TEMP");
} else {
lcd.print("ABNORMAL ");
}
delay(100); // Small delay to prevent too fast polling
}

12 | P a g e

You might also like