Monday, 3 October 2016

Filler Lesson - Push Button Codes

Codes Part II

const int button = 11;
const int led = 4;
int currentState = LOW;
int previousState = LOW;
int ledState = LOW;

void setup()
{
   pinMode(button, INPUT);
   pinMode(led, OUTPUT);
   digitalWrite(led, LOW);
}

void loop()
{
   currentState = digitalRead(button);
   if ((currentState == HIGH) && (previousState == LOW))
   {
      if (ledState == LOW)                                                      // toggle ledstate from LOW to HIGH
          ledState = HIGH;                                                        // or HIGH to LOW
      else                                                                                 // depending on the initial state
          ledState = LOW;
}
   previousState = currentState;                                             // moves currentState to previousState
   digitalWrite(led, ledState);                                                 // for next cycle
   delay(10);
}

Filler Lesson - Push Button

Filler Lesson

Material Needed:

1 x Arduino Board
1 x Breadboard
1 x Laptop
1 x USB Cable
1 x LED
1 x 330Ω Resistor
Push Button
1 x Switch Button
1 x 10kΩ Resistor
7 x Jumper Wires


Codes( Part I):

const int button = 11;                                    
const int led = 4;                                          
int buttonState = LOW;                              

void setup()
{
   pinMode(led, OUTPUT);                          
   pinMode(button, INPUT);                          
}

void loop()
{
   buttonState = digitalRead(button);                
   if (buttonState == HIGH)                        
        digitalWrite(led, HIGH);                    
   else
        digitalWrite(led, LOW);                    

}

Monday, 26 September 2016

Lesson 9: Activity 2(ii) (Buttons)

Lesson 9 
Activity 2 Part (ii) - Buttons

Codes:

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int readkey;
void setup() {
  lcd.begin(16, 2);
  lcd.print("How are you");
  lcd.setCursor(0, 1);
  lcd.print("today?");
}
void loop()
{
  readkey=analogRead(0);
  if (readkey<50) {
  lcd.clear();
  lcd.print("Happy");
  }
  else if(readkey<195) {
    lcd.clear();
    lcd.print("Sad");
  }
  else if(readkey<380) {
    lcd.clear();
    lcd.print("Excited");
  }
  else if(readkey<790) {
    lcd.clear();
    lcd.print("Bored");
  }
}

Lesson 9: Activity 2(LCD Shield)

Lesson 9 

Activity 2: LCD Shield

Material Needed:
  • Laptop
  • USB cable
  • Arduino Board
  • LCD Shield

Codes:

#include <LiquidCrystal.h>
LiquidCrystal lcd (8,9,4,5,6,7);
void setup()
{
  lcd.begin(16,2);
}
void loop()
{
  lcd.home();
  lcd.print("How are you ");
  delay (500);
  lcd.setCursor(0,1);
  lcd.print("today???");
  delay (500);
  lcd.clear();
  delay (500);
}

* Note: Please change the Pin value from the previous activity



Monday, 19 September 2016

Lesson 9: Activity 1(Displaying Characters on LCD Panel)

Lesson 9

Activity 1: Displaying Characters on LCD Panel

Material Needed:

  • Laptop
  • USB cable
  • Breadboard
  • Arduino Board
  • LCD Panel
  • 14 x Jumper Wires
Codes:

#include <LiquidCrystal.h>
LiquidCrystal lcd (8,9,10,11,12,13);
void setup()

___._____(16,2);
}
void loop()
{
  lcd.home();
  lcd.print("How are you");
  delay (1000);
  lcd.setCursor(0,1);          
 ___._____("today 1R3???");
delay (1000);
____.______();
delay (1000);
}

Pin No. : 
Pin 1: GND Bus
Pin 2: Live Bus
Pin 3: GND Bus
Pin 4: Digital Pin 8
Pin 5: GND Bus
Pin 6: Digital Pin 9
Pin 7: Empty
Pin 8: Empty
Pin 9: Empty
Pin 10: Empty
Pin 11: Digital Pin 10
Pin 12: Digital Pin 11
Pin 13: Digital Pin 12
Pin 14: Digital Pin 13
Pin 15: Live Bus
Pin 16: GND Bus

Lesson 8: Activity 1(Testing Heart Rate Sensor)

Lesson 8
Activity 1 - Testing Heart Rate Sensor

Materials Needed:

  • Arduino Board
  • Breadboard
  • USB Cable
  • Laptop
  • Heart Rate ear-clip sensor
  • 5 x Jumper Wires

Codes:


const int heartPin = ?;                         
                     
void setup()
{
  Serial.begin(9600);                    
  pinMode(heartPin, ?);                 
}

void loop()
{
  if(digitalRead(heartPin)>0)
    {              
    Serial.println("Reading");              
    }
else
    {
     Serial.println("0");                 
    }
}

Monday, 12 September 2016

Lesson 7: Activity 2 (Temperature Warning System)

Lesson 7
Activity 2 - Temperature Warning System

Materials Needed:

  • Arduino Board
  • Breadboard
  • USB Cable
  • Laptop
  • Temperature Sensor
  • Buzzer
  • 1 x 330Ω
  • 1 x LED
  • 9 x Jumper Wires
Codes:

int analogVal;
const int tempPin = A0;
float voltage;
float temperature;
const int led = ?;
const int buzzer = 6;
void setup()
{
  pinMode(tempPin, INPUT);
  pinMode(led,?); 
  pinMode(buzzer,?);
  Serial.begin(9600);

}
void loop()
{
  analogVal=analogRead(tempPin);
  voltage = (analogVal/1024.0)*5.0;
  temperature = 100*voltage-50;     
  Serial.println(temperature);
  delay(200);       
  if (temperature>30.0)
  {
   digitalWrite (led,?);
   digitalWrite (buzzer,?);
   delay (100);
  }
    else
    digitalWrite(led,LOW);
    digitalWrite(buzzer,LOW);
    delay (100);                      
}