Beginners Tutorials with sample codes - Part 4 CloudX

  • img
Project Details

1. MAX7219 LED Dot-Matrix Display 

Brief Description

In this project, we’ll extend our LED matrix display knowledge further, but this time round, it’ll involve making use of an already full-fledged made module off the MAX7219 LED display chip. 

 

 

Wiring

 

Code

#include <CloudX\DotMatrix_MAX7219.h> 


setup(){
//setup here

MAX7219_setting(3, 2, 1, 8, 7);
//DIN, CLK, CS, colSize, brightness
//brightness (0 -> Dim : 15 -> Brightest)




loop() {
//Program here

MAX7219_scrollDisplay(" Hello, World! ", 20);
//string, scrollSpeed

}
}
 

 

Simulation

 

2. Relay 

Brief Description

In this project, we’ll use a button-switch to switch OFF/ ON a Light Bulb via a Relay connected to the Microcontroller.

 

Utilizing a relay device is actually one effective way of controlling an AC (Alternating Current) Load via the Microcontroller. 

 

Wiring

 

Code

#define RELAY  pin1        //digital pin 1 defined as RELAY  
#define BUTTON 2 //digital pin 2 defined as Button

setup(){
//setup here

pinMode(BUTTON, INPUT); //configures digital I/O pin 2
//(BUTTON) as an INPUT pin

pin1Mode = OUTPUT; //sets up digital I/O pin 1
//(RELAY) as OUTPUT

RELAY = LOW; //initializes RELAY @ an OFF state

loop(){
//Program here

//---------------------------------------------------
//Execute this section of code, if BUTTON is pressed.
//---------------------------------------------------
if(readPin(BUTTON) is LOW)
{
delayMs(250); //switch debounce delay

RELAY = ~RELAY; //toggles or alternates RELAY’s
//ON/OFF status
}
}
}
 

 

Simulation

 

 

3. Clap Switch Control using Sound Sensor 

Brief Description

In this project, we’ll monitor the output from a Sound Sensor module via an input pin; and then switch OFF and ON a Light Bulb using a Relay connected to the Microcontroller.

This is a home automation prototype, whose basic knowledge can easily be extrapolated to a wider application in the home automation space.

 

Wiring

 

Code

#define relay       1   //digital pin 1 defined as relay 
#define soundSensor 2 //digital pin 2 defined as soundSensor

setup(){
//setup here

pinMode(soundSensor, INPUT); //configures Sound sensor
//as INPUT

pinMode(relay, OUTPUT); //configures Relay as OUTPUT

loop(){
//Program here

//=========================================================
//Execute this section of code, if a Clap is heard by the
//Sound Sensor.
//=========================================================
if(readPin(soundSensor))
{
delayMs(250); //clears feedback/echo/noise from
//surrounding

if(readPin(relay)) //if relay is on, relay turns off
digitalWrite(relay, LOW);

else //if relay is off, relay turns on
digitalWrite(relay, HIGH);
}

}
}

 

Simulation

 

 

4. Flame Sensor 

Brief Description

In this project, we’ll check out for a Fire incident via a Flame Sensor, and display data on an LCD relative to the state of the sensor.

 

 

We’ll also control the state of a buzzer, a Red LED and a Green LED with respect to the sensor’s Output. 

A Buzzer


Wiring

 

Code  

#include <CloudX/LCD.h>  

#define FlameSensor_DOPin 7 //digital pin 7 connects to D0 pin
//on the Flame Sensor
#define Buzzer 8 //digital pin 8 connects to Buzzer
#define GreenLED 9 //digital pin 9 connects to
//GREEN LED
#define RedLED 10 //digital pin 10 connects to
//RED LED

setup(){
//setup here

LCD_setting(1, 2, 3, 4, 5, 6); //RS,EN,D4,D5,D6,D7

pinMode(FlameSensor_DOPin, INPUT); //sets up D0 pin on the
//Flame Sensor as INPUT
pinMode(Buzzer, OUTPUT); //sets up Buzzer as OUTPUT
pinMode(RedLED, OUTPUT); //sets up RED LED as OUTPUT
pinMode(GreenLED, OUTPUT); //sets up GREEN LED as OUTPUT

LCD_cmd(clear);
LCD_writeText(1, 1," FLAME SENSOR "); //displays “Flame
//Sensor” on LCD

loop(){
//Program here

//------------------------------------------------------
//Execute this section of code, if the Flame sensor
//senses Fire
//------------------------------------------------------
if (readPin(FlameSensor_DOPin))
{
digitalWrite(Buzzer, HIGH); //turns on Buzzer
digitalWrite(RedLED, HIGH); //turns on Red LED
digitalWrite(GreenLED, LOW); //turns off Green LED
LCD_writeText(2, 1, "Fire!!! Call 911");
//shows “FIRE!!! CALL 911” on LCD
}
//------------------------------------------------------
//Execute this section of code, if the if-statement
//above is NOT TRUE (NO FIRE).
//------------------------------------------------------
else
{
digitalWrite(Buzzer, LOW); //turns off Buzzer
digitalWrite(RedLED, LOW); //turns off Red LED
digitalWrite(GreenLED, HIGH); //turns on Green LED
LCD_writeText(2, 1, "No Flame Detectd ");
//shows “No flame” on LCD
}

}
}
 

 

Simulation

 

 

You can drop your comments below.

Share this with friends